Skip to content

Commit d124553

Browse files
committed
ignore if ref doesn't exist on remote
1 parent 1cae0c0 commit d124553

4 files changed

Lines changed: 15 additions & 13 deletions

File tree

cmd/link.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,10 @@ func pushBranchArgs(cfg *config.Config, opts *linkOptions, args []string) error
161161
return ErrSilent
162162
}
163163

164-
if err := git.FetchBranches(remote, branches); err != nil {
165-
cfg.Warningf("Failed to fetch branches from %s: %v", remote, err)
166-
}
164+
// Best-effort fetch to update tracking refs (helps --force-with-lease
165+
// in shallow clones). Silently ignored if branches don't exist on the
166+
// remote yet.
167+
_ = git.FetchBranches(remote, branches)
167168

168169
cfg.Printf("Pushing %d %s to %s...", len(branches), plural(len(branches), "branch", "branches"), remote)
169170
if err := git.Push(remote, branches, false, true); err != nil {

cmd/push.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ func runPush(cfg *config.Config, opts *pushOptions) error {
9393
cfg.Printf("No active branches to push (all merged or queued)")
9494
return nil
9595
}
96-
if err := git.FetchBranches(remote, activeBranches); err != nil {
97-
cfg.Warningf("Failed to fetch branches from %s: %v", remote, err)
98-
}
96+
// Best-effort fetch to update tracking refs (helps --force-with-lease
97+
// in shallow clones). Silently ignored if branches don't exist on the
98+
// remote yet.
99+
_ = git.FetchBranches(remote, activeBranches)
99100
cfg.Printf("Pushing %d %s to %s...", len(activeBranches), plural(len(activeBranches), "branch", "branches"), remote)
100101
if err := git.Push(remote, activeBranches, true, false); err != nil {
101102
cfg.Errorf("failed to push: %s", err)

cmd/push_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func TestPush_FetchFailureIsNonFatal(t *testing.T) {
262262

263263
assert.NoError(t, err, "fetch failure should not abort push")
264264
assert.True(t, pushCalled, "push should proceed after fetch failure")
265-
assert.Contains(t, string(errOut), "Failed to fetch")
265+
assert.NotContains(t, string(errOut), "Failed to fetch", "fetch failure should be silent")
266266
}
267267

268268
func TestPush_DoesNotCreatePRs(t *testing.T) {

cmd/submit.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ func runSubmit(cfg *config.Config, opts *submitOptions) error {
5959
return ErrNotInStack
6060
}
6161

62+
cfg.Printf("Checking stack state...")
63+
6264
// Find the stack for the current branch without switching branches.
6365
// Submit should never change the user's checked-out branch.
6466
stacks := sf.FindAllStacksForBranch(currentBranch)
@@ -141,12 +143,10 @@ func runSubmit(cfg *config.Config, opts *submitOptions) error {
141143
}
142144
}
143145

144-
// Fetch the active branches from the remote so that the local tracking refs
145-
// are up-to-date before pushing. This ensures --force-with-lease has accurate
146-
// remote state even in shallow clones.
147-
if err := git.FetchBranches(remote, activeBranches); err != nil {
148-
cfg.Warningf("Failed to fetch branches from %s: %v", remote, err)
149-
}
146+
// Best-effort fetch to update tracking refs (helps --force-with-lease
147+
// in shallow clones). Silently ignored if branches don't exist on the
148+
// remote yet.
149+
_ = git.FetchBranches(remote, activeBranches)
150150

151151
// Push each branch and create/update its PR in stack order (bottom to top).
152152
// Sequential pushing ensures each branch's base is up-to-date on the

0 commit comments

Comments
 (0)