GeezerVison is showing github.com — Address review feedback about dangling commondir · gitpython-developers/GitPython@83c3e64
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: git/repo/fun.py +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -87,9 +87,12 @@ def is_git_dir(d: PathLike) -> bool: |
87 | 87 | if common_dir == "": |
88 | 88 | return False |
89 | 89 | if common_dir is None: |
| 90 | + common_dir_file = Path(d) / "commondir" |
90 | 91 | 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") |
92 | 93 | except FileNotFoundError: |
| 94 | + if osp.lexists(common_dir_file): |
| 95 | + return False |
93 | 96 | common_dir = os.fspath(d) |
94 | 97 | except OSError: |
95 | 98 | return False |
|
Collapse file
Copy file name to clipboardExpand all lines: test/test_repo.py +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -181,6 +181,17 @@ def test_repo_discovery_rejects_invalid_metadata(self): |
181 | 181 | with self.subTest(metadata=".git", contents=contents): |
182 | 182 | self.assertRaises(InvalidGitRepositoryError, Repo, path) |
183 | 183 |
|
| 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 | + |
184 | 195 | def test_repo_discovery_uses_storage_environment(self): |
185 | 196 | with tempfile.TemporaryDirectory() as tdir: |
186 | 197 | git_dir = Path(tdir) / "git" |
|