Skip to content

Fix local branch rebasing after land#120

Open
roxchkplusony wants to merge 2 commits intomodular:mainfrom
inclined-tech:fix/land-align-local-stack-commits
Open

Fix local branch rebasing after land#120
roxchkplusony wants to merge 2 commits intomodular:mainfrom
inclined-tech:fix/land-align-local-stack-commits

Conversation

@roxchkplusony
Copy link

Summary

This change updates stack-pr land so that when the current branch contains the stack being landed, the local branch is rebased onto the updated stack tip rather than being rebased independently onto origin/main.

As a result, the local branch now reuses the same rewritten commits as the remaining PR branches after landing, and then rebases any additional local commits on top as usual.

This PR also includes a follow-up fix so that the rewritten stack tip is resolved to a stable commit hash before local stack branches are cleaned up.

Problem

Previously, stack-pr land would:

  1. land the bottom-most PR,
  2. rebase the remaining PR branches, and then
  3. rebase the current branch directly onto origin/<target>.

That preserved equivalent content, but it did not guarantee that the local branch would be based on the same commit chain as the PR branches. In practice, the local branch could diverge from the rewritten stack and end up with different commit identities.

A follow-up regression also remained when PRs still existed above the landed one: the command tracked the rewritten remaining stack tip by local branch name, then deleted the local stack branches before rebasing the current branch. In real usage this could fail with fatal: invalid upstream '<branch>'.

Fix

This change adjusts command_land to:

  • detect whether the current branch contains the stack being landed,
  • refresh the remote target branch after the merge,
  • track the correct post-land base for the current branch,
  • rebase the current branch onto the updated stack tip when appropriate, and
  • resolve the rewritten remaining stack tip to a commit hash before deleting local stack branches.

If there are no remaining PRs in the stack, the current branch is still rebased onto the refreshed origin/<target>.

Tests

Added regression coverage for the land command flow:

  • verify the current branch is rebased onto the updated remaining stack tip when PRs remain,
  • verify the rewritten stack tip is resolved before local stack branches are deleted,
  • verify the stale branch name is not used for the final current-branch rebase,
  • verify the target branch is refreshed before rebasing the current branch.

Validation

Validated locally with:

  • python3 -m py_compile src/stack_pr/cli.py tests/test_land.py
  • pytest tests/test_land.py
  • pytest

The pytest runs were executed in the repo's pyenv virtualenv (Python 3.9.25).

Pytest emits two existing config warnings about unknown asyncio_default_fixture_loop_scope and asyncio_mode options, but all tests pass.


Pull Request opened by Augment Code with guidance from the PR author

@roxchkplusony
Copy link
Author

NOTE: This also seems to fix #117

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