Commit c7cf4d1
fix: prefer
<!-- agent -->
GitPython considered worktree administration and bare-repository signatures
before a worktree's real .git entry. Align discovery with Git so .git files
and directories win, malformed .git files stop discovery, and candidate git
directories validate HEAD plus commondir-backed object and ref storage. This
addresses GHSA-239g-whfq-7xj9.
Regression coverage compares ambiguous layouts with git rev-parse and rejects
invalid HEAD/.git metadata.
Git baseline: 15c6308cf7ad276b306aa5b3ababfbdebfb1a917; setup.c
setup_git_directory_gently_1(), is_git_directory(), and validate_headref().
Repository validation can use GIT_COMMON_DIR for refs and objects. Preserve the
same value on Repo so later config, ref, and object access uses the directory
that made discovery succeed.
Capture GIT_COMMON_DIR before the first repository config read so bare-state
detection uses the same metadata location as discovery. Resolve relative
environment values immediately so later working-directory changes cannot
retarget the Repo.
Review feedback: relative GIT_COMMON_DIR left Git subprocesses resolving GIT_DIR
and GIT_COMMON_DIR from a different working directory; malformed commondir data,
empty GIT_OBJECT_DIRECTORY, and the linked-worktree signature were also handled
inconsistently.
Pin the repository environment to resolved paths, reject invalid
metadata without consulting the process working directory, and
restore HEAD-based linked-worktree detection. Keep the loose HEAD
and dangling .git behavior because both match Git setup.c at baseline
15c6308cf7ad276b306aa5b3ababfbdebfb1a917.
Review feedback identified that chained or self-referential .git pointers
recurse, filesystem-encoded metadata can fail text decoding, and a relative
GIT_DIR is not retained for later Git commands.
Parse one regular, size-bounded Gitfile exactly once, decode Gitfile and
commondir paths with the filesystem codec, and retain the resolved GIT_DIR
for subprocesses. This rejects cycles like Git instead of recursing and keeps
commands stable after working-directory changes.
Review feedback noted that a dangling commondir symlink was treated as absent,
allowing local objects and refs to validate the repository.
Distinguish a truly missing commondir from a dangling symlink. This follows
Git's get_common_dir_noenv(), whose file_exists check uses lstat before
attempting to read the entry.
Python 3.9 on Windows raised UnicodeDecodeError while the repository-discovery
regression test parsed invalid commondir bytes, causing the Python package test
(windows, 3.9) check to fail.
Treat UnicodeError like an unreadable metadata file in both commondir and
gitfile parsing. Invalid bytes now make discovery reject the candidate
repository, matching Git's behavior.
Review feedback noted that GIT_OBJECT_DIRECTORY made discovery succeed without
becoming the Repo ODB root, while a relative value could later be resolved from
the Git wrapper's different working directory.
Resolve the environment value against the construction directory, use it as the
ODB root, and preserve the absolute value for later Git commands. The regression
moves the only object store outside the git directory and verifies access
through both GitDB and git cat-file after the original environment and current
directory are restored.
Review feedback identified four setup mismatches: non-missing .git stat failures
could fall through to another repository, explicit GIT_DIR could be redirected
through a nested .git entry, Gitfile reads were not bounded to the stat-reported
size, and alternates ignored GIT_OBJECT_DIRECTORY.
Match Git setup.c by bypassing discovery for an environment-selected GIT_DIR,
stopping discovery when Gitfile stat fails for reasons other than a missing
path, and reading exactly the previously observed Gitfile size. Resolve
alternates below the active ODB root so custom object stores remain internally
consistent.
The commit review noted that treating every present GIT_DIR as explicit broke
two documented cases: an empty GIT_DIR must fall back to current-directory
discovery, while an empty Repo path must still use a nonempty GIT_DIR.
Assisted-by: GPT 5.6
Co-authored-by: GPT 5.6 <codex@openai.com>.git during repository discovery1 parent d160fb4 commit c7cf4d1
4 files changed
Lines changed: 333 additions & 89 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
49 | 48 | | |
50 | 49 | | |
51 | 50 | | |
| |||
234 | 233 | | |
235 | 234 | | |
236 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
237 | 240 | | |
238 | 241 | | |
239 | 242 | | |
| |||
268 | 271 | | |
269 | 272 | | |
270 | 273 | | |
271 | | - | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
272 | 279 | | |
273 | 280 | | |
274 | 281 | | |
| |||
290 | 297 | | |
291 | 298 | | |
292 | 299 | | |
293 | | - | |
294 | | - | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
295 | 303 | | |
296 | 304 | | |
297 | 305 | | |
298 | 306 | | |
299 | 307 | | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
314 | 324 | | |
315 | | - | |
316 | | - | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
317 | 335 | | |
318 | | - | |
| 336 | + | |
| 337 | + | |
319 | 338 | | |
320 | | - | |
| 339 | + | |
| 340 | + | |
321 | 341 | | |
322 | | - | |
323 | | - | |
324 | 342 | | |
325 | 343 | | |
326 | 344 | | |
| |||
340 | 358 | | |
341 | 359 | | |
342 | 360 | | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
| 361 | + | |
359 | 362 | | |
360 | 363 | | |
361 | 364 | | |
| |||
366 | 369 | | |
367 | 370 | | |
368 | 371 | | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
369 | 382 | | |
370 | 383 | | |
371 | 384 | | |
372 | 385 | | |
373 | 386 | | |
374 | 387 | | |
375 | 388 | | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | 389 | | |
383 | 390 | | |
384 | 391 | | |
| |||
387 | 394 | | |
388 | 395 | | |
389 | 396 | | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
390 | 403 | | |
391 | 404 | | |
392 | | - | |
| 405 | + | |
393 | 406 | | |
394 | 407 | | |
395 | 408 | | |
| |||
990 | 1003 | | |
991 | 1004 | | |
992 | 1005 | | |
993 | | - | |
| 1006 | + | |
994 | 1007 | | |
995 | 1008 | | |
996 | 1009 | | |
| |||
1011 | 1024 | | |
1012 | 1025 | | |
1013 | 1026 | | |
1014 | | - | |
| 1027 | + | |
1015 | 1028 | | |
1016 | 1029 | | |
1017 | 1030 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
63 | 68 | | |
64 | 69 | | |
65 | 70 | | |
66 | 71 | | |
67 | 72 | | |
68 | 73 | | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
79 | 118 | | |
80 | 119 | | |
81 | 120 | | |
| |||
84 | 123 | | |
85 | 124 | | |
86 | 125 | | |
87 | | - | |
| 126 | + | |
88 | 127 | | |
89 | | - | |
| 128 | + | |
90 | 129 | | |
91 | 130 | | |
92 | 131 | | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
100 | 140 | | |
101 | 141 | | |
102 | 142 | | |
103 | 143 | | |
104 | 144 | | |
105 | 145 | | |
106 | 146 | | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
127 | 159 | | |
128 | 160 | | |
129 | 161 | | |
| |||
0 commit comments