fix(finish): use repo_root for agent_worktree_root in submodule repos#646
Merged
NagyVikt merged 3 commits intoJun 17, 2026
Conversation
added 3 commits
June 17, 2026 09:48
`git worktree list` inside a submodule that lives in a LINKED worktree
reports the gitdir (<parent>/.git/worktrees/<wt>/modules/<sub>) as the
worktree path, not the actual working tree. load_all_locks only read
lock files from those reported roots, so validate could not see claims
the same checkout had just recorded — agent commits in such submodules
were always blocked ("staged files must be safely claimed").
Always include the caller's resolved repo_root in the roots list.
Regression test: parent repo + submodule + linked worktree; claim then
validate from inside the worktree's submodule (fails without the fix,
11/11 suite pass with it).
Review follow-up: cmd_status iterates list_worktree_roots directly, so the gitdir-quirk fix in load_all_locks left `gx locks status` blind to the same submodule-under-linked-worktree claims. Hoist the guard into list_worktree_roots so every caller (claim conflict scan, validate, status) sees the caller's own lock file; load_all_locks drops its local copy of the guard.
In a git submodule, repo_common_root resolves to the parent's .git/modules/<sub> directory, not the submodule working tree. agent-branch-start.sh builds the worktree path with repo_root, so agent-branch-finish.sh must match. When the paths diverge the cleanup condition never fires, worktree removal is silently skipped, and git branch -d fails with 'used by worktree'.
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.
Automated by gx branch finish (PR flow).