aggressive_tree_merge: fixed incorrect handling of one branch, it was… · pythonthings/GitPython@55dcc17 · GitHub
Skip to content

Commit 55dcc17

Browse files
committed
aggressive_tree_merge: fixed incorrect handling of one branch, it was just not implemented causing incorrect merge results. Added test to cover this issue
Diff: added NULL_BIN_SHA constant for completeness
1 parent 129f90a commit 55dcc17

6 files changed

Lines changed: 45 additions & 7 deletions

File tree

CHANGES

Lines changed: 2 additions & 1 deletion

lib/git/diff.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ class Diff(object):
197197
""", re.VERBOSE | re.MULTILINE)
198198
# can be used for comparisons
199199
NULL_HEX_SHA = "0"*40
200+
NULL_BIN_SHA = "\0"*20
200201

201202
__slots__ = ("a_blob", "b_blob", "a_mode", "b_mode", "new_file", "deleted_file",
202203
"rename_from", "rename_to", "diff")

lib/git/ext/gitdb

Submodule gitdb updated from 9b53ab0 to d3a0037

lib/git/index/base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,7 @@ def write_tree(self):
530530
:raise ValueError: if there are no entries in the cache
531531
:raise UnmergedEntriesError: """
532532
# we obtain no lock as we just flush our contents to disk as tree
533-
if not self.entries:
534-
raise ValueError("Cannot write empty index")
535-
533+
# If we are a new index, the entries access will load our data accordingly
536534
mdb = MemoryDB()
537535
entries = self._entries_sorted()
538536
binsha, tree_items = write_tree_from_cache(entries, mdb, slice(0, len(entries)))
@@ -892,7 +890,6 @@ def move(self, items, skip_errors=False, **kwargs):
892890

893891
return out
894892

895-
@default_index
896893
def commit(self, message, parent_commits=None, head=True):
897894
"""
898895
Commit the current default index file, creating a commit object.

lib/git/index/fun.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,16 @@ def aggressive_tree_merge(odb, tree_shas):
283283
elif theirs is None:
284284
# added in our branch
285285
out_append(_tree_entry_to_baseindexentry(ours, 0))
286-
# END hanle heads
286+
else:
287+
# both have it, except for the base, see whether it changed
288+
if ours[0] != theirs[0] or ours[1] != theirs[1]:
289+
out_append(_tree_entry_to_baseindexentry(ours, 2))
290+
out_append(_tree_entry_to_baseindexentry(theirs, 3))
291+
else:
292+
# it was added the same in both
293+
out_append(_tree_entry_to_baseindexentry(ours, 0))
294+
# END handle two items
295+
# END handle heads
287296
# END handle base exists
288297
# END for each entries tuple
289298

test/git/test_fun.py

Lines changed: 30 additions & 0 deletions

0 commit comments

Comments
 (0)