|
| 1 | +import os |
| 2 | +import subprocess |
| 3 | +import shlex |
| 4 | +import git |
| 5 | +from helper import invoke_git_extras_command |
| 6 | + |
| 7 | +class TestGitAbort: |
| 8 | + def test_init(self, git_repo): |
| 9 | + repo, tmp_dir, tmp_a, tmp_b = git_repo |
| 10 | + repo.git.branch("A") |
| 11 | + repo.git.branch("B") |
| 12 | + repo.git.checkout("A") |
| 13 | + with open(tmp_a[1], "w", encoding="utf-8") as file_a_on_A: |
| 14 | + file_a_on_A.write("a") |
| 15 | + file_a_on_A.close() |
| 16 | + repo.git.add(".") |
| 17 | + repo.git.commit("-m", "A") |
| 18 | + repo.git.checkout("B") |
| 19 | + with open(tmp_a[1], "w", encoding="utf-8") as file_a_on_B: |
| 20 | + file_a_on_B.write("b") |
| 21 | + file_a_on_B.close() |
| 22 | + repo.git.add(".") |
| 23 | + repo.git.commit("-m", "B") |
| 24 | + repo.git.status() |
| 25 | + |
| 26 | + def test_cherry_pick(self, git_repo): |
| 27 | + repo = git_repo[0] |
| 28 | + try: |
| 29 | + repo.git.cherry_pick("A") |
| 30 | + except git.GitCommandError: |
| 31 | + pass |
| 32 | + result = repo.git.status() |
| 33 | + assert "Unmerged path" in result |
| 34 | + invoke_git_extras_command("git-abort") |
| 35 | + result = repo.git.status() |
| 36 | + assert "nothing to commit, working tree clean" in result |
| 37 | + |
| 38 | + def test_merge(self, git_repo): |
| 39 | + repo = git_repo[0] |
| 40 | + try: |
| 41 | + repo.git.merge("A") |
| 42 | + except git.GitCommandError: |
| 43 | + pass |
| 44 | + result = repo.git.status() |
| 45 | + assert "Unmerged path" in result |
| 46 | + invoke_git_extras_command("git-abort") |
| 47 | + result = repo.git.status() |
| 48 | + assert "nothing to commit, working tree clean" in result |
| 49 | + |
| 50 | + def test_rebase(self, git_repo): |
| 51 | + repo = git_repo[0] |
| 52 | + try: |
| 53 | + repo.git.rebase("A") |
| 54 | + except git.GitCommandError: |
| 55 | + pass |
| 56 | + result = repo.git.status() |
| 57 | + assert "Unmerged path" in result |
| 58 | + invoke_git_extras_command("git-abort") |
| 59 | + result = repo.git.status() |
| 60 | + assert "nothing to commit, working tree clean" in result |
| 61 | + |
| 62 | + def test_revert(self, git_repo): |
| 63 | + repo = git_repo[0] |
| 64 | + try: |
| 65 | + repo.git.revert("A") |
| 66 | + except git.GitCommandError: |
| 67 | + pass |
| 68 | + result = repo.git.status() |
| 69 | + assert "Unmerged path" in result |
| 70 | + invoke_git_extras_command("git-abort") |
| 71 | + result = repo.git.status() |
| 72 | + assert "nothing to commit, working tree clean" in result |
0 commit comments