diff --git a/.changes/unreleased/Fixed-20241126-195502.yaml b/.changes/unreleased/Fixed-20241126-195502.yaml new file mode 100644 index 00000000..af460020 --- /dev/null +++ b/.changes/unreleased/Fixed-20241126-195502.yaml @@ -0,0 +1,3 @@ +kind: Fixed +body: 'submit: Present a warning if submission might fail because of an unsubmitted base branch.' +time: 2024-11-26T19:55:02.491968-08:00 diff --git a/branch_submit.go b/branch_submit.go index bc19bf56..2c567dcc 100644 --- a/branch_submit.go +++ b/branch_submit.go @@ -190,12 +190,14 @@ func (cmd *branchSubmitCmd) run( // Similarly, if the branch's base has a different name upstream, // use that name instead. upstreamBase := branch.Base + baseWasSubmitted := true if branch.Base != store.Trunk() { baseBranch, err := svc.LookupBranch(ctx, branch.Base) if err != nil { return fmt.Errorf("lookup base branch: %w", err) } upstreamBase = cmp.Or(baseBranch.UpstreamBranch, branch.Base) + baseWasSubmitted = baseBranch.Change != nil } var existingChange *forge.FindChangeItem @@ -343,6 +345,13 @@ func (cmd *branchSubmitCmd) run( // At this point, existingChange is nil only if we need to create a new CR. if existingChange == nil { + // If we're definitely creating a new CR, + // make sure that the branch's base has been submitted. + if !baseWasSubmitted { + log.Warnf("%v: submit may fail: base %v has not been submitted", + cmd.Branch, upstreamBase) + } + if upstreamBranch == "" { unique, err := svc.UnusedBranchName(ctx, remote, cmd.Branch) if err != nil { diff --git a/testdata/script/issue460_branch_submit_unsubmitted_base.txt b/testdata/script/issue460_branch_submit_unsubmitted_base.txt new file mode 100644 index 00000000..60e0e6f9 --- /dev/null +++ b/testdata/script/issue460_branch_submit_unsubmitted_base.txt @@ -0,0 +1,35 @@ +# branch submit presents a good message when the base branch for a CR +# hasn't been submitted yet. +# +# https://github.com/abhinav/git-spice/issues/460 + +as 'Test ' +at '2024-11-26T19:20:21Z' + +# setup +cd repo +git init +git commit --allow-empty -m 'Initial commit' + +shamhub init +shamhub new origin alice/example.git +shamhub register alice +git push origin main + +env SHAMHUB_USERNAME=alice +gs auth login + +# set up main -> feat1 -> feat2 +git add feat1.txt +gs bc -m feat1 +git add feat2.txt +gs bc -m feat2 + +# attempt to submit feat2 +! gs branch submit --fill +stderr 'feat2: submit may fail: base feat1 has not been submitted' + +-- repo/feat1.txt -- +feat 1 +-- repo/feat2.txt -- +feat 2