Conversation
skarim
added this pull request to stack #530
September 28, 2026 17:20
skarim
force-pushed
the
skarim/worktrees-shared-tracking
branch
from
September 28, 2026 21:37
c413105 to
4c1661f
Compare
This was referenced Sep 29, 2026
skarim
marked this pull request as ready for review
September 29, 2026 16:28
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Pending one-layer submissions can remain permanently blocked, and modify continuation can falsely accept a missing rebase.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Moves stack tracking to repository-wide shared state so linked worktrees can safely share catalogs, navigation, locking, and recovery.
Changes:
- Adds conservative legacy-catalog migration and clone-wide mutation locking.
- Adds worktree-aware adoption, navigation, and
--print-path. - Adds ownership preflight and shared recovery for rebase, sync, and modify.
| File | Description |
|---|---|
.github/copilot-instructions.md |
Documents shared-state architecture. |
AGENTS.md |
Updates contributor guidance. |
README.md |
Documents worktree support. |
cmd/add.go |
Supports foreign-owned branch adoption. |
cmd/add_test.go |
Tests worktree-aware add behavior. |
cmd/checkout.go |
Adds path-mode checkout. |
cmd/checkout_test.go |
Tests checkout ownership and paths. |
cmd/init.go |
Supports adopting branches across worktrees. |
cmd/init_test.go |
Tests cross-worktree initialization. |
cmd/link.go |
Coordinates link mutations. |
cmd/link_test.go |
Tests link locking. |
cmd/merge.go |
Uses shared mutation state. |
cmd/merge_test.go |
Tests merge coordination. |
cmd/modify.go |
Adds ownership and recovery preflight. |
cmd/modify_test.go |
Tests distributed-stack rejection. |
cmd/navigate.go |
Adds worktree-aware path navigation. |
cmd/navigate_test.go |
Tests navigation paths and ownership. |
cmd/push.go |
Coordinates push mutations. |
cmd/rebase.go |
Adds origin-bound shared recovery. |
cmd/rebase_test.go |
Tests rebase ownership and recovery. |
cmd/submit.go |
Matches pending recovery to stacks. |
cmd/submit_test.go |
Tests modify/submit recovery integration. |
cmd/switch.go |
Adds path-aware switching. |
cmd/switch_test.go |
Tests worktree-aware switching. |
cmd/sync.go |
Adds reconciliation ownership preflight. |
cmd/sync_test.go |
Tests sync worktree boundaries. |
cmd/trunk.go |
Adds trunk path navigation. |
cmd/unstack.go |
Uses shared catalogs and locking. |
cmd/unstack_test.go |
Tests shared-state unstack behavior. |
cmd/utils.go |
Centralizes shared stack resolution. |
cmd/utils_test.go |
Tests migration and locking helpers. |
cmd/view.go |
Reads shared catalogs safely. |
cmd/view_test.go |
Tests shared-state views. |
cmd/worktree_utils.go |
Implements state routing and ownership lookup. |
docs/src/content/docs/getting-started/quick-start.md |
Updates prerequisites. |
docs/src/content/docs/guides/modify.md |
Documents modify limitations. |
docs/src/content/docs/guides/workflows.md |
Documents worktree workflows. |
docs/src/content/docs/reference/cli.md |
Updates CLI behavior. |
internal/config/config.go |
Adds explicit non-interactive mode. |
internal/git/mock_ops.go |
Extends Git test doubles. |
internal/modify/apply.go |
Adds context-tracked continuation. |
internal/modify/apply_test.go |
Tests modify recovery behavior. |
internal/modify/preconditions.go |
Rejects unsupported distributed modifies. |
internal/modify/recovery.go |
Adds conservative shared recovery. |
internal/modify/state.go |
Records and matches stack identity. |
internal/stack/lock.go |
Adds clone-wide operation locking. |
internal/stack/migration.go |
Consolidates legacy catalogs safely. |
internal/stack/stack.go |
Supports shared catalog persistence. |
internal/worktree/context.go |
Tracks worktree-owned mutations. |
internal/worktree/context_test.go |
Tests mutation tracking and restoration. |
skills/gh-stack/SKILL.md |
Updates agent worktree guidance. |
skills/gh-stack/references/commands.md |
Documents command behavior. |
skills/gh-stack/references/troubleshooting.md |
Documents migration and recovery. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+897
to
+903
| if ops.IsRebaseInProgress() { | ||
| if err := ops.RebaseContinue(git.RebaseOpts{}); err != nil { | ||
| return fmt.Errorf("rebase continue failed in %s — resolve remaining conflicts and try again: %w", ctx.Origin.Path, err) | ||
| } | ||
| } | ||
| if err := ctx.Record(state.ConflictBranch); err != nil { | ||
| return err |
Comment on lines
+264
to
+265
| if stackSynced { | ||
| if err := clearPendingModifyState(cfg, s, gitDir); err != nil { |
skarim
force-pushed
the
skarim/worktrees-shared-tracking
branch
from
September 29, 2026 22:47
4c1661f to
7286fc2
Compare
skarim
force-pushed
the
skarim/worktrees-shared-tracking
branch
from
September 29, 2026 23:14
7286fc2 to
b83f71a
Compare
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.


Makes stack tracking belong to the repository, not the directory where
initran. Worktrees can hold independent stacks or different branches of the same stack without losing tracking information when a checkout is removed.Functionality and user impact
<common-dir>/gh-stack. Older tracking files are combined automatically when their definitions agree or describe separate stacks. Backups are preserved; conflicting definitions stop with guidance instead of choosing one.initandaddcan adopt a branch checked out elsewhere without switching either checkout. Commit/stage shortcuts cannot target another worktree. Navigation reports that branch's location;--print-pathprints it, or checks out an available branch locally before printing the current path.Boundary: rebase/sync still refuse stacks with member branches—or a trunk they would update—checked out elsewhere. Migration may happen before that refusal, and rebase recovery must run where it started. #529 enables cross-worktree rebase/sync; #521 adds distributed modify. Requires Git 2.36+, with no automatic stashing or worktree creation/removal.
Key areas to review
cmd/worktree_utils.go:stackStateDir,beginStackMutation, andmutationStateDirchoose the shared catalog and lock the command before changes begin. Older interrupted operations must keep using the catalog they started with.cmd/worktree_utils.go:foreignWorktreePath/checkoutWorktreeBranchlocate branches without taking over another checkout. Follow their callers incmd/init.goandcmd/add.goto see when adoption changes only tracking information.cmd/utils.go:preflightSyncReconciliationandrequireLocalBranchescheck remotely added branches before creating branches or changing stack membership. Choosing a stack must not switch checkouts before these checks.cmd/rebase.go:requireRebaseOrigin,rebaseStackFromState, andloadRebaseStateensure recovery uses the correct stack and checkout.origin-onlymarks operations that need this version's recovery behavior.internal/modify/state.go,recovery.go, andcmd/submit.go:MatchesStack,unwindState, andhandlePendingModifymatch the actual stack, not its position in a list, and keep recovery records when restoring or submitting fails.Related issues
gh stack rebasesilently succeeds whengit rebase --ontofails to start (in branch checked out in another worktree) #35Part 3 of the 4-PR split of #520