Commit 4c69e85
committed
hooks: resolve enlistment root for worktrees outside enlistment tree
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>1 parent 3c18fe5 commit 4c69e85
4 files changed
Lines changed: 402 additions & 58 deletions
File tree
- GVFS
- GVFS.FunctionalTests/Tests/EnlistmentPerFixture
- GVFS.Hooks
- GVFS.NativeHooks.Common
- GVFS.UnitTests/Common
Lines changed: 77 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
194 | 271 | | |
195 | 272 | | |
196 | 273 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
50 | | - | |
51 | | - | |
52 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
53 | 66 | | |
54 | 67 | | |
55 | 68 | | |
| |||
0 commit comments