Merge pull request #9477 from benebsiny/cli-9496
fix behavior for `gh issue develop -b does-not-exist-on-remote`
This commit is contained in:
commit
4f681aaee1
3 changed files with 29 additions and 1 deletions
|
|
@ -138,6 +138,9 @@ func FindRepoBranchID(client *Client, repo ghrepo.Interface, ref string) (string
|
|||
|
||||
branchID := query.Repository.Ref.Target.Oid
|
||||
if branchID == "" {
|
||||
if ref != "" {
|
||||
return "", "", fmt.Errorf("could not find branch %q in %s", ref, ghrepo.FullName(repo))
|
||||
}
|
||||
branchID = query.Repository.DefaultBranchRef.Target.Oid
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ func NewCmdDevelop(f *cmdutil.Factory, runF func(*DevelopOptions) error) *cobra.
|
|||
|
||||
fl := cmd.Flags()
|
||||
fl.StringVar(&opts.BranchRepo, "branch-repo", "", "Name or URL of the repository where you want to create your new branch")
|
||||
fl.StringVarP(&opts.BaseBranch, "base", "b", "", "Name of the base branch you want to make your new branch from")
|
||||
fl.StringVarP(&opts.BaseBranch, "base", "b", "", "Name of the remote branch you want to make your new branch from")
|
||||
fl.BoolVarP(&opts.Checkout, "checkout", "c", false, "Checkout the branch after creating it")
|
||||
fl.BoolVarP(&opts.List, "list", "l", false, "List linked branches for the issue")
|
||||
fl.StringVarP(&opts.Name, "name", "n", "", "Name of the branch to create")
|
||||
|
|
|
|||
|
|
@ -515,6 +515,31 @@ func TestDevelopRun(t *testing.T) {
|
|||
},
|
||||
expectedOut: "github.com/OWNER/REPO/tree/my-branch\n",
|
||||
},
|
||||
{
|
||||
name: "develop with base branch which does not exist",
|
||||
opts: &DevelopOptions{
|
||||
IssueSelector: "123",
|
||||
BaseBranch: "does-not-exist-branch",
|
||||
},
|
||||
remotes: map[string]string{
|
||||
"origin": "OWNER/REPO",
|
||||
},
|
||||
httpStubs: func(reg *httpmock.Registry, t *testing.T) {
|
||||
reg.Register(
|
||||
httpmock.GraphQL(`query LinkedBranchFeature\b`),
|
||||
httpmock.StringResponse(featureEnabledPayload),
|
||||
)
|
||||
reg.Register(
|
||||
httpmock.GraphQL(`query IssueByNumber\b`),
|
||||
httpmock.StringResponse(`{"data":{"repository":{"hasIssuesEnabled":true,"issue":{"id": "SOMEID","number":123,"title":"my issue"}}}}`),
|
||||
)
|
||||
reg.Register(
|
||||
httpmock.GraphQL(`query FindRepoBranchID\b`),
|
||||
httpmock.StringResponse(`{"data":{"repository":{"id":"REPOID","defaultBranchRef":{"target":{"oid":"DEFAULTOID"}},"ref":null}}}`),
|
||||
)
|
||||
},
|
||||
wantErr: "could not find branch \"does-not-exist-branch\" in OWNER/REPO",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue