From cf56a695f96d13ed9f18bf376dd6d0d2b1c47e42 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 19 Mar 2015 07:48:18 +0100 Subject: [PATCH] Fix error when merging files with unicode content. 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. --- pygit2/repository.py | 2 +- test/test_repository.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pygit2/repository.py b/pygit2/repository.py index 6e0406370..c7330e187 100644 --- a/pygit2/repository.py +++ b/pygit2/repository.py @@ -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 diff --git a/test/test_repository.py b/test/test_repository.py index 860eaf217..3ee05bfe4 100644 --- a/test/test_repository.py +++ b/test/test_repository.py @@ -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() @@ -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) @@ -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 ''')