Skip to content

Commit 2c54a0d

Browse files
Merge pull request cli#12673 from cli/wm-explore-fork-branches-in-pr
Fork with default branch only during pr create
2 parents 4e65637 + 2b5c3b5 commit 2c54a0d

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

pkg/cmd/pr/create/create.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
214214
Upon success, the URL of the created pull request will be printed.
215215
216216
When the current branch isn't fully pushed to a git remote, a prompt will ask where
217-
to push the branch and offer an option to fork the base repository. Use %[1]s--head%[1]s to
217+
to push the branch and offer an option to fork the base repository. Any fork created this
218+
way will only have the default branch of the upstream repository. Use %[1]s--head%[1]s to
218219
explicitly skip any forking or pushing behavior.
219220
220221
%[1]s--head%[1]s supports %[1]s<user>:<branch>%[1]s syntax to select a head repo owned by %[1]s<user>%[1]s.
@@ -1128,7 +1129,7 @@ func handlePush(opts CreateOptions, ctx CreateContext) error {
11281129
forkableRefs, requiresFork := refs.(forkableRefs)
11291130
if requiresFork {
11301131
opts.IO.StartProgressIndicator()
1131-
forkedRepo, err := api.ForkRepo(ctx.Client, forkableRefs.BaseRepo(), "", "", false)
1132+
forkedRepo, err := api.ForkRepo(ctx.Client, forkableRefs.BaseRepo(), "", "", true)
11321133
opts.IO.StopProgressIndicator()
11331134
if err != nil {
11341135
return fmt.Errorf("error forking repo: %w", err)

pkg/cmd/pr/create/create_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,11 +894,13 @@ func Test_createRun(t *testing.T) {
894894
httpmock.StringResponse(`{"data": {"viewer": {"login": "monalisa"} } }`))
895895
reg.Register(
896896
httpmock.REST("POST", "repos/OWNER/REPO/forks"),
897-
httpmock.StatusStringResponse(201, `
897+
httpmock.RESTPayload(201, `
898898
{ "node_id": "NODEID",
899899
"name": "REPO",
900900
"owner": {"login": "monalisa"}
901-
}`))
901+
}`, func(payload map[string]interface{}) {
902+
assert.Equal(t, true, payload["default_branch_only"])
903+
}))
902904
reg.Register(
903905
httpmock.GraphQL(`mutation PullRequestCreate\b`),
904906
httpmock.GraphQLMutation(`

0 commit comments

Comments
 (0)