Support del in ConflictCollection

This commit is contained in:
Carlos Martín Nieto
2014-07-10 11:20:58 +02:00
parent 5ed9eb4228
commit ae32ad12ee
3 changed files with 22 additions and 5 deletions

View File

@@ -498,3 +498,4 @@ void git_index_conflict_iterator_free(git_index_conflict_iterator *iterator);
int git_index_conflict_iterator_new(git_index_conflict_iterator **iterator_out, git_index *index);
int git_index_conflict_get(const git_index_entry **ancestor_out, const git_index_entry **our_out, const git_index_entry **their_out, git_index *index, const char *path);
int git_index_conflict_next(const git_index_entry **ancestor_out, const git_index_entry **our_out, const git_index_entry **their_out, git_index_conflict_iterator *iterator);
int git_index_conflict_remove(git_index *index, const char *path);

View File

@@ -290,11 +290,14 @@ class Index(object):
def conflicts(self):
"""A collection of conflict information
Each conflict is made up of three elements (and access or
iteration of the conflicts returns a three-tuple of
:py:class:`~pygit2.IndexEntry`. The first is the common ancestor, the
second is the "ours" side of the conflict and the thirs is the
"theirs" side.
This presents a mapping interface with the paths as keys. You
can use the ``del`` operator to remove a conflict form the Index.
Each conflict is made up of three elements. Access or iteration
of the conflicts returns a three-tuple of
:py:class:`~pygit2.IndexEntry`. The first is the common
ancestor, the second is the "ours" side of the conflict and the
thirs is the "theirs" side.
These elements may be None depending on which sides exist for
the particular conflict.
@@ -385,6 +388,10 @@ class ConflictCollection(object):
return ancestor, ours, theirs
def __delitem__(self, path):
err = C.git_index_conflict_remove(self._index._index, to_str(path))
check_error(err)
def __iter__(self):
return ConflictIterator(self._index)

View File

@@ -127,3 +127,12 @@ class MergeTestWithConflicts(utils.RepoTestCaseForMerging):
self.repo.index.add('.gitignore')
self.repo.index.write()
self.assertRaises(KeyError, self.repo.index.conflicts.__getitem__, '.gitignore')
def test_merge_remove_conflicts(self):
other_branch_tip = '1b2bae55ac95a4be3f8983b86cd579226d0eb247'
self.repo.merge(other_branch_tip)
idx = self.repo.index
self.assertTrue(idx.has_conflicts)
self.assertRaises(KeyError, idx.conflicts.__delitem__, 'some-file')
del idx.conflicts['.gitignore']
self.assertFalse(idx.has_conflicts)