Skip to content

Commit 69c5c61

Browse files
codexByron
authored andcommitted
fix(repo): preserve literal Cygwin gitfile paths
The `test-cygwin` workflow's `test (fast)` job reported two `InvalidGitRepositoryError` failures in the new submodule regression. Cloning preserved the requested metadata directory, but reopening it expanded the relative path read from the submodule's `.git` file. Disable expansion when `find_submodule_git_dir()` converts gitfile paths with `cygpath()`. These paths come from repository metadata and must be used literally. This completes the Cygwin behavior for `GHSA-fx3j-rwgx-fr94`. Extend the existing regression to exercise Cygwin gitfile conversion on every platform. The same two cases now reproduce locally before the fix and pass afterward. Git's `read_gitfile_gently()` in `setup.c` at `d38352cd43ab9745686d697872408bc3249a153f` likewise resolves the literal gitfile path without environment expansion. Validation: - All 22 clone/submodule regression cases pass. - `test/test_fun.py` and `test/test_submodule.py`: 177 passed, 3 skipped, and 1 expected failure. The one sandbox-blocked temporary-index test passed on rerun with access to this worktree's Git metadata directory. - `ruff check` and `ruff format --check` pass for the changed files. - `mypy` passes for all 46 checked source files.
1 parent b532a50 commit 69c5c61

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

‎git/repo/fun.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def find_submodule_git_dir(d: PathLike) -> Optional[PathLike]:
151151
# Cygwin creates submodules prefixed with `/cygdrive/...`.
152152
# Cygwin git understands Cygwin paths much better than Windows ones.
153153
# Also the Cygwin tests are assuming Cygwin paths.
154-
path = cygpath(path)
154+
path = cygpath(path, expand_vars=False)
155155
if not osp.isabs(path):
156156
path = osp.normpath(osp.join(osp.dirname(d), path))
157157
return path if is_git_dir(path) else None

‎test/test_submodule.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ def test_submodule_update_preserves_literal_name(tmp_path, monkeypatch, caplog,
7070

7171
modules_dir = Path(clone.git_dir, "modules")
7272
assert {path.name for path in modules_dir.iterdir()} == {name}
73+
# Exercise relative gitfile conversion on every platform.
74+
with mock.patch.object(Git, "is_cygwin", return_value=True):
75+
resolved_git_dir = find_submodule_git_dir(Path(clone.working_tree_dir, "module", ".git"))
76+
assert resolved_git_dir is not None
77+
assert (modules_dir / name).samefile(resolved_git_dir)
7378
with clone.submodules[0].module() as module:
7479
assert (modules_dir / name).samefile(module.git_dir)
7580
assert module.head.commit == source.head.commit

0 commit comments

Comments
 (0)