Repository navigation
Closed
Conversation
Adds IsCheckedOutInOtherWorktree helper to gitClient interface and gitExecuter. Uses git worktree list --porcelain to parse worktrees and check whether the target branch is checked out in any worktree other than the current one. Refs #12927. Signed-off-by: SAY-5 <[email protected]>
Fixes #12927. Previously, gh repo sync used git update-ref to fast-forward a branch that wasnt the currently checked-out branch. This works when no other worktree has the branch, but when a worktree does, update-ref silently advances the ref without updating that worktrees index or working tree. The other worktree is left with git thinking files are staged that havent actually changed. With this change, gh repo sync now uses IsCheckedOutInOtherWorktree and refuses to advance the ref with a helpful error telling the user to run sync from the other worktree (or check the branch out in the current worktree first) so git also updates the index/working tree. Signed-off-by: SAY-5 <[email protected]>
Signed-off-by: SAY-5 <[email protected]>
Add test case verifying that executeLocalRepoSync refuses to update the ref when the branch is checked out in another worktree. Also updates the existing non-current-branch UpdateBranch test to stub IsCheckedOutInOtherWorktree returning false so the happy path continues to work. Signed-off-by: SAY-5 <[email protected]>
Contributor
|
Thanks for your pull request! Unfortunately, it doesn't meet the minimum requirements for review:
Please update your PR to address the above. Requirements:
This PR will be automatically closed in 7 days if these requirements are not met. |
Contributor
|
Thank you for your contribution! Unfortunately, this pull request is not linked to a We encourage community contributions on issues labeled If you believe this was done in error, please let us know. |
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.
Fixes #12927.
Problem
gh repo synccurrently usesgit update-refto fast-forward a branch that isn't the currently checked-out branch (in the current worktree). That works when no other worktree has the branch checked out, but when a worktree does,update-refsilently advances the ref without updating that worktree's index or working tree. The other worktree is left in an inconsistent state —git statusshows every file changed between the old and new commit as "staged changes".Reproducer from #12927:
Fix
Before
UpdateBranch(which runsgit update-ref), check whether the target branch is checked out in any worktree other than the current one. If it is, refuse to sync and tell the user what to do instead.Implementation:
gitClientgainsIsCheckedOutInOtherWorktree(branch) (bool, error).gitExecuterimplements it viagit worktree list --porcelain, scanning for abranch refs/heads/<name>record whose worktree path is different from the current worktree (determined viagit rev-parse --show-toplevel).executeLocalRepoSynccalls this beforeUpdateBranchand returns a clear error when the branch is in another worktree.Only the
update-refpath is guarded. The current-worktree path still usesgit merge --ff-only/git reset --hard, which correctly update the index and working tree. TheCreateBranchpath is unaffected (new branches can't be checked out anywhere yet).Error message
Tests
IsCheckedOutInOtherWorktree→falseso the happy path still exercisesUpdateBranch.IsCheckedOutInOtherWorktree→trueand asserts the new error message.mocks.go.No new integration tests — the
git worktree list --porcelainparsing is simple enough to unit-test via the mock, and the existing integration test matrix exercises the worktree-less happy paths.Behavior change
Users who previously triggered this silent corruption now see an error instead. That's the point — they were already getting a broken worktree; now they get a clear message telling them how to proceed.