Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

submit: warn if a branch's base is unsubmitted #499

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading