|
| 1 | +import os |
| 2 | +import subprocess |
| 3 | +import shlex |
| 4 | + |
| 5 | +class TestGitAbort: |
| 6 | + def test_init(self, git_repo): |
| 7 | + _, tmp_dir, tmp_a, tmp_b = git_repo |
| 8 | + subprocess.run(shlex.split("git branch A")) |
| 9 | + subprocess.run(shlex.split("git branch B")) |
| 10 | + subprocess.run(shlex.split("git checkout A")) |
| 11 | + file_a = open(tmp_a[1], "w", encoding="utf-8") |
| 12 | + file_a.write('a') |
| 13 | + file_a.close() |
| 14 | + subprocess.run(shlex.split("git add .")) |
| 15 | + subprocess.run(shlex.split("git commit -m \"A\"")) |
| 16 | + subprocess.run(shlex.split("git checkout B")) |
| 17 | + file_b = open(tmp_a[1], "w", encoding="utf-8") |
| 18 | + file_b.write('b') |
| 19 | + file_b.close() |
| 20 | + subprocess.run(shlex.split("git add .")) |
| 21 | + subprocess.run(shlex.split("git commit -m \"B\"")) |
| 22 | + subprocess.run(shlex.split("git status")) |
| 23 | + |
| 24 | + def test_cherry_pick(self, git_repo): |
| 25 | + git_extras_cwd = git_repo[0] |
| 26 | + result = subprocess.run(shlex.split("git cherry-pick A"), capture_output=True) |
| 27 | + result = subprocess.run(shlex.split("git status"), capture_output=True) |
| 28 | + assert "Unmerged path" in result.stdout.decode() |
| 29 | + subprocess.run(shlex.split(os.path.join(git_extras_cwd, 'bin', 'git-abort'))) |
| 30 | + result = subprocess.run(shlex.split("git status"), capture_output=True) |
| 31 | + assert "nothing to commit, working tree clean" in result.stdout.decode() |
| 32 | + |
| 33 | + def test_merge(self, git_repo): |
| 34 | + git_extras_cwd = git_repo[0] |
| 35 | + git_extras_cwd = git_repo[0] |
| 36 | + result = subprocess.run(shlex.split("git merge --allow-unrelated-histories A"), capture_output=True) |
| 37 | + result = subprocess.run(shlex.split("git status"), capture_output=True) |
| 38 | + assert "Unmerged path" in result.stdout.decode() |
| 39 | + subprocess.run(shlex.split(os.path.join(git_extras_cwd, 'bin', 'git-abort'))) |
| 40 | + result = subprocess.run(shlex.split("git status"), capture_output=True) |
| 41 | + assert "nothing to commit, working tree clean" in result.stdout.decode() |
| 42 | + |
| 43 | + def test_rebase(self, git_repo): |
| 44 | + git_extras_cwd = git_repo[0] |
| 45 | + git_extras_cwd = git_repo[0] |
| 46 | + result = subprocess.run(shlex.split("git rebase A"), capture_output=True) |
| 47 | + result = subprocess.run(shlex.split("git status"), capture_output=True) |
| 48 | + assert "Unmerged path" in result.stdout.decode() |
| 49 | + subprocess.run(shlex.split(os.path.join(git_extras_cwd, 'bin', 'git-abort'))) |
| 50 | + result = subprocess.run(shlex.split("git status"), capture_output=True) |
| 51 | + assert "nothing to commit, working tree clean" in result.stdout.decode() |
| 52 | + |
| 53 | + def test_revert(self, git_repo): |
| 54 | + git_extras_cwd = git_repo[0] |
| 55 | + result = subprocess.run(shlex.split("git revert A"), capture_output=True) |
| 56 | + result = subprocess.run(shlex.split("git status"), capture_output=True) |
| 57 | + assert "Unmerged path" in result.stdout.decode() |
| 58 | + subprocess.run(shlex.split(os.path.join(git_extras_cwd, 'bin', 'git-abort'))) |
| 59 | + result = subprocess.run(shlex.split("git status"), capture_output=True) |
| 60 | + assert "nothing to commit, working tree clean" in result.stdout.decode() |
0 commit comments