Skip to content

Commit 96dc437

Browse files
author
Nate Smith
authored
Merge pull request cli#429 from cli/co-drawing-board
revert pr checkout branch prefixing
2 parents 2e7fedd + c5a511a commit 96dc437

File tree

2 files changed

+30
-31
lines changed

2 files changed

+30
-31
lines changed

command/pr_checkout.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ func prCheckout(cmd *cobra.Command, args []string) error {
4040

4141
cmdQueue := [][]string{}
4242

43-
// namespace PR checkout branches to avoid local branch name collisions
44-
newBranchName := fmt.Sprintf("pr/%d/%s", pr.Number, pr.HeadRefName)
43+
newBranchName := pr.HeadRefName
4544
if headRemote != nil {
4645
// there is an existing git remote for PR head
4746
remoteBranch := fmt.Sprintf("%s/%s", headRemote.Name, pr.HeadRefName)

command/pr_checkout_test.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestPRCheckout_sameRepo(t *testing.T) {
4242
ranCommands := [][]string{}
4343
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
4444
switch strings.Join(cmd.Args, " ") {
45-
case "git show-ref --verify --quiet refs/heads/pr/123/feature":
45+
case "git show-ref --verify --quiet refs/heads/feature":
4646
return &errorStub{"exit status: 1"}
4747
default:
4848
ranCommands = append(ranCommands, cmd.Args)
@@ -57,9 +57,9 @@ func TestPRCheckout_sameRepo(t *testing.T) {
5757

5858
eq(t, len(ranCommands), 4)
5959
eq(t, strings.Join(ranCommands[0], " "), "git fetch origin +refs/heads/feature:refs/remotes/origin/feature")
60-
eq(t, strings.Join(ranCommands[1], " "), "git checkout -b pr/123/feature --no-track origin/feature")
61-
eq(t, strings.Join(ranCommands[2], " "), "git config branch.pr/123/feature.remote origin")
62-
eq(t, strings.Join(ranCommands[3], " "), "git config branch.pr/123/feature.merge refs/heads/feature")
60+
eq(t, strings.Join(ranCommands[1], " "), "git checkout -b feature --no-track origin/feature")
61+
eq(t, strings.Join(ranCommands[2], " "), "git config branch.feature.remote origin")
62+
eq(t, strings.Join(ranCommands[3], " "), "git config branch.feature.merge refs/heads/feature")
6363
}
6464

6565
func TestPRCheckout_urlArg(t *testing.T) {
@@ -94,7 +94,7 @@ func TestPRCheckout_urlArg(t *testing.T) {
9494
ranCommands := [][]string{}
9595
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
9696
switch strings.Join(cmd.Args, " ") {
97-
case "git show-ref --verify --quiet refs/heads/pr/123/feature":
97+
case "git show-ref --verify --quiet refs/heads/feature":
9898
return &errorStub{"exit status: 1"}
9999
default:
100100
ranCommands = append(ranCommands, cmd.Args)
@@ -108,7 +108,7 @@ func TestPRCheckout_urlArg(t *testing.T) {
108108
eq(t, output.String(), "")
109109

110110
eq(t, len(ranCommands), 4)
111-
eq(t, strings.Join(ranCommands[1], " "), "git checkout -b pr/123/feature --no-track origin/feature")
111+
eq(t, strings.Join(ranCommands[1], " "), "git checkout -b feature --no-track origin/feature")
112112
}
113113

114114
func TestPRCheckout_branchArg(t *testing.T) {
@@ -143,7 +143,7 @@ func TestPRCheckout_branchArg(t *testing.T) {
143143
ranCommands := [][]string{}
144144
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
145145
switch strings.Join(cmd.Args, " ") {
146-
case "git show-ref --verify --quiet refs/heads/pr/123/feature":
146+
case "git show-ref --verify --quiet refs/heads/feature":
147147
return &errorStub{"exit status: 1"}
148148
default:
149149
ranCommands = append(ranCommands, cmd.Args)
@@ -157,7 +157,7 @@ func TestPRCheckout_branchArg(t *testing.T) {
157157
eq(t, output.String(), "")
158158

159159
eq(t, len(ranCommands), 5)
160-
eq(t, strings.Join(ranCommands[1], " "), "git fetch origin refs/pull/123/head:pr/123/feature")
160+
eq(t, strings.Join(ranCommands[1], " "), "git fetch origin refs/pull/123/head:feature")
161161
}
162162

163163
func TestPRCheckout_existingBranch(t *testing.T) {
@@ -192,7 +192,7 @@ func TestPRCheckout_existingBranch(t *testing.T) {
192192
ranCommands := [][]string{}
193193
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
194194
switch strings.Join(cmd.Args, " ") {
195-
case "git show-ref --verify --quiet refs/heads/pr/123/feature":
195+
case "git show-ref --verify --quiet refs/heads/feature":
196196
return &outputStub{}
197197
default:
198198
ranCommands = append(ranCommands, cmd.Args)
@@ -207,7 +207,7 @@ func TestPRCheckout_existingBranch(t *testing.T) {
207207

208208
eq(t, len(ranCommands), 3)
209209
eq(t, strings.Join(ranCommands[0], " "), "git fetch origin +refs/heads/feature:refs/remotes/origin/feature")
210-
eq(t, strings.Join(ranCommands[1], " "), "git checkout pr/123/feature")
210+
eq(t, strings.Join(ranCommands[1], " "), "git checkout feature")
211211
eq(t, strings.Join(ranCommands[2], " "), "git merge --ff-only refs/remotes/origin/feature")
212212
}
213213

@@ -244,7 +244,7 @@ func TestPRCheckout_differentRepo_remoteExists(t *testing.T) {
244244
ranCommands := [][]string{}
245245
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
246246
switch strings.Join(cmd.Args, " ") {
247-
case "git show-ref --verify --quiet refs/heads/pr/123/feature":
247+
case "git show-ref --verify --quiet refs/heads/feature":
248248
return &errorStub{"exit status: 1"}
249249
default:
250250
ranCommands = append(ranCommands, cmd.Args)
@@ -259,9 +259,9 @@ func TestPRCheckout_differentRepo_remoteExists(t *testing.T) {
259259

260260
eq(t, len(ranCommands), 4)
261261
eq(t, strings.Join(ranCommands[0], " "), "git fetch robot-fork +refs/heads/feature:refs/remotes/robot-fork/feature")
262-
eq(t, strings.Join(ranCommands[1], " "), "git checkout -b pr/123/feature --no-track robot-fork/feature")
263-
eq(t, strings.Join(ranCommands[2], " "), "git config branch.pr/123/feature.remote robot-fork")
264-
eq(t, strings.Join(ranCommands[3], " "), "git config branch.pr/123/feature.merge refs/heads/feature")
262+
eq(t, strings.Join(ranCommands[1], " "), "git checkout -b feature --no-track robot-fork/feature")
263+
eq(t, strings.Join(ranCommands[2], " "), "git config branch.feature.remote robot-fork")
264+
eq(t, strings.Join(ranCommands[3], " "), "git config branch.feature.merge refs/heads/feature")
265265
}
266266

267267
func TestPRCheckout_differentRepo(t *testing.T) {
@@ -296,7 +296,7 @@ func TestPRCheckout_differentRepo(t *testing.T) {
296296
ranCommands := [][]string{}
297297
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
298298
switch strings.Join(cmd.Args, " ") {
299-
case "git config branch.pr/123/feature.merge":
299+
case "git config branch.feature.merge":
300300
return &errorStub{"exit status 1"}
301301
default:
302302
ranCommands = append(ranCommands, cmd.Args)
@@ -310,10 +310,10 @@ func TestPRCheckout_differentRepo(t *testing.T) {
310310
eq(t, output.String(), "")
311311

312312
eq(t, len(ranCommands), 4)
313-
eq(t, strings.Join(ranCommands[0], " "), "git fetch origin refs/pull/123/head:pr/123/feature")
314-
eq(t, strings.Join(ranCommands[1], " "), "git checkout pr/123/feature")
315-
eq(t, strings.Join(ranCommands[2], " "), "git config branch.pr/123/feature.remote origin")
316-
eq(t, strings.Join(ranCommands[3], " "), "git config branch.pr/123/feature.merge refs/pull/123/head")
313+
eq(t, strings.Join(ranCommands[0], " "), "git fetch origin refs/pull/123/head:feature")
314+
eq(t, strings.Join(ranCommands[1], " "), "git checkout feature")
315+
eq(t, strings.Join(ranCommands[2], " "), "git config branch.feature.remote origin")
316+
eq(t, strings.Join(ranCommands[3], " "), "git config branch.feature.merge refs/pull/123/head")
317317
}
318318

319319
func TestPRCheckout_differentRepo_existingBranch(t *testing.T) {
@@ -348,7 +348,7 @@ func TestPRCheckout_differentRepo_existingBranch(t *testing.T) {
348348
ranCommands := [][]string{}
349349
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
350350
switch strings.Join(cmd.Args, " ") {
351-
case "git config branch.pr/123/feature.merge":
351+
case "git config branch.feature.merge":
352352
return &outputStub{[]byte("refs/heads/feature\n")}
353353
default:
354354
ranCommands = append(ranCommands, cmd.Args)
@@ -362,13 +362,13 @@ func TestPRCheckout_differentRepo_existingBranch(t *testing.T) {
362362
eq(t, output.String(), "")
363363

364364
eq(t, len(ranCommands), 2)
365-
eq(t, strings.Join(ranCommands[0], " "), "git fetch origin refs/pull/123/head:pr/123/feature")
366-
eq(t, strings.Join(ranCommands[1], " "), "git checkout pr/123/feature")
365+
eq(t, strings.Join(ranCommands[0], " "), "git fetch origin refs/pull/123/head:feature")
366+
eq(t, strings.Join(ranCommands[1], " "), "git checkout feature")
367367
}
368368

369369
func TestPRCheckout_differentRepo_currentBranch(t *testing.T) {
370370
ctx := context.NewBlank()
371-
ctx.SetBranch("pr/123/feature")
371+
ctx.SetBranch("feature")
372372
ctx.SetRemotes(map[string]string{
373373
"origin": "OWNER/REPO",
374374
})
@@ -398,7 +398,7 @@ func TestPRCheckout_differentRepo_currentBranch(t *testing.T) {
398398
ranCommands := [][]string{}
399399
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
400400
switch strings.Join(cmd.Args, " ") {
401-
case "git config branch.pr/123/feature.merge":
401+
case "git config branch.feature.merge":
402402
return &outputStub{[]byte("refs/heads/feature\n")}
403403
default:
404404
ranCommands = append(ranCommands, cmd.Args)
@@ -448,7 +448,7 @@ func TestPRCheckout_maintainerCanModify(t *testing.T) {
448448
ranCommands := [][]string{}
449449
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
450450
switch strings.Join(cmd.Args, " ") {
451-
case "git config branch.pr/123/feature.merge":
451+
case "git config branch.feature.merge":
452452
return &errorStub{"exit status 1"}
453453
default:
454454
ranCommands = append(ranCommands, cmd.Args)
@@ -462,8 +462,8 @@ func TestPRCheckout_maintainerCanModify(t *testing.T) {
462462
eq(t, output.String(), "")
463463

464464
eq(t, len(ranCommands), 4)
465-
eq(t, strings.Join(ranCommands[0], " "), "git fetch origin refs/pull/123/head:pr/123/feature")
466-
eq(t, strings.Join(ranCommands[1], " "), "git checkout pr/123/feature")
467-
eq(t, strings.Join(ranCommands[2], " "), "git config branch.pr/123/feature.remote https://github.com/hubot/REPO.git")
468-
eq(t, strings.Join(ranCommands[3], " "), "git config branch.pr/123/feature.merge refs/heads/feature")
465+
eq(t, strings.Join(ranCommands[0], " "), "git fetch origin refs/pull/123/head:feature")
466+
eq(t, strings.Join(ranCommands[1], " "), "git checkout feature")
467+
eq(t, strings.Join(ranCommands[2], " "), "git config branch.feature.remote https://github.com/hubot/REPO.git")
468+
eq(t, strings.Join(ranCommands[3], " "), "git config branch.feature.merge refs/heads/feature")
469469
}

0 commit comments

Comments
 (0)