MCPcopy Create free account
hub / github.com/libgit2/pygit2 / test_conflicts_in_bare_repository

Function test_conflicts_in_bare_repository

test/test_repository_bare.py:211–251  ·  view source on GitHub ↗
(barerepo: Repository)

Source from the content-addressed store, hash-verified

209
210
211def test_conflicts_in_bare_repository(barerepo: Repository) -> None:
212 def create_conflict_file(repo: Repository, branch: Branch, content: str) -> Oid:
213 oid = repo.create_blob(content.encode('utf-8'))
214 tb = repo.TreeBuilder()
215 tb.insert('conflict', oid, FileMode.BLOB)
216 tree = tb.write()
217
218 sig = pygit2.Signature('Author', 'author@example.com')
219 commit = repo.create_commit(
220 branch.name, sig, sig, 'Conflict', tree, [branch.target]
221 )
222 assert commit is not None
223 return commit
224
225 head_peeled = barerepo.head.peel()
226 assert isinstance(head_peeled, Commit)
227 b1 = barerepo.create_branch('b1', head_peeled)
228 c1 = create_conflict_file(barerepo, b1, 'ASCII - abc')
229 head_peeled = barerepo.head.peel()
230 assert isinstance(head_peeled, Commit)
231 b2 = barerepo.create_branch('b2', head_peeled)
232 c2 = create_conflict_file(barerepo, b2, 'Unicode - äüö')
233
234 index = barerepo.merge_commits(c1, c2)
235 assert index.conflicts is not None
236
237 # ConflictCollection does not allow calling len(...) on it directly so
238 # we have to calculate length by iterating over its entries
239 assert sum(1 for _ in index.conflicts) == 1
240
241 (a, t, o) = index.conflicts['conflict']
242 diff = barerepo.merge_file_from_index(a, t, o)
243 assert (
244 diff
245 == """<<<<<<< conflict
246ASCII - abc
247=======
248Unicode - äüö
249>>>>>>> conflict
250"""
251 )

Callers

nothing calls this directly

Calls 3

create_conflict_fileFunction · 0.85
merge_commitsMethod · 0.80
merge_file_from_indexMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…