diff --git a/command/pr.go b/command/pr.go index 216671a40..b9d87e14e 100644 --- a/command/pr.go +++ b/command/pr.go @@ -549,7 +549,7 @@ func prMerge(cmd *cobra.Command, args []string) error { fmt.Fprintf(colorableOut(cmd), "%s %s pull request #%d\n", utils.Magenta("✔"), action, pr.Number) - if deleteBranch { + if deleteBranch && !cmd.Flags().Changed("repo") { repo, err := api.GitHubRepo(apiClient, baseRepo) if err != nil { return err diff --git a/command/pr_test.go b/command/pr_test.go index 39a571ca5..9bd78ebcf 100644 --- a/command/pr_test.go +++ b/command/pr_test.go @@ -1017,6 +1017,31 @@ func TestPrMerge(t *testing.T) { } } +func TestPrMerge_withRepoFlag(t *testing.T) { + initBlankContext("", "OWNER/REPO", "master") + http := initFakeHTTP() + http.StubResponse(200, bytes.NewBufferString(`{ "data": { "repository": { + "pullRequest": { "number": 1, "closed": false, "state": "OPEN"} + } } }`)) + http.StubResponse(200, bytes.NewBufferString(`{"id": "THE-ID"}`)) + + cs, cmdTeardown := test.InitCmdStubber() + defer cmdTeardown() + + eq(t, len(cs.Calls), 0) + + output, err := RunCommand("pr merge 1 --merge -R stinky/boi") + if err != nil { + t.Fatalf("error running command `pr merge`: %v", err) + } + + r := regexp.MustCompile(`Merged pull request #1`) + + if !r.MatchString(output.String()) { + t.Fatalf("output did not match regexp /%s/\n> output\n%q\n", r, output.Stderr()) + } +} + func TestPrMerge_deleteBranch(t *testing.T) { initWithStubs("blueberries", stubResponse{200, bytes.NewBufferString(` diff --git a/git/git.go b/git/git.go index c1a8bd619..529dc792d 100644 --- a/git/git.go +++ b/git/git.go @@ -204,8 +204,8 @@ func ReadBranchConfig(branch string) (cfg BranchConfig) { } func DeleteLocalBranch(branch string) error { - configCmd := GitCommand("branch", "-d", branch) - _, err := run.PrepareCmd(configCmd).Output() + branchCmd := GitCommand("branch", "-D", branch) + err := run.PrepareCmd(branchCmd).Run() return err } @@ -223,7 +223,7 @@ func HasLocalBranch(branch string) bool { func CheckoutBranch(branch string) error { configCmd := GitCommand("checkout", branch) - _, err := run.PrepareCmd(configCmd).Output() + err := run.PrepareCmd(configCmd).Run() return err }