Repository navigation
Update branches in place and use each branch's own base (works in worktrees) - #37
Merged
Merged
Conversation
…he base When the branch is behind origin/<base>, fetch the base and merge origin/<base> into the current branch (or rebase onto it with strategy = rebase) rather than checking out the base branch, pulling it and checking the feature branch out again. Git refuses to check out a branch that is checked out in another worktree, so the old flow failed in worktrees. Conflict instructions now say how to finish for each strategy, rebase conflicts are detected too (stderr is captured), and other git failures exit with git's message instead of a traceback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
git pullrequest assumed every branch came from gitfeatures.masterBranch,
so a branch cut from a release branch was merged with, and had its PR
opened against, main.
Each branch now has a base, kept in branch.<name>.gitfeaturesBase.
git feature new and git release/stable/hotfix new record the branch
they were run from. git pullrequest takes the base from --base, the
recorded value, or git's reflog ("Created from origin/release_x") for
branches made outside gitfeatures; failing those it asks whether the
base is masterBranch rather than assuming it. It records what it used,
updates the branch from origin/<base> and opens the PR against it.
git feature finish checks the branch is merged into its own base.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
finish_feature checked out masterBranch before anything else, which fails in a git worktree while the base branch is checked out in another worktree, and left you on the base branch even when it then refused. It now resolves the base the same way as git pullrequest (and takes --base), checks the branch is merged into origin/<base> before moving off it, then switches to the base branch if no worktree has it checked out, or detaches at origin/<base> if one does. Finishing a named branch that is checked out in another worktree stops with that worktree's path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When GitHub deletes a branch after its PR is merged, `git push origin :<branch>` fails and finish exited before deleting the local branch. It now checks origin with ls-remote first; if the branch is already gone it says so, drops the stale origin/<branch> ref and deletes the local branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
git pullrequestbrought a branch up to date by checking out the base branch, pulling it, and checking the feature branch out again. Git won't check out a branch that is already checked out in another worktree, so this failed in a worktree whenevermainwas checked out somewhere else. That's the normal setup for Harper's repos, which have many sibling worktrees. It also assumed every branch came fromgitfeatures.masterBranch. A branch cut from a release branch was therefore merged withmain, and its PR was opened againstmain.What changes
git pullrequestupdates the branch in place. It runsgit fetch origin <base>, thengit merge origin/<base>, orgit rebase origin/<base>withstrategy = rebase. It never checks out the base branch. On conflicts it still stops, and now says how to finish for each strategy. It catches rebase conflicts too, and other git failures print git's own message instead of a traceback.branch.<name>.gitfeaturesBase:git feature newandgit release/stable/hotfix newrecord the branch they were run from.git pullrequesttakes the base from--base <branch>, then the recorded value, then git's reflog (Created from origin/release_x) for branches made outside gitfeatures. If none of those gives an answer, it asks whether the base ismasterBranchinstead of assuming it.origin/<base>and opens the PR against<base>. The API call, the GitHub compare URL and Bitbucket'sdestall use it.git feature finishworks out the base the same way and also takes--base. It checks the branch is merged intoorigin/<base>before moving off it. It then switches to the base branch, or detaches atorigin/<base>when another worktree has the base branch checked out.git feature finishwhen origin already deleted the branch (e.g. GitHub's automatic delete after a merge): it now deletes the local branch and the staleorigin/<branch>, where before it stopped with the local branch still there.Behaviour change to note
git pullrequestnow asks once ("Was it main? [y/n]") for a branch whose start point it can't tell, where it used to assumemainsilently. This applies when gitfeatures didn't create the branch and git only loggedCreated from HEAD. The answer is recorded, so it's asked only once per branch.Tests
tests/test_pullrequest.pyhas 10 tests, mostly with the base branch checked out in another worktree:feature newoff a release branchgit worktree add -b(base taken from the reflog)--basefeature finishagainst its own base, from a worktree, and after origin deleted the branchEach was checked to fail before its fix.
pre-commit run --all-filesandpytestpass, with 71 tests.README ("Base branches" section, command reference, troubleshooting) and CHANGELOG are updated.
🤖 Generated with Claude Code