Skip to content

Commit 8c9fec6

Browse files
codexByron
authored andcommitted
test: preserve hidden gitfiles when preparing submodule aliases
The Windows Python 3.8 partial CI log showed two failures in `test_submodule_allows_existing_metadata_symlinks`: preparing update and move aliases raised `PermissionError` before invoking GitPython. Git marks the submodule's `.git` file hidden; Python's `write_text()` attempts to recreate it, which Windows rejects for an existing hidden file. Open that fixture file with `r+`, write the replacement target, and truncate it. This preserves the hidden attribute while replacing the full contents. The separate fixture that creates a previously absent gitfile is unchanged. Validation: all six native/windows37 update, move, and remove alias modes pass locally. Ruff lint, formatting, and `git diff --check` pass. The Windows-specific file-attribute behavior will be verified by CI.
1 parent 8d73bae commit 8c9fec6

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎test/test_submodule.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,11 @@ def test_submodule_allows_existing_metadata_symlinks(
741741
target = tmp_path / "outside"
742742
if kind == "alias":
743743
target = modules / "nested"
744-
(root / "module/.git").write_text("gitdir: ../.git/modules/alias/module")
744+
# Git hides .git on Windows; opening that existing file with O_CREAT
745+
# fails even when it is writable. Preserve its attributes with r+.
746+
with (root / "module/.git").open("r+", encoding="utf-8") as gitfile:
747+
gitfile.write("gitdir: ../.git/modules/alias/module")
748+
gitfile.truncate()
745749
else:
746750
link.rename(target)
747751
link.symlink_to(target, target_is_directory=target.is_dir())

0 commit comments

Comments
 (0)