|
11 | 11 |
|
12 | 12 | import pytest |
13 | 13 |
|
14 | | -from git import Actor, Commit, Git, Reference, Repo, SymbolicReference, _backend |
| 14 | +from git import Actor, Commit, Git, Reference, Repo, SymbolicReference, Tree, _backend |
15 | 15 | from git.exc import GitCommandError, InvalidGitRepositoryError, UnsafeOptionError |
16 | 16 | from git.index.fun import run_commit_hook |
17 | 17 | from git.repo.fun import find_submodule_git_dir, find_worktree_git_dir, is_git_dir |
@@ -264,6 +264,37 @@ def test_native_objects_trees_commits_and_index_reads(repo): |
264 | 264 | assert commit.replace(message="changed").message == "changed" |
265 | 265 |
|
266 | 266 |
|
| 267 | +@pytest.mark.parametrize("object_format", ["sha1", "sha256"]) |
| 268 | +@pytest.mark.parametrize("entry_types", ["blob-and-link", "gitlink"]) |
| 269 | +def test_native_tree_entry_modes_match_git(object_format, entry_types): |
| 270 | + with fixture_repo("tree-modes.sh", object_format, entry_types) as repo: |
| 271 | + oid = (Path(repo.working_dir).parent / "tree-id").read_text().strip() |
| 272 | + lines = repo.git.ls_tree(oid).splitlines() |
| 273 | + expected = [(line.split("\t")[1], int(line.split()[0], 8)) for line in lines] |
| 274 | + with patch.object(Git, "execute", side_effect=AssertionError("unexpected tree-listing CLI call")): |
| 275 | + tree = Tree(repo, bytes.fromhex(oid), path="") |
| 276 | + assert [(entry.path, entry.mode) for entry in tree] == expected |
| 277 | + |
| 278 | + |
| 279 | +@pytest.mark.parametrize("object_format", ["sha1", "sha256"]) |
| 280 | +@pytest.mark.parametrize("entry_types", ["missing-mode", "zero-mode"]) |
| 281 | +def test_ambiguous_tree_entry_mode_uses_git(object_format, entry_types): |
| 282 | + with fixture_repo("tree-modes.sh", object_format, entry_types) as repo: |
| 283 | + oid = (Path(repo.working_dir).parent / "tree-id").read_text().strip() |
| 284 | + tree = Tree(repo, bytes.fromhex(oid), path="") |
| 285 | + before = _backend.statistics() |
| 286 | + if entry_types == "missing-mode": |
| 287 | + with pytest.raises(GitCommandError, match="malformed mode"): |
| 288 | + repo.git.ls_tree(oid) |
| 289 | + with pytest.raises(GitCommandError, match="malformed mode"): |
| 290 | + list(tree) |
| 291 | + else: |
| 292 | + assert "160000 commit" in repo.git.ls_tree(oid) |
| 293 | + assert tree["module"].mode == 0o160000 |
| 294 | + key = ("ls_tree", "CLI: ambiguous zero tree entry mode (GIX-41)") |
| 295 | + assert _backend.statistics().get(key, 0) == before.get(key, 0) + 1 |
| 296 | + |
| 297 | + |
267 | 298 | def test_native_metadata_paths_match_git_in_each_worktree(repo): |
268 | 299 | tmp_path = Path(repo.working_dir).parent |
269 | 300 | linked_path = tmp_path / "linked" |
@@ -376,6 +407,17 @@ def snapshot(): |
376 | 407 | assert snapshot() == expected |
377 | 408 |
|
378 | 409 |
|
| 410 | +@pytest.mark.parametrize("object_format", ["sha1", "sha256"]) |
| 411 | +@pytest.mark.parametrize("syntax", ["implicit-extra", "inline-extra", "comment-in-key"]) |
| 412 | +def test_submodule_configuration_rejects_lines_git_rejects(object_format, syntax): |
| 413 | + with fixture_repo("submodule-rejected-lines.sh", object_format, syntax) as repo: |
| 414 | + with pytest.raises(GitCommandError, match="bad config line"): |
| 415 | + repo.git.config("--file", ".gitmodules", "--list") |
| 416 | + data = (Path(repo.working_dir) / ".gitmodules").read_bytes() |
| 417 | + with pytest.raises(gix.Error): |
| 418 | + gix.ModulesFile.from_bytes(data) |
| 419 | + |
| 420 | + |
379 | 421 | def test_native_revision_path_and_mode_match_cli(repo): |
380 | 422 | blob = repo.head.commit.tree["dir/file"] |
381 | 423 | revisions = ["HEAD:", "HEAD:dir/", "HEAD:dir/file", "HEAD:executable", "HEAD:link", ":executable", ":0:link"] |
@@ -718,6 +760,16 @@ def test_native_status_tracks_submodule_dirtiness(repo): |
718 | 760 | assert dirty == [repo.is_dirty(**option) for option in options] |
719 | 761 |
|
720 | 762 |
|
| 763 | +@pytest.mark.parametrize("target", ["untracked", "file"]) |
| 764 | +def test_embedded_status_uses_git_diff_policy(repo, target): |
| 765 | + expected = target == "file" |
| 766 | + assert bool(repo.git.diff("--raw")) == expected |
| 767 | + before = _backend.statistics() |
| 768 | + assert repo.is_dirty() == expected |
| 769 | + key = ("Repo.is_dirty", "CLI: embedded repository diff policy (GIX-40)") |
| 770 | + assert _backend.statistics().get(key, 0) == before.get(key, 0) + 1 |
| 771 | + |
| 772 | + |
721 | 773 | @pytest.mark.parametrize("error", [OSError(22, "Invalid filename"), PermissionError(13, "Permission denied")]) |
722 | 774 | def test_ignore_metadata_errors_retain_cli(error): |
723 | 775 | with fixture_repo("repo.sh", "ignore-verbatim") as repo: |
|
0 commit comments