|
4 | 4 |
|
5 | 5 | import pytest |
6 | 6 |
|
7 | | -from git import Git, Remote, Repo |
| 7 | +from git import Actor, Git, GitCommandError, Head, Remote, RemoteReference, Repo, TagReference |
8 | 8 | from git.exc import UnsafeOptionError |
9 | 9 |
|
10 | 10 |
|
@@ -40,3 +40,43 @@ def test_pull_preserves_operand_and_explicit_option_values(tmp_path): |
40 | 40 | remote.pull("refs/heads/topic", upload_pack="helper with spaces", allow_unsafe_options=True) |
41 | 41 | assert run.call_args[0] == ("pull", "--", remote, ["refs/heads/topic"]) |
42 | 42 | assert run.call_args[1]["upload_pack"] == "helper with spaces" |
| 43 | + |
| 44 | + |
| 45 | +def test_delete_head_cannot_override_force(tmp_path): |
| 46 | + repo = Repo.init(tmp_path) |
| 47 | + actor = Actor("Test", "test@example.com") |
| 48 | + initial = repo.index.commit("initial", author=actor, committer=actor) |
| 49 | + branch = repo.create_head("unmerged", initial) |
| 50 | + branch.commit = repo.index.commit("unmerged", head=False, author=actor, committer=actor) |
| 51 | + with pytest.raises(GitCommandError): |
| 52 | + repo.delete_head("--force", branch, force=False) |
| 53 | + assert branch.is_valid() |
| 54 | + repo.delete_head(branch, force=True) |
| 55 | + assert not branch.is_valid() |
| 56 | + |
| 57 | + |
| 58 | +def test_rename_head_cannot_select_current_branch(tmp_path): |
| 59 | + repo = Repo.init(tmp_path) |
| 60 | + actor = Actor("Test", "test@example.com") |
| 61 | + repo.index.commit("initial", author=actor, committer=actor) |
| 62 | + original = repo.active_branch.name |
| 63 | + with pytest.raises(GitCommandError): |
| 64 | + Head(repo, "refs/heads/--force").rename("renamed") |
| 65 | + assert repo.active_branch.name == original |
| 66 | + |
| 67 | + |
| 68 | +def test_tag_operands_follow_option_terminator(tmp_path): |
| 69 | + repo = Repo.init(tmp_path) |
| 70 | + with mock.patch.object(Git, "_call_process") as run: |
| 71 | + TagReference.create(repo, "topic", "HEAD") |
| 72 | + assert run.call_args[0] == ("tag", "--", "topic", "HEAD") |
| 73 | + TagReference.delete(repo, "--list") |
| 74 | + assert run.call_args[0] == ("tag", "-d", "--", "--list") |
| 75 | + |
| 76 | + |
| 77 | +def test_remote_ref_delete_preserves_operand(tmp_path): |
| 78 | + repo = Repo.init(tmp_path) |
| 79 | + ref = RemoteReference(repo, "refs/remotes/--force") |
| 80 | + with mock.patch.object(Git, "_call_process") as run: |
| 81 | + RemoteReference.delete(repo, ref) |
| 82 | + assert run.call_args[0] == ("branch", "-d", "-r", "--", ref) |
0 commit comments