|
9 | 9 |
|
10 | 10 | import pytest |
11 | 11 |
|
12 | | -from git import Actor, Commit, Git, Reference, Repo, _backend |
| 12 | +from git import Actor, Commit, Git, Reference, Repo, SymbolicReference, _backend |
13 | 13 | from git.exc import GitCommandError, InvalidGitRepositoryError |
14 | 14 | from gitdb import IStream |
15 | 15 |
|
@@ -253,6 +253,26 @@ def test_native_tree_and_commit_bytes_match_cli(repo): |
253 | 253 | assert commit.replace(message="a changed message").hexsha == native.hexsha |
254 | 254 |
|
255 | 255 |
|
| 256 | +def test_native_reference_reads_include_missing_and_dangling_targets(repo): |
| 257 | + repo.index.commit("initial", skip_hooks=True) |
| 258 | + repo.git.pack_refs("--all", "--prune") |
| 259 | + repo.git.symbolic_ref("refs/heads/alias", "refs/heads/absent") |
| 260 | + paths = ["HEAD", "refs/heads/main", "refs/heads/alias"] |
| 261 | + with patch.object(_backend, "gix", None): |
| 262 | + expected = [SymbolicReference._get_ref_info(repo, path) for path in paths] |
| 263 | + SymbolicReference._check_ref_name_valid("refs/heads/absent") |
| 264 | + with pytest.raises(ValueError) as missing: |
| 265 | + SymbolicReference._get_ref_info(repo, "refs/heads/absent") |
| 266 | + count = _backend.statistics().get(("Git.execute", "CLI process"), 0) |
| 267 | + with patch.object(Git, "execute", side_effect=AssertionError("unexpected reference CLI call")): |
| 268 | + assert [SymbolicReference._get_ref_info(repo, path) for path in paths] == expected |
| 269 | + with pytest.raises(ValueError) as native_missing: |
| 270 | + SymbolicReference._get_ref_info(repo, "refs/heads/absent") |
| 271 | + assert str(native_missing.value) == str(missing.value) |
| 272 | + assert not Reference(repo, "refs/heads/alias").is_valid() |
| 273 | + assert _backend.statistics().get(("Git.execute", "CLI process"), 0) == count |
| 274 | + |
| 275 | + |
256 | 276 | def test_unknown_command_and_storage_environment_use_cli(repo): |
257 | 277 | before = _backend.statistics() |
258 | 278 | assert repo.git._call_process_safe("status", "--porcelain") == "" |
|
0 commit comments