diff options
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | lib/git/diff.py | 1 | ||||
m--------- | lib/git/ext/gitdb | 0 | ||||
-rw-r--r-- | lib/git/index/base.py | 5 | ||||
-rw-r--r-- | lib/git/index/fun.py | 11 | ||||
-rw-r--r-- | test/git/test_fun.py | 30 |
6 files changed, 44 insertions, 6 deletions
@@ -6,7 +6,8 @@ CHANGES * ConcurrentWriteOperation was removed, and replaced by LockedFD * IndexFile.get_entries_key was renamed to entry_key * IndexEntry instances contained in IndexFile.entries now use binary sha's. Use - the .hexsha property to obtain the hexadecimal version + the .hexsha property to obtain the hexadecimal version. The .sha property + was removed to make the use of the respective sha more explicit. * IndexFile.write_tree: removed missing_ok keyword, its always True now Instead of raising GitCommandError it raises UnmergedEntriesError * diff.Diff.null_hex_sha renamed to NULL_HEX_SHA, to be conforming with diff --git a/lib/git/diff.py b/lib/git/diff.py index f9a0a66f..36b216e3 100644 --- a/lib/git/diff.py +++ b/lib/git/diff.py @@ -197,6 +197,7 @@ class Diff(object): """, re.VERBOSE | re.MULTILINE) # can be used for comparisons NULL_HEX_SHA = "0"*40 + NULL_BIN_SHA = "\0"*20 __slots__ = ("a_blob", "b_blob", "a_mode", "b_mode", "new_file", "deleted_file", "rename_from", "rename_to", "diff") diff --git a/lib/git/ext/gitdb b/lib/git/ext/gitdb -Subproject 9b53ab02cb44571e6167a125a5296b7c3395563 +Subproject d3a0037dd5a11459985e7dc4b6819f6292f20c1 diff --git a/lib/git/index/base.py b/lib/git/index/base.py index 771f1710..7568b476 100644 --- a/lib/git/index/base.py +++ b/lib/git/index/base.py @@ -530,9 +530,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): :raise ValueError: if there are no entries in the cache :raise UnmergedEntriesError: """ # we obtain no lock as we just flush our contents to disk as tree - if not self.entries: - raise ValueError("Cannot write empty index") - + # If we are a new index, the entries access will load our data accordingly mdb = MemoryDB() entries = self._entries_sorted() binsha, tree_items = write_tree_from_cache(entries, mdb, slice(0, len(entries))) @@ -892,7 +890,6 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): return out - @default_index def commit(self, message, parent_commits=None, head=True): """ Commit the current default index file, creating a commit object. diff --git a/lib/git/index/fun.py b/lib/git/index/fun.py index 23a6d8f9..14a47fdc 100644 --- a/lib/git/index/fun.py +++ b/lib/git/index/fun.py @@ -283,7 +283,16 @@ def aggressive_tree_merge(odb, tree_shas): elif theirs is None: # added in our branch out_append(_tree_entry_to_baseindexentry(ours, 0)) - # END hanle heads + else: + # both have it, except for the base, see whether it changed + if ours[0] != theirs[0] or ours[1] != theirs[1]: + out_append(_tree_entry_to_baseindexentry(ours, 2)) + out_append(_tree_entry_to_baseindexentry(theirs, 3)) + else: + # it was added the same in both + out_append(_tree_entry_to_baseindexentry(ours, 0)) + # END handle two items + # END handle heads # END handle base exists # END for each entries tuple diff --git a/test/git/test_fun.py b/test/git/test_fun.py index b2b94415..dad9fcda 100644 --- a/test/git/test_fun.py +++ b/test/git/test_fun.py @@ -114,6 +114,36 @@ class TestFun(TestBase): trees = [tb, th, tm] assert_entries(aggressive_tree_merge(odb, trees), 2) + # same file added in both, differently + fa = mkfile('1', shab) + th = mktree(odb, [fa]) + fb = mkfile('1', shac) + tm = mktree(odb, [fb]) + + # expect conflict + trees = [tb, th, tm] + assert_entries(aggressive_tree_merge(odb, trees), 2, True) + + # same file added, different mode + fa = mkfile('1', shab) + th = mktree(odb, [fa]) + fb = mkcommit('1', shab) + tm = mktree(odb, [fb]) + + # expect conflict + trees = [tb, th, tm] + assert_entries(aggressive_tree_merge(odb, trees), 2, True) + + # same file added in both + fa = mkfile('1', shab) + th = mktree(odb, [fa]) + fb = mkfile('1', shab) + tm = mktree(odb, [fb]) + + # expect conflict + trees = [tb, th, tm] + assert_entries(aggressive_tree_merge(odb, trees), 1) + # modify same base file, differently fa = mkfile(bfn, shab) th = mktree(odb, [fa]) |