-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_merge.py
More file actions
232 lines (187 loc) · 8.79 KB
/
test_merge.py
File metadata and controls
232 lines (187 loc) · 8.79 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
import subprocess
import pytest
# TODO: Have a different "person" for the commit and for the merge
# TODO: Test "unborn" case, but how ?
def test_merge_fast_forward(xtl_clone, git_config, git2cpp_path, tmp_path, monkeypatch):
assert (tmp_path / "xtl").exists()
xtl_path = tmp_path / "xtl"
checkout_cmd = [git2cpp_path, "checkout", "-b", "foregone"]
p_checkout = subprocess.run(
checkout_cmd, capture_output=True, cwd=xtl_path, text=True
)
assert p_checkout.returncode == 0
file_path = xtl_path / "mook_file.txt"
file_path.write_text("blablabla")
add_cmd = [git2cpp_path, "add", "mook_file.txt"]
p_add = subprocess.run(add_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_add.returncode == 0
commit_cmd = [git2cpp_path, "commit", "-m", "test commit"]
p_commit = subprocess.run(commit_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_commit.returncode == 0
checkout_cmd_2 = [git2cpp_path, "checkout", "master"]
p_checkout_2 = subprocess.run(
checkout_cmd_2, capture_output=True, cwd=xtl_path, text=True
)
assert p_checkout_2.returncode == 0
merge_cmd = [git2cpp_path, "merge", "foregone"]
p_merge = subprocess.run(merge_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_merge.returncode == 0
assert "Fast-forward" in p_merge.stdout
log_cmd = [git2cpp_path, "log", "--format=full", "--max-count", "1"]
p_log = subprocess.run(log_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_log.returncode == 0
assert "Author: Jane Doe" in p_log.stdout
# assert "Commit: John Doe" in p_log.stdout
assert (xtl_path / "mook_file.txt").exists()
merge_cmd_2 = [git2cpp_path, "merge", "foregone"]
p_merge_2 = subprocess.run(
merge_cmd_2, capture_output=True, cwd=xtl_path, text=True
)
assert p_merge_2.returncode == 0
assert p_merge_2.stdout == "Already up-to-date\n"
def test_merge_commit(xtl_clone, git_config, git2cpp_path, tmp_path, monkeypatch):
assert (tmp_path / "xtl").exists()
xtl_path = tmp_path / "xtl"
checkout_cmd = [git2cpp_path, "checkout", "-b", "foregone"]
p_checkout = subprocess.run(
checkout_cmd, capture_output=True, cwd=xtl_path, text=True
)
assert p_checkout.returncode == 0
file_path = xtl_path / "mook_file.txt"
file_path.write_text("blablabla")
add_cmd = [git2cpp_path, "add", "mook_file.txt"]
p_add = subprocess.run(add_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_add.returncode == 0
commit_cmd = [git2cpp_path, "commit", "-m", "test commit foregone"]
p_commit = subprocess.run(commit_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_commit.returncode == 0
checkout_cmd_2 = [git2cpp_path, "checkout", "master"]
p_checkout_2 = subprocess.run(
checkout_cmd_2, capture_output=True, cwd=xtl_path, text=True
)
assert p_checkout_2.returncode == 0
file_path_2 = xtl_path / "mook_file_2.txt"
file_path_2.write_text("BLABLABLA")
add_cmd_2 = [git2cpp_path, "add", "mook_file_2.txt"]
p_add_2 = subprocess.run(add_cmd_2, capture_output=True, cwd=xtl_path, text=True)
assert p_add_2.returncode == 0
commit_cmd_2 = [git2cpp_path, "commit", "-m", "test commit master"]
p_commit_2 = subprocess.run(
commit_cmd_2, capture_output=True, cwd=xtl_path, text=True
)
assert p_commit_2.returncode == 0
merge_cmd = [git2cpp_path, "merge", "foregone"]
p_merge = subprocess.run(merge_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_merge.returncode == 0
log_cmd = [git2cpp_path, "log", "--format=full", "--max-count", "2"]
p_log = subprocess.run(log_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_log.returncode == 0
assert "Author: Jane Doe" in p_log.stdout
# assert "Commit: John Doe" in p_log.stdout
assert "Johan" not in p_log.stdout
assert (xtl_path / "mook_file.txt").exists()
assert (xtl_path / "mook_file_2.txt").exists()
merge_cmd_2 = [git2cpp_path, "merge", "foregone"]
p_merge_2 = subprocess.run(
merge_cmd_2, capture_output=True, cwd=xtl_path, text=True
)
assert p_merge_2.returncode == 0
assert p_merge_2.stdout == "Already up-to-date\n"
@pytest.mark.parametrize("flag", ["--abort", "--quit", "--continue"])
def test_merge_conflict(
xtl_clone, git_config, git2cpp_path, tmp_path, monkeypatch, flag
):
assert (tmp_path / "xtl").exists()
xtl_path = tmp_path / "xtl"
checkout_cmd = [git2cpp_path, "checkout", "-b", "foregone"]
p_checkout = subprocess.run(
checkout_cmd, capture_output=True, cwd=xtl_path, text=True
)
assert p_checkout.returncode == 0
file_path = xtl_path / "mook_file.txt"
file_path.write_text("blablabla")
file_path_2 = xtl_path / "mook_file_2.txt"
file_path_2.write_text("Second file")
add_cmd = [git2cpp_path, "add", "--all"]
p_add = subprocess.run(add_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_add.returncode == 0
commit_cmd = [git2cpp_path, "commit", "-m", "test commit foregone"]
p_commit = subprocess.run(commit_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_commit.returncode == 0
checkout_cmd_2 = [git2cpp_path, "checkout", "master"]
p_checkout_2 = subprocess.run(
checkout_cmd_2, capture_output=True, cwd=xtl_path, text=True
)
assert p_checkout_2.returncode == 0
file_path.write_text("BLABLABLA")
add_cmd_2 = [git2cpp_path, "add", "mook_file.txt"]
p_add_2 = subprocess.run(add_cmd_2, capture_output=True, cwd=xtl_path, text=True)
assert p_add_2.returncode == 0
commit_cmd_2 = [git2cpp_path, "commit", "-m", "test commit master"]
p_commit_2 = subprocess.run(
commit_cmd_2, capture_output=True, cwd=xtl_path, text=True
)
assert p_commit_2.returncode == 0
merge_cmd = [git2cpp_path, "merge", "foregone"]
p_merge = subprocess.run(merge_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_merge.returncode == 0
assert "conflict: " in p_merge.stdout
flag_cmd = [git2cpp_path, "merge", flag]
if flag == "--abort":
for answer in {"y", ""}:
p_abort = subprocess.run(
flag_cmd, input=answer, capture_output=True, cwd=xtl_path, text=True
)
assert p_abort.returncode == 0
assert (xtl_path / "mook_file.txt").exists()
with open(xtl_path / "mook_file.txt") as f:
if answer == "y":
assert "BLA" in f.read()
assert "bla" not in f.read()
else:
assert "Abort." in p_abort.stdout
elif flag == "--quit":
pass
# p_quit = subprocess.run(flag_cmd, capture_output=True, cwd=xtl_path, text=True)
# assert p_quit.returncode == 0
# assert (xtl_path / "mook_file.txt").exists()
# with open(xtl_path / "mook_file.txt") as f:
# lines = f.readlines()
# assert "<<<<<<< HEAD" in lines[0]
# assert ">>>>>>> foregone" in lines[-1]
# p_merge_2 = subprocess.run(
# merge_cmd, capture_output=True, cwd=xtl_path, text=True
# )
# assert p_merge_2.returncode != 0
# print(p_merge_2.stdout)
# assert "error: Merging is not possible because you have unmerged files." in p_merge_2.stdout
elif flag == "--continue":
# Create another branch pointing to the same commit (alias branch).
# This checks the merge behaviour when a different branch name points to the same commit.
branch_alias_cmd = [git2cpp_path, "branch", "foregone_alias"]
p_branch_alias = subprocess.run(
branch_alias_cmd, capture_output=True, cwd=xtl_path, text=True
)
assert p_branch_alias.returncode == 0
file_path.write_text("blablabla")
cmd_add = [git2cpp_path, "add", "mook_file.txt"]
p_add = subprocess.run(cmd_add, cwd=xtl_path, text=True)
assert p_add.returncode == 0
p_continue = subprocess.run(
flag_cmd, capture_output=True, cwd=xtl_path, text=True
)
assert p_continue.returncode == 0
log_cmd = [git2cpp_path, "log", "--format=full", "--max-count", "2"]
p_log = subprocess.run(log_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_log.returncode == 0
assert "Author: Jane Doe" in p_log.stdout
# assert "Commit: John Doe" in p_log.stdout
assert "Johan" not in p_log.stdout
assert (xtl_path / "mook_file.txt").exists()
assert (xtl_path / "mook_file_2.txt").exists()
merge_cmd_2 = [git2cpp_path, "merge", "foregone"]
p_merge_2 = subprocess.run(
merge_cmd_2, capture_output=True, cwd=xtl_path, text=True
)
assert p_merge_2.returncode == 0
assert p_merge_2.stdout == "Already up-to-date\n"