fix: Validate submodule checkout and metadata paths before mutation · gitpython-developers/GitPython@340c895 · GitHub
Skip to content

Commit 340c895

Browse files
Byroncodex
andcommitted
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

File tree

git/objects/submodule/base.py

Lines changed: 35 additions & 14 deletions

test/test_submodule.py

Lines changed: 165 additions & 0 deletions

0 commit comments

Comments
 (0)