Skip to content

Commit

Permalink
submit: warn if a branch's base is unsubmitted
Browse files Browse the repository at this point in the history
Resolves #460
  • Loading branch information
abhinav committed Nov 27, 2024
1 parent 285a611 commit f74dbfb
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Fixed-20241126-195502.yaml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions branch_submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
35 changes: 35 additions & 0 deletions testdata/script/issue460_branch_submit_unsubmitted_base.txt
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>'
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

0 comments on commit f74dbfb

Please sign in to comment.