MCPcopy Create free account
hub / github.com/cli/cli / runCommandWithBranchFunc

Function runCommandWithBranchFunc

pkg/cmd/pr/merge/merge_test.go:257–305  ·  view source on GitHub ↗
(rt http.RoundTripper, pm *prompter.PrompterMock, branch func() (string, error), isTTY bool, cli string)

Source from the content-addressed store, hash-verified

255}
256
257func runCommandWithBranchFunc(rt http.RoundTripper, pm *prompter.PrompterMock, branch func() (string, error), isTTY bool, cli string) (*test.CmdOut, error) {
258 ios, _, stdout, stderr := iostreams.Test()
259 ios.SetStdoutTTY(isTTY)
260 ios.SetStdinTTY(isTTY)
261 ios.SetStderrTTY(isTTY)
262
263 factory := &cmdutil.Factory{
264 IOStreams: ios,
265 HttpClient: func() (*http.Client, error) {
266 return &http.Client{Transport: rt}, nil
267 },
268 Branch: branch,
269 Remotes: func() (context.Remotes, error) {
270 return []*context.Remote{
271 {
272 Remote: &git.Remote{
273 Name: "origin",
274 },
275 Repo: ghrepo.New("OWNER", "REPO"),
276 },
277 }, nil
278 },
279 GitClient: &git.Client{
280 GhPath: "some/path/gh",
281 GitPath: "some/path/git",
282 },
283 Prompter: pm,
284 }
285
286 cmd := NewCmdMerge(factory, nil)
287 cmd.PersistentFlags().StringP("repo", "R", "", "")
288
289 cli = strings.TrimPrefix(cli, "pr merge")
290 argv, err := shlex.Split(cli)
291 if err != nil {
292 return nil, err
293 }
294 cmd.SetArgs(argv)
295
296 cmd.SetIn(&bytes.Buffer{})
297 cmd.SetOut(io.Discard)
298 cmd.SetErr(io.Discard)
299
300 _, err = cmd.ExecuteC()
301 return &test.CmdOut{
302 OutBuf: stdout,
303 ErrBuf: stderr,
304 }, err
305}
306
307func singleWorktree(branch string) string {
308 return fmt.Sprintf("worktree /path/to/repo\nHEAD abc123\nbranch refs/heads/%s\n", branch)

Callers 2

runCommandFunction · 0.85

Calls 6

TestFunction · 0.92
NewFunction · 0.92
NewCmdMergeFunction · 0.85
SetStdoutTTYMethod · 0.80
SetStdinTTYMethod · 0.80
SetStderrTTYMethod · 0.80

Tested by

no test coverage detected