From 41e67aa3e71bb95056afd4224a72a5302e4b324e Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Fri, 22 May 2020 10:04:02 -0700 Subject: [PATCH 1/4] Fix typo --- command/pr.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command/pr.go b/command/pr.go index 464894c22..92cd8972d 100644 --- a/command/pr.go +++ b/command/pr.go @@ -569,7 +569,7 @@ func prMerge(cmd *cobra.Command, args []string) error { err = git.DeleteLocalBranch(pr.HeadRefName) if err != nil { - fmt.Fprintf(colorableErr(cmd), "%s Could not deleted local branch %s: %s\n", utils.Red("!"), utils.Cyan(pr.HeadRefName), err) + fmt.Fprintf(colorableErr(cmd), "%s Could not delete local branch %s: %s\n", utils.Red("!"), utils.Cyan(pr.HeadRefName), err) return err } fmt.Fprintf(colorableOut(cmd), "%s Deleted local branch %s\n", utils.Red("✔"), utils.Cyan(pr.HeadRefName)) From b2c1b12bee432d552c1442d46bb861a83369ee5b Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Fri, 22 May 2020 14:39:53 -0700 Subject: [PATCH 2/4] Don't delete branch if the repo flag is used --- command/pr.go | 2 +- command/pr_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/command/pr.go b/command/pr.go index 92cd8972d..c740b3968 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 d9b535c5e..5f5cdf6b8 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(` From 28d8a9e7819eaf33c9ea0ae2ed35c5a636b38d3f Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Fri, 22 May 2020 14:40:38 -0700 Subject: [PATCH 3/4] Use big D --- git/git.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/git.go b/git/git.go index 38a9a60bf..256b65f6d 100644 --- a/git/git.go +++ b/git/git.go @@ -204,7 +204,7 @@ func ReadBranchConfig(branch string) (cfg BranchConfig) { } func DeleteLocalBranch(branch string) error { - configCmd := GitCommand("branch", "-d", branch) + configCmd := GitCommand("branch", "-D", branch) _, err := run.PrepareCmd(configCmd).Output() return err } From d7c933bc40715fe2bb6813b9c78b82d858721ee9 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Fri, 22 May 2020 14:52:29 -0700 Subject: [PATCH 4/4] branchCmd --- git/git.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/git/git.go b/git/git.go index 256b65f6d..634b9e084 100644 --- a/git/git.go +++ b/git/git.go @@ -204,14 +204,14 @@ 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 } func CheckoutBranch(branch string) error { configCmd := GitCommand("checkout", branch) - _, err := run.PrepareCmd(configCmd).Output() + err := run.PrepareCmd(configCmd).Run() return err }