Commit 340c895
fix: Validate submodule checkout and metadata paths before mutation
A bit of a sloppy review, rubber-stamping the tests based on the assumption
that they are validating it's conforming to Git, probably also while increasing
coverage.
<!-- agent -->
Submodule.add() could clone through a checkout symlink after module_exists()
swallowed the validation error. Metadata paths had a similar gap: locally
planted symlinks under .git/modules could redirect cloning, reconnecting,
renaming, updating, or removing a submodule. Some failures were detected only
after changing configuration or moving or removing checkout directories.
Reuse the checkout component check for metadata paths and validate checkout
paths in the shared clone helper, including legacy embedded repositories.
Check .gitfiles, submodule configuration files, and the actual repository
path named by a gitfile, which can differ from .git/modules/<name>. Reject
symlinked .gitmodules files as well. Preflight move and rename sources and
destinations before mutation, including the implicit metadata rename when
a default-named submodule moves. Keep module_exists()'s boolean contract
and the existing supported replacement of a leaf symlink during a move.
Add 56 regression cases covering checkout and metadata links, dangling
links, redirected gitfiles, legacy clone layouts, and rejected operations
preserving external targets, configuration, the index, and an empty move
destination. The initial 36 cases reproduced failures before the fix.
These checks reject existing symlinks; they do not prevent concurrent
filesystem replacement between validation and use.
Assisted-by: GPT 6.0
Co-authored-by: GPT 6.0 <codex@openai.com>1 parent a088524 commit 340c895
2 files changed
Lines changed: 200 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
258 | | - | |
| 258 | + | |
259 | 259 | | |
260 | 260 | | |
261 | 261 | | |
| |||
322 | 322 | | |
323 | 323 | | |
324 | 324 | | |
325 | | - | |
| 325 | + | |
326 | 326 | | |
327 | 327 | | |
328 | 328 | | |
| |||
361 | 361 | | |
362 | 362 | | |
363 | 363 | | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
364 | 368 | | |
365 | | - | |
366 | 369 | | |
367 | 370 | | |
368 | 371 | | |
| |||
377 | 380 | | |
378 | 381 | | |
379 | 382 | | |
380 | | - | |
381 | 383 | | |
382 | 384 | | |
383 | 385 | | |
| |||
423 | 425 | | |
424 | 426 | | |
425 | 427 | | |
426 | | - | |
427 | | - | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
428 | 436 | | |
429 | | - | |
| 437 | + | |
| 438 | + | |
430 | 439 | | |
431 | | - | |
| 440 | + | |
432 | 441 | | |
433 | 442 | | |
434 | 443 | | |
435 | | - | |
| 444 | + | |
436 | 445 | | |
437 | 446 | | |
438 | 447 | | |
| |||
458 | 467 | | |
459 | 468 | | |
460 | 469 | | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
461 | 473 | | |
| 474 | + | |
462 | 475 | | |
463 | 476 | | |
464 | 477 | | |
465 | 478 | | |
466 | 479 | | |
467 | 480 | | |
468 | | - | |
| 481 | + | |
469 | 482 | | |
470 | 483 | | |
471 | 484 | | |
| |||
576 | 589 | | |
577 | 590 | | |
578 | 591 | | |
| 592 | + | |
| 593 | + | |
579 | 594 | | |
580 | 595 | | |
581 | 596 | | |
| |||
1067 | 1082 | | |
1068 | 1083 | | |
1069 | 1084 | | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
1070 | 1089 | | |
1071 | 1090 | | |
1072 | 1091 | | |
| |||
1099 | 1118 | | |
1100 | 1119 | | |
1101 | 1120 | | |
1102 | | - | |
1103 | 1121 | | |
1104 | 1122 | | |
1105 | 1123 | | |
| |||
1201 | 1219 | | |
1202 | 1220 | | |
1203 | 1221 | | |
| 1222 | + | |
| 1223 | + | |
1204 | 1224 | | |
1205 | 1225 | | |
1206 | 1226 | | |
| |||
1219 | 1239 | | |
1220 | 1240 | | |
1221 | 1241 | | |
1222 | | - | |
| 1242 | + | |
1223 | 1243 | | |
1224 | 1244 | | |
1225 | 1245 | | |
| |||
1460 | 1480 | | |
1461 | 1481 | | |
1462 | 1482 | | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
1463 | 1486 | | |
1464 | 1487 | | |
1465 | 1488 | | |
| |||
1476 | 1499 | | |
1477 | 1500 | | |
1478 | 1501 | | |
1479 | | - | |
1480 | 1502 | | |
1481 | | - | |
1482 | 1503 | | |
1483 | 1504 | | |
1484 | 1505 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 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 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
179 | 344 | | |
180 | 345 | | |
181 | 346 | | |
| |||
0 commit comments