Skip to content

Commit

Permalink
Fix error when merging files with unicode content.
Browse files Browse the repository at this point in the history
When merging index entries where the corresponding files contain Unicode
codepoints an error is thrown. Decode the C string using UTF-8 to fix the issue
and adjust the test case for merging files to contain umlauts to catch such
errors.
  • Loading branch information
pks-t committed Mar 19, 2015
1 parent 8b05b29 commit cf56a69
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pygit2/repository.py
Expand Up @@ -555,7 +555,7 @@ def merge_file_from_index(self, ancestor, ours, theirs):
check_error(err)

ret = ffi.string(cmergeresult.ptr,
cmergeresult.len).decode()
cmergeresult.len).decode('utf-8')
C.git_merge_file_result_free(cmergeresult)

return ret
Expand Down
10 changes: 5 additions & 5 deletions test/test_repository.py
Expand Up @@ -200,7 +200,7 @@ def test_hashfile(self):

def test_conflicts_in_bare_repository(self):
def create_conflict_file(repo, branch, content):
oid = repo.create_blob(content)
oid = repo.create_blob(content.encode('utf-8'))
tb = repo.TreeBuilder()
tb.insert('conflict', oid, pygit2.GIT_FILEMODE_BLOB)
tree = tb.write()
Expand All @@ -212,9 +212,9 @@ def create_conflict_file(repo, branch, content):
return commit

b1 = self.repo.create_branch('b1', self.repo.head.peel())
c1 = create_conflict_file(self.repo, b1, 'Conflict 1')
c1 = create_conflict_file(self.repo, b1, 'ASCII - abc')
b2 = self.repo.create_branch('b2', self.repo.head.peel())
c2 = create_conflict_file(self.repo, b2, 'Conflict 2')
c2 = create_conflict_file(self.repo, b2, 'Unicode - äüö')

index = self.repo.merge_commits(c1, c2)
self.assertIsNotNone(index.conflicts)
Expand All @@ -226,9 +226,9 @@ def create_conflict_file(repo, branch, content):
(a, t, o) = index.conflicts['conflict']
diff = self.repo.merge_file_from_index(a, t, o)
self.assertEqual(diff, '''<<<<<<< conflict
Conflict 1
ASCII - abc
=======
Conflict 2
Unicode - äüö
>>>>>>> conflict
''')

Expand Down

0 comments on commit cf56a69

Please sign in to comment.