FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Address review feedback about dangling commondir · gitpython-developers/GitPython@83c3e64 · GitHub

Commit 83c3e64

Browse files
authored andcommitted
Address review feedback about dangling commondir
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. Git baseline: 15c6308cf7ad276b306aa5b3ababfbdebfb1a917, setup.c get_common_dir_noenv() and dir.c file_exists(). Validation: 8 focused tests and 12 subtests; Ruff check and format; mypy; compileall; git diff --check.
1 parent b8c000e commit 83c3e64

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎git/repo/fun.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,12 @@ def is_git_dir(d: PathLike) -> bool:
8787
if common_dir == "":
8888
return False
8989
if common_dir is None:
90+
common_dir_file = Path(d) / "commondir"
9091
try:
91-
common_dir = os.fsdecode((Path(d) / "commondir").read_bytes()).rstrip("\r\n")
92+
common_dir = os.fsdecode(common_dir_file.read_bytes()).rstrip("\r\n")
9293
except FileNotFoundError:
94+
if osp.lexists(common_dir_file):
95+
return False
9396
common_dir = os.fspath(d)
9497
except OSError:
9598
return False

‎test/test_repo.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,17 @@ def test_repo_discovery_rejects_invalid_metadata(self):
181181
with self.subTest(metadata=".git", contents=contents):
182182
self.assertRaises(InvalidGitRepositoryError, Repo, path)
183183

184+
@requires_symlinks
185+
def test_repo_discovery_rejects_dangling_commondir(self):
186+
with tempfile.TemporaryDirectory() as tdir:
187+
path = Path(tdir)
188+
(path / "objects").mkdir()
189+
(path / "refs").mkdir()
190+
(path / "HEAD").write_text("ref: refs/heads/main\n")
191+
(path / "commondir").symlink_to("missing")
192+
193+
self.assertRaises(InvalidGitRepositoryError, Repo, path)
194+
184195
def test_repo_discovery_uses_storage_environment(self):
185196
with tempfile.TemporaryDirectory() as tdir:
186197
git_dir = Path(tdir) / "git"

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL