@@ -39,6 +39,16 @@ def test_merge_invalid_type(mergerepo, id):
39
39
mergerepo .merge (id )
40
40
41
41
42
+ # TODO: Once Repository.merge drops support for str arguments,
43
+ # add an extra parameter to test_merge_invalid_type above
44
+ # to make sure we cover legacy code.
45
+ def test_merge_string_argument_deprecated (mergerepo ):
46
+ branch_head_hex = '5ebeeebb320790caf276b9fc8b24546d63316533'
47
+
48
+ with pytest .warns (DeprecationWarning , match = r'Pass Commit.+instead' ):
49
+ mergerepo .merge (branch_head_hex )
50
+
51
+
42
52
def test_merge_analysis_uptodate (mergerepo ):
43
53
branch_head_hex = '5ebeeebb320790caf276b9fc8b24546d63316533'
44
54
branch_id = mergerepo .get (branch_head_hex ).id
@@ -82,7 +92,10 @@ def test_merge_no_fastforward_no_conflicts(mergerepo):
82
92
83
93
def test_merge_invalid_hex (mergerepo ):
84
94
branch_head_hex = '12345678'
85
- with pytest .raises (KeyError ):
95
+ with (
96
+ pytest .raises (KeyError ),
97
+ pytest .warns (DeprecationWarning , match = r'Pass Commit.+instead' ),
98
+ ):
86
99
mergerepo .merge (branch_head_hex )
87
100
88
101
@@ -132,7 +145,7 @@ def test_merge_no_fastforward_conflicts(mergerepo):
132
145
133
146
134
147
def test_merge_remove_conflicts (mergerepo ):
135
- other_branch_tip = '1b2bae55ac95a4be3f8983b86cd579226d0eb247'
148
+ other_branch_tip = pygit2 . Oid ( hex = '1b2bae55ac95a4be3f8983b86cd579226d0eb247' )
136
149
mergerepo .merge (other_branch_tip )
137
150
idx = mergerepo .index
138
151
conflicts = idx .conflicts
@@ -158,30 +171,29 @@ def test_merge_remove_conflicts(mergerepo):
158
171
],
159
172
)
160
173
def test_merge_favor (mergerepo , favor ):
161
- branch_head_hex = '1b2bae55ac95a4be3f8983b86cd579226d0eb247'
162
- mergerepo .merge (branch_head_hex , favor = favor )
174
+ branch_head = pygit2 . Oid ( hex = '1b2bae55ac95a4be3f8983b86cd579226d0eb247' )
175
+ mergerepo .merge (branch_head , favor = favor )
163
176
164
177
assert mergerepo .index .conflicts is None
165
178
166
179
167
180
def test_merge_fail_on_conflict (mergerepo ):
168
- branch_head_hex = '1b2bae55ac95a4be3f8983b86cd579226d0eb247'
181
+ branch_head = pygit2 . Oid ( hex = '1b2bae55ac95a4be3f8983b86cd579226d0eb247' )
169
182
170
- with pytest .raises (pygit2 .GitError ):
183
+ with pytest .raises (pygit2 .GitError , match = r'merge conflicts exist' ):
171
184
mergerepo .merge (
172
- branch_head_hex , flags = MergeFlag .FIND_RENAMES | MergeFlag .FAIL_ON_CONFLICT
185
+ branch_head , flags = MergeFlag .FIND_RENAMES | MergeFlag .FAIL_ON_CONFLICT
173
186
)
174
187
175
188
176
189
def test_merge_commits (mergerepo ):
177
- branch_head_hex = '03490f16b15a09913edb3a067a3dc67fbb8d41f1'
178
- branch_id = mergerepo .get (branch_head_hex ).id
190
+ branch_head = pygit2 .Oid (hex = '03490f16b15a09913edb3a067a3dc67fbb8d41f1' )
179
191
180
- merge_index = mergerepo .merge_commits (mergerepo .head .target , branch_head_hex )
192
+ merge_index = mergerepo .merge_commits (mergerepo .head .target , branch_head )
181
193
assert merge_index .conflicts is None
182
194
merge_commits_tree = merge_index .write_tree (mergerepo )
183
195
184
- mergerepo .merge (branch_id )
196
+ mergerepo .merge (branch_head )
185
197
index = mergerepo .index
186
198
assert index .conflicts is None
187
199
merge_tree = index .write_tree ()
@@ -190,26 +202,23 @@ def test_merge_commits(mergerepo):
190
202
191
203
192
204
def test_merge_commits_favor (mergerepo ):
193
- branch_head_hex = '1b2bae55ac95a4be3f8983b86cd579226d0eb247'
205
+ branch_head = pygit2 . Oid ( hex = '1b2bae55ac95a4be3f8983b86cd579226d0eb247' )
194
206
195
207
merge_index = mergerepo .merge_commits (
196
- mergerepo .head .target , branch_head_hex , favor = MergeFavor .OURS
208
+ mergerepo .head .target , branch_head , favor = MergeFavor .OURS
197
209
)
198
210
assert merge_index .conflicts is None
199
211
200
212
# Incorrect favor value
201
- with pytest .raises (TypeError ):
202
- mergerepo .merge_commits (mergerepo .head .target , branch_head_hex , favor = 'foo' )
213
+ with pytest .raises (TypeError , match = r'favor argument must be MergeFavor' ):
214
+ mergerepo .merge_commits (mergerepo .head .target , branch_head , favor = 'foo' )
203
215
204
216
205
217
def test_merge_trees (mergerepo ):
206
- branch_head_hex = '03490f16b15a09913edb3a067a3dc67fbb8d41f1'
207
- branch_id = mergerepo .get (branch_head_hex ).id
218
+ branch_id = pygit2 .Oid (hex = '03490f16b15a09913edb3a067a3dc67fbb8d41f1' )
208
219
ancestor_id = mergerepo .merge_base (mergerepo .head .target , branch_id )
209
220
210
- merge_index = mergerepo .merge_trees (
211
- ancestor_id , mergerepo .head .target , branch_head_hex
212
- )
221
+ merge_index = mergerepo .merge_trees (ancestor_id , mergerepo .head .target , branch_id )
213
222
assert merge_index .conflicts is None
214
223
merge_commits_tree = merge_index .write_tree (mergerepo )
215
224
@@ -312,10 +321,10 @@ def test_merge_octopus(mergerepo):
312
321
def test_merge_mergeheads (mergerepo ):
313
322
assert mergerepo .listall_mergeheads () == []
314
323
315
- branch_head_hex = '1b2bae55ac95a4be3f8983b86cd579226d0eb247'
316
- mergerepo .merge (branch_head_hex )
324
+ branch_head = pygit2 . Oid ( hex = '1b2bae55ac95a4be3f8983b86cd579226d0eb247' )
325
+ mergerepo .merge (branch_head )
317
326
318
- assert mergerepo .listall_mergeheads () == [pygit2 . Oid ( hex = branch_head_hex ) ]
327
+ assert mergerepo .listall_mergeheads () == [branch_head ]
319
328
320
329
mergerepo .state_cleanup ()
321
330
assert mergerepo .listall_mergeheads () == [], (
@@ -327,27 +336,28 @@ def test_merge_message(mergerepo):
327
336
assert not mergerepo .message
328
337
assert not mergerepo .raw_message
329
338
330
- branch_head_hex = '1b2bae55ac95a4be3f8983b86cd579226d0eb247'
331
- mergerepo .merge (branch_head_hex )
339
+ branch_head = pygit2 . Oid ( hex = '1b2bae55ac95a4be3f8983b86cd579226d0eb247' )
340
+ mergerepo .merge (branch_head )
332
341
333
- assert mergerepo .message .startswith (f"Merge commit '{ branch_head_hex } '" )
342
+ assert mergerepo .message .startswith (f"Merge commit '{ branch_head } '" )
334
343
assert mergerepo .message .encode ('utf-8' ) == mergerepo .raw_message
335
344
336
345
mergerepo .state_cleanup ()
337
346
assert not mergerepo .message
338
347
339
348
340
349
def test_merge_remove_message (mergerepo ):
341
- branch_head_hex = '1b2bae55ac95a4be3f8983b86cd579226d0eb247'
342
- mergerepo .merge (branch_head_hex )
350
+ branch_head = pygit2 . Oid ( hex = '1b2bae55ac95a4be3f8983b86cd579226d0eb247' )
351
+ mergerepo .merge (branch_head )
343
352
344
- assert mergerepo .message .startswith (f"Merge commit '{ branch_head_hex } '" )
353
+ assert mergerepo .message .startswith (f"Merge commit '{ branch_head } '" )
345
354
mergerepo .remove_message ()
346
355
assert not mergerepo .message
347
356
348
357
349
358
def test_merge_commit (mergerepo ):
350
359
commit = mergerepo ['1b2bae55ac95a4be3f8983b86cd579226d0eb247' ]
360
+ assert isinstance (commit , pygit2 .Commit )
351
361
mergerepo .merge (commit )
352
362
353
363
assert mergerepo .message .startswith (f"Merge commit '{ str (commit .id )} '" )
0 commit comments