Conversation
skarim
added this pull request to stack #530
September 28, 2026 17:20
skarim
marked this pull request as ready for review
September 29, 2026 16:27
Contributor
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
The broad, cross-platform changes to Git execution identity and recovery behavior warrant final human validation.
Review effort: Balanced
Findings: None
What changed in this PR
Adds worktree-scoped Git execution while preserving repository identity and isolating checkout-specific state.
Changes:
- Adds worktree discovery, validation, and scoped Git clients.
- Makes rebase, conflict, and cherry-pick operations receiver-scoped.
- Adds extensive integration coverage for worktree behavior and recovery.
| File | Description |
|---|---|
internal/git/worktree.go |
Implements worktree discovery and scoping. |
internal/git/worktree_test.go |
Tests parsing, versions, wrappers, and environment isolation. |
internal/git/git.go |
Adds scoped command execution and rebase policy. |
internal/git/gitops.go |
Routes Git operations through scoped receivers. |
internal/git/gitops_test.go |
Adds linked-worktree integration coverage. |
internal/git/mock_ops.go |
Extends mocks for worktree APIs. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This branch has not been deployed
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.


Git worktrees share branch refs and objects, but each has its own HEAD, index, working files, and paused Git operations. This PR adds explicit worktree-scoped Git execution: the foundation for independent stacks in separate checkouts and for one stack whose layers live across several worktrees.
Functionality and user impact
Boundary: this PR does not move stack metadata, add navigation flags, or automatically run stack commands in other worktrees. Shared tracking follows in #528, cross-worktree rebase/sync in #529, and distributed modify in #521. Discovery requires Git 2.36+; this supports existing worktrees, not their creation or removal.
Key areas to review
internal/git/worktree.go:ForWorktreeandgitClientbind execution to a repository/worktree identity. Focus on rejecting a changed Git directory rather than falling back to the caller.internal/git/worktree.go:Worktrees,rebaseBranch, andresolveMainWorktreehandle ownership during detached rebases and separate Git directories. Existingcore.worktreebacklinks are used; unknown checkout paths are not guessed.internal/git/git.go:configureCommand,rebaseArgs, andrunRebaseCommandisolate the environment, set rebase policy, and distinguish a failure to start from a recoverable conflict.internal/git/gitops.go: followRebaseOnto,RebaseContinue, and the conflict/cherry-pick helpers to confirm checkout-sensitive operations stay on the scoped receiver.Related issues
gh stack rebasesilently succeeds whengit rebase --ontofails to start (in branch checked out in another worktree) #35*Part 1 of the 4-PR split of #520