Skip to content

Commit

Permalink
Merge pull request cli#429 from cli/co-drawing-board
Browse files Browse the repository at this point in the history
revert pr checkout branch prefixing
  • Loading branch information
Nate Smith authored Feb 13, 2020
2 parents 2e7fedd + c5a511a commit 96dc437
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
3 changes: 1 addition & 2 deletions command/pr_checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ func prCheckout(cmd *cobra.Command, args []string) error {

cmdQueue := [][]string{}

// namespace PR checkout branches to avoid local branch name collisions
newBranchName := fmt.Sprintf("pr/%d/%s", pr.Number, pr.HeadRefName)
newBranchName := pr.HeadRefName
if headRemote != nil {
// there is an existing git remote for PR head
remoteBranch := fmt.Sprintf("%s/%s", headRemote.Name, pr.HeadRefName)
Expand Down
58 changes: 29 additions & 29 deletions command/pr_checkout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestPRCheckout_sameRepo(t *testing.T) {
ranCommands := [][]string{}
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
switch strings.Join(cmd.Args, " ") {
case "git show-ref --verify --quiet refs/heads/pr/123/feature":
case "git show-ref --verify --quiet refs/heads/feature":
return &errorStub{"exit status: 1"}
default:
ranCommands = append(ranCommands, cmd.Args)
Expand All @@ -57,9 +57,9 @@ func TestPRCheckout_sameRepo(t *testing.T) {

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

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

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

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

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

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

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

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

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

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

eq(t, len(ranCommands), 4)
eq(t, strings.Join(ranCommands[0], " "), "git fetch origin refs/pull/123/head:pr/123/feature")
eq(t, strings.Join(ranCommands[1], " "), "git checkout pr/123/feature")
eq(t, strings.Join(ranCommands[2], " "), "git config branch.pr/123/feature.remote origin")
eq(t, strings.Join(ranCommands[3], " "), "git config branch.pr/123/feature.merge refs/pull/123/head")
eq(t, strings.Join(ranCommands[0], " "), "git fetch origin refs/pull/123/head:feature")
eq(t, strings.Join(ranCommands[1], " "), "git checkout feature")
eq(t, strings.Join(ranCommands[2], " "), "git config branch.feature.remote origin")
eq(t, strings.Join(ranCommands[3], " "), "git config branch.feature.merge refs/pull/123/head")
}

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

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

func TestPRCheckout_differentRepo_currentBranch(t *testing.T) {
ctx := context.NewBlank()
ctx.SetBranch("pr/123/feature")
ctx.SetBranch("feature")
ctx.SetRemotes(map[string]string{
"origin": "OWNER/REPO",
})
Expand Down Expand Up @@ -398,7 +398,7 @@ func TestPRCheckout_differentRepo_currentBranch(t *testing.T) {
ranCommands := [][]string{}
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
switch strings.Join(cmd.Args, " ") {
case "git config branch.pr/123/feature.merge":
case "git config branch.feature.merge":
return &outputStub{[]byte("refs/heads/feature\n")}
default:
ranCommands = append(ranCommands, cmd.Args)
Expand Down Expand Up @@ -448,7 +448,7 @@ func TestPRCheckout_maintainerCanModify(t *testing.T) {
ranCommands := [][]string{}
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
switch strings.Join(cmd.Args, " ") {
case "git config branch.pr/123/feature.merge":
case "git config branch.feature.merge":
return &errorStub{"exit status 1"}
default:
ranCommands = append(ranCommands, cmd.Args)
Expand All @@ -462,8 +462,8 @@ func TestPRCheckout_maintainerCanModify(t *testing.T) {
eq(t, output.String(), "")

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

0 comments on commit 96dc437

Please sign in to comment.