Skip to content

fix: fetch after merge in land_pr to update remote refs#117

Open
gvaish wants to merge 1 commit intomodular:mainfrom
gvaish:fix/land-fetch-after-merge
Open

fix: fetch after merge in land_pr to update remote refs#117
gvaish wants to merge 1 commit intomodular:mainfrom
gvaish:fix/land-fetch-after-merge

Conversation

@gvaish
Copy link

@gvaish gvaish commented Feb 18, 2026

Problem

When land is run with a single-PR stack, the current branch is not correctly rebased onto the post-merge origin/main.

Root cause: land_pr does a git fetch before calling gh pr merge --squash, but not after. The squash commit lands on the remote, but the local origin/{target} ref is still stale. The final rebase in command_land then runs against the pre-merge ref - a no-op - leaving the current branch behind.

Why multi-PR stacks are unaffected: rebase_pr begins with its own git fetch --prune, which incidentally refreshes origin/{target} in time for the final current_branch rebase. Single-PR stacks skip the rebase_pr loop entirely, so no fetch ever happens after the merge.

Fix

Add git fetch --prune inside land_pr, immediately after gh pr merge. This makes land_pr self-contained: after it returns, remote refs reflect the newly landed commit. The fetch is harmless for multi-PR stacks (a slight redundancy with the fetch at the start of rebase_pr).

Reproducer

  1. Have a single commit on a branch with a submitted PR (stack-pr submit)
  2. Run stack-pr land
  3. Check git log --oneline origin/main..HEAD — the current branch still contains the (now-landed) commit instead of being empty

After `gh pr merge --squash`, the remote (e.g. origin/main) has a new
squash commit, but no git fetch is performed before the final rebase of
the current branch in command_land. For single-PR stacks this means
origin/{target} is stale (land_pr fetches *before* the merge), so the
rebase is a no-op against the pre-merge ref and the current branch is
not brought up-to-date.

For multi-PR stacks the bug is masked because rebase_pr starts with its
own fetch, which incidentally updates origin/{target} in time for the
final rebase. Adding the fetch inside land_pr makes the function
self-contained and fixes the single-PR case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments