Skip to content

Commit c4ec0a6

Browse files
authored
Merge pull request cli#4363 from RasmusWL/patch-1
Also set `pushRemote` on `gh pr checkout` from fork
2 parents af812e2 + 9e3893e commit c4ec0a6

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

pkg/cmd/pr/checkout/checkout.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,11 @@ func cmdsForMissingRemote(pr *api.PullRequest, baseURLOrName, repoHost, defaultB
220220
mergeRef = fmt.Sprintf("refs/heads/%s", pr.HeadRefName)
221221
}
222222
if missingMergeConfigForBranch(localBranch) {
223+
// .remote is needed for `git pull` to work
224+
// .pushRemote is needed for `git push` to work, if user has set `remote.pushDefault`.
225+
// see https://git-scm.com/docs/git-config#Documentation/git-config.txt-branchltnamegtremote
223226
cmds = append(cmds, []string{"git", "config", fmt.Sprintf("branch.%s.remote", localBranch), remote})
227+
cmds = append(cmds, []string{"git", "config", fmt.Sprintf("branch.%s.pushRemote", localBranch), remote})
224228
cmds = append(cmds, []string{"git", "config", fmt.Sprintf("branch.%s.merge", localBranch), mergeRef})
225229
}
226230

pkg/cmd/pr/checkout/checkout_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ func Test_checkoutRun(t *testing.T) {
9797
cs.Register(`git config branch\.feature\.merge`, 1, "")
9898
cs.Register(`git checkout feature`, 0, "")
9999
cs.Register(`git config branch\.feature\.remote origin`, 0, "")
100+
cs.Register(`git config branch\.feature\.pushRemote origin`, 0, "")
100101
cs.Register(`git config branch\.feature\.merge refs/pull/123/head`, 0, "")
101102
},
102103
},
@@ -152,6 +153,7 @@ func Test_checkoutRun(t *testing.T) {
152153
cs.Register(`git fetch origin refs/pull/123/head:foobar`, 0, "")
153154
cs.Register(`git checkout foobar`, 0, "")
154155
cs.Register(`git config branch\.foobar\.remote https://github.com/hubot/REPO.git`, 0, "")
156+
cs.Register(`git config branch\.foobar\.pushRemote https://github.com/hubot/REPO.git`, 0, "")
155157
cs.Register(`git config branch\.foobar\.merge refs/heads/feature`, 0, "")
156158
},
157159
},
@@ -343,6 +345,7 @@ func TestPRCheckout_differentRepo(t *testing.T) {
343345
cs.Register(`git config branch\.feature\.merge`, 1, "")
344346
cs.Register(`git checkout feature`, 0, "")
345347
cs.Register(`git config branch\.feature\.remote origin`, 0, "")
348+
cs.Register(`git config branch\.feature\.pushRemote origin`, 0, "")
346349
cs.Register(`git config branch\.feature\.merge refs/pull/123/head`, 0, "")
347350

348351
output, err := runCommand(http, nil, "master", `123`)
@@ -442,6 +445,7 @@ func TestPRCheckout_maintainerCanModify(t *testing.T) {
442445
cs.Register(`git config branch\.feature\.merge`, 1, "")
443446
cs.Register(`git checkout feature`, 0, "")
444447
cs.Register(`git config branch\.feature\.remote https://github\.com/hubot/REPO\.git`, 0, "")
448+
cs.Register(`git config branch\.feature\.pushRemote https://github\.com/hubot/REPO\.git`, 0, "")
445449
cs.Register(`git config branch\.feature\.merge refs/heads/feature`, 0, "")
446450

447451
output, err := runCommand(http, nil, "master", `123`)

0 commit comments

Comments
 (0)