-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_reset.py
More file actions
37 lines (27 loc) · 1.36 KB
/
test_reset.py
File metadata and controls
37 lines (27 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import subprocess
def test_reset(repo_init_with_commit, commit_env_config, git2cpp_path, tmp_path):
assert (tmp_path / "initial.txt").exists()
p = tmp_path / "mook_file.txt"
p.write_text("")
cmd_add = [git2cpp_path, "add", "mook_file.txt"]
p_add = subprocess.run(cmd_add, cwd=tmp_path, text=True)
assert p_add.returncode == 0
cmd_commit = [git2cpp_path, "commit", "-m", "test commit"]
p_commit = subprocess.run(cmd_commit, cwd=tmp_path, text=True)
assert p_commit.returncode == 0
cmd_log = [git2cpp_path, "log"]
p_log = subprocess.run(cmd_log, capture_output=True, cwd=tmp_path, text=True)
assert p_log.returncode == 0
assert "test commit" in p_log.stdout
cmd_reset = [git2cpp_path, "reset", "--hard", "HEAD~1"]
p_reset = subprocess.run(cmd_reset, capture_output=True, cwd=tmp_path, text=True)
assert p_reset.returncode == 0
cmd_log_2 = [git2cpp_path, "log"]
p_log2 = subprocess.run(cmd_log_2, capture_output=True, cwd=tmp_path, text=True)
assert p_log2.returncode == 0
assert "test commit" not in p_log2.stdout
def test_reset_nogit(git2cpp_path, tmp_path):
cmd_reset = [git2cpp_path, "reset", "--hard", "HEAD~1"]
p_reset = subprocess.run(cmd_reset, capture_output=True, cwd=tmp_path, text=True)
assert p_reset.returncode != 0
assert "error: could not find repository at" in p_reset.stderr