FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
git2cpp/test/test_merge.py at main · QuantStack/git2cpp · GitHub
QuantStack
git2cpp
Repository navigation
Code
Issues
6
(6)
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
git2cpp
/
test
/
test_merge.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
216 lines (170 loc) · 8.66 KB
Breadcrumbs
git2cpp
/
test
/
test_merge.py
Copy path
File metadata and controls
216 lines (170 loc) · 8.66 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
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
(
repo_init_with_commit
,
commit_env_config
,
git2cpp_path
,
tmp_path
):
assert
(
tmp_path
/
"initial.txt"
).
exists
()
checkout_cmd
=
[
git2cpp_path
,
"checkout"
,
"-b"
,
"foregone"
]
p_checkout
=
subprocess
.
run
(
checkout_cmd
,
capture_output
=
True
,
cwd
=
tmp_path
,
text
=
True
)
assert
p_checkout
.
returncode
==
0
file_path
=
tmp_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
=
tmp_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
=
tmp_path
,
text
=
True
)
assert
p_commit
.
returncode
==
0
checkout_cmd_2
=
[
git2cpp_path
,
"checkout"
,
"main"
]
p_checkout_2
=
subprocess
.
run
(
checkout_cmd_2
,
capture_output
=
True
,
cwd
=
tmp_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
=
tmp_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
=
tmp_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
(
tmp_path
/
"mook_file.txt"
).
exists
()
merge_cmd_2
=
[
git2cpp_path
,
"merge"
,
"foregone"
]
p_merge_2
=
subprocess
.
run
(
merge_cmd_2
,
capture_output
=
True
,
cwd
=
tmp_path
,
text
=
True
)
assert
p_merge_2
.
returncode
==
0
assert
p_merge_2
.
stdout
==
"Already up-to-date
\n
"
def
test_merge_commit
(
repo_init_with_commit
,
commit_env_config
,
git2cpp_path
,
tmp_path
):
assert
(
tmp_path
/
"initial.txt"
).
exists
()
checkout_cmd
=
[
git2cpp_path
,
"checkout"
,
"-b"
,
"foregone"
]
p_checkout
=
subprocess
.
run
(
checkout_cmd
,
capture_output
=
True
,
cwd
=
tmp_path
,
text
=
True
)
assert
p_checkout
.
returncode
==
0
file_path
=
tmp_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
=
tmp_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
=
tmp_path
,
text
=
True
)
assert
p_commit
.
returncode
==
0
checkout_cmd_2
=
[
git2cpp_path
,
"checkout"
,
"main"
]
p_checkout_2
=
subprocess
.
run
(
checkout_cmd_2
,
capture_output
=
True
,
cwd
=
tmp_path
,
text
=
True
)
assert
p_checkout_2
.
returncode
==
0
file_path_2
=
tmp_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
=
tmp_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
=
tmp_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
=
tmp_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
=
tmp_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
(
tmp_path
/
"mook_file.txt"
).
exists
()
assert
(
tmp_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
=
tmp_path
,
text
=
True
)
assert
p_merge_2
.
returncode
==
0
assert
p_merge_2
.
stdout
==
"Already up-to-date
\n
"
@
pytest
.
mark
.
parametrize
(
"flag,abort_input"
,
[
(
"--abort"
,
"y"
),
(
"--abort"
,
"Y"
),
(
"--abort"
,
"n"
),
(
"--abort"
,
"N"
),
(
"--abort"
,
""
),
(
"--quit"
,
None
),
(
"--continue"
,
None
),
],
)
def
test_merge_conflict
(
repo_init_with_commit
,
commit_env_config
,
git2cpp_path
,
tmp_path
,
flag
,
abort_input
):
assert
(
tmp_path
/
"initial.txt"
).
exists
()
checkout_cmd
=
[
git2cpp_path
,
"checkout"
,
"-b"
,
"foregone"
]
p_checkout
=
subprocess
.
run
(
checkout_cmd
,
capture_output
=
True
,
cwd
=
tmp_path
,
text
=
True
)
assert
p_checkout
.
returncode
==
0
file_path
=
tmp_path
/
"mook_file.txt"
file_path
.
write_text
(
"blablabla"
)
file_path_2
=
tmp_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
=
tmp_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
=
tmp_path
,
text
=
True
)
assert
p_commit
.
returncode
==
0
checkout_cmd_2
=
[
git2cpp_path
,
"checkout"
,
"main"
]
p_checkout_2
=
subprocess
.
run
(
checkout_cmd_2
,
capture_output
=
True
,
cwd
=
tmp_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
=
tmp_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
=
tmp_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
=
tmp_path
,
text
=
True
)
assert
p_merge
.
returncode
==
0
assert
"conflict: "
in
p_merge
.
stdout
flag_cmd
=
[
git2cpp_path
,
"merge"
,
flag
]
if
flag
==
"--abort"
:
p_abort
=
subprocess
.
run
(
flag_cmd
,
input
=
abort_input
,
capture_output
=
True
,
cwd
=
tmp_path
,
text
=
True
)
assert
p_abort
.
returncode
==
0
assert
(
tmp_path
/
"mook_file.txt"
).
exists
()
text
=
(
tmp_path
/
"mook_file.txt"
).
read_text
()
if
abort_input
.
lower
()
==
"y"
:
assert
"BLA"
in
text
assert
"bla"
not
in
text
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
=
tmp_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
=
tmp_path
,
text
=
True
)
assert
p_add
.
returncode
==
0
p_continue
=
subprocess
.
run
(
flag_cmd
,
capture_output
=
True
,
cwd
=
tmp_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
=
tmp_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
(
tmp_path
/
"mook_file.txt"
).
exists
()
assert
(
tmp_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
=
tmp_path
,
text
=
True
)
assert
p_merge_2
.
returncode
==
0
assert
p_merge_2
.
stdout
==
"Already up-to-date
\n
"
Back
|
FazBrowse Home
|
New Git URL