@@ -198,6 +198,39 @@ def test_hashfile(self):
198198 written_sha1 = self .repo .create_blob (data )
199199 self .assertEqual (hashed_sha1 , written_sha1 )
200200
201+ def test_conflicts_in_bare_repository (self ):
202+ def create_conflict_file (repo , branch , content ):
203+ oid = repo .create_blob (content )
204+ tb = repo .TreeBuilder ()
205+ tb .insert ('conflict' , oid , pygit2 .GIT_FILEMODE_BLOB )
206+ tree = tb .write ()
207+
208+ sig = pygit2 .Signature ('Author' , 'author@example.com' )
209+ commit = repo .create_commit (branch .name , sig , sig ,
210+ 'Conflict' , tree , [branch .target ])
211+ self .assertIsNotNone (commit )
212+ return commit
213+
214+ b1 = self .repo .create_branch ('b1' , self .repo .head .peel ())
215+ c1 = create_conflict_file (self .repo , b1 , 'Conflict 1' )
216+ b2 = self .repo .create_branch ('b2' , self .repo .head .peel ())
217+ c2 = create_conflict_file (self .repo , b2 , 'Conflict 2' )
218+
219+ index = self .repo .merge_commits (c1 , c2 )
220+ self .assertIsNotNone (index .conflicts )
221+
222+ # ConflictCollection does not allow calling len(...) on it directly so
223+ # we have to calculate length by iterating over its entries
224+ self .assertEqual (sum (1 for _ in index .conflicts ), 1 )
225+
226+ (a , t , o ) = index .conflicts ['conflict' ]
227+ diff = self .repo .merge_file_from_index (a , t , o )
228+ self .assertEqual (diff , '''<<<<<<< conflict
229+ Conflict 1
230+ =======
231+ Conflict 2
232+ >>>>>>> conflict
233+ ''' )
201234
202235class RepositoryTest_II (utils .RepoTestCase ):
203236
0 commit comments