hooks: resolve enlistment root for worktrees outside enlistment tree#1979
Open
tyrielv wants to merge 1 commit into
Open
hooks: resolve enlistment root for worktrees outside enlistment tree#1979tyrielv wants to merge 1 commit into
tyrielv wants to merge 1 commit into
Conversation
13a70d3 to
915fe80
Compare
All native hooks (virtual-filesystem, read-object, post-index-changed) and managed hooks (GVFS.Hooks) resolved the primary enlistment root by walking up from CWD looking for a .gvfs/ directory. This meant worktrees placed outside the enlistment directory tree (e.g. in a temp directory or as a sibling) could not use git commands — the hooks would fail with 'must be run from inside a GVFS enlistment'. Fix by adding a worktree fallback path: when .gvfs walk-up fails, walk up looking for a .git file (indicating a linked worktree), then resolve the primary enlistment root through the gitdir chain — first from the gvfs-enlistment-root marker file, then by deriving from commondir. The resolved root is validated by checking that .gvfs/ exists there. Native hooks (common.windows.cpp): - Extract ReadFirstLine, Utf8ToWide, TryParseGitFile helpers - Refactor GetWorktreePipeSuffix to use shared helpers - Add TryResolveFromWorktree that returns both enlistment root and pipe suffix - GetGVFSPipeName tries .gvfs walk-up first, then worktree fallback Managed hooks (Program.cs): - After TryGetGVFSEnlistmentRoot fails, try TryGetWorktreeInfo -> GetEnlistmentRoot() before exiting - Validate .gvfs exists at the resolved root Tests: - Unit tests for GetEnlistmentRoot with marker file, SharedGitDir fallback, and marker-preferred scenarios - Functional test creating worktree in temp directory, verifying git status from root and subdirectory, file projection, commits Assisted-by: Claude Opus 4.6 Signed-off-by: Ty Larrabee <tyrielv@gmail.com>
915fe80 to
4c69e85
Compare
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.
Summary
All native hooks (virtual-filesystem, read-object, post-index-changed) and managed hooks (GVFS.Hooks) resolved the primary enlistment root by walking up from CWD looking for a
.gvfs/directory. Worktrees placed outside the enlistment directory tree (e.g. in a temp directory or as a sibling) could not use git commands — hooks failed with 'must be run from inside a GVFS enlistment'.Fix
Added a worktree fallback path: when
.gvfswalk-up fails, walk up looking for a.gitfile (indicating a linked worktree), then resolve the primary enlistment root through the gitdir chain — first from thegvfs-enlistment-rootmarker file, then by deriving fromcommondir. The resolved root is validated by checking that.gvfs/exists.Native hooks (
common.windows.cpp)ReadFirstLine,Utf8ToWide,TryParseGitFilehelpersGetWorktreePipeSuffixto use shared helpersTryResolveFromWorktreereturning both enlistment root and pipe suffixGetGVFSPipeNametries.gvfswalk-up first, then worktree fallbackManaged hooks (
Program.cs)TryGetGVFSEnlistmentRootfails, tryTryGetWorktreeInfo→GetEnlistmentRoot()before exiting.gvfsexists at the resolved rootTesting
GetEnlistmentRoot(marker file, SharedGitDir fallback, marker-preferred)