Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 55dcc17

Browse filesBrowse 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
Copy full SHA for 55dcc17

6 files changed

+45-7Lines changed: 45 additions & 7 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎CHANGES‎

Copy file name to clipboardExpand all lines: CHANGES
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ CHANGES
66
* ConcurrentWriteOperation was removed, and replaced by LockedFD
77
* IndexFile.get_entries_key was renamed to entry_key
88
* IndexEntry instances contained in IndexFile.entries now use binary sha's. Use
9-
the .hexsha property to obtain the hexadecimal version
9+
the .hexsha property to obtain the hexadecimal version. The .sha property
10+
was removed to make the use of the respective sha more explicit.
1011
* IndexFile.write_tree: removed missing_ok keyword, its always True now
1112
Instead of raising GitCommandError it raises UnmergedEntriesError
1213
* diff.Diff.null_hex_sha renamed to NULL_HEX_SHA, to be conforming with
Collapse file

‎lib/git/diff.py‎

Copy file name to clipboardExpand all lines: lib/git/diff.py
+1Lines 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")
Collapse file

‎lib/git/ext/gitdb‎

Copy file name to clipboard
Submodule gitdb updated from 9b53ab0 to d3a0037
Collapse file

‎lib/git/index/base.py‎

Copy file name to clipboardExpand all lines: lib/git/index/base.py
+1-4Lines 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.
Collapse file

‎lib/git/index/fun.py‎

Copy file name to clipboardExpand all lines: lib/git/index/fun.py
+10-1Lines 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

Collapse file

‎test/git/test_fun.py‎

Copy file name to clipboardExpand all lines: test/git/test_fun.py
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,36 @@ def assert_entries(entries, num_entries, has_conflict=False):
114114
trees = [tb, th, tm]
115115
assert_entries(aggressive_tree_merge(odb, trees), 2)
116116

117+
# same file added in both, differently
118+
fa = mkfile('1', shab)
119+
th = mktree(odb, [fa])
120+
fb = mkfile('1', shac)
121+
tm = mktree(odb, [fb])
122+
123+
# expect conflict
124+
trees = [tb, th, tm]
125+
assert_entries(aggressive_tree_merge(odb, trees), 2, True)
126+
127+
# same file added, different mode
128+
fa = mkfile('1', shab)
129+
th = mktree(odb, [fa])
130+
fb = mkcommit('1', shab)
131+
tm = mktree(odb, [fb])
132+
133+
# expect conflict
134+
trees = [tb, th, tm]
135+
assert_entries(aggressive_tree_merge(odb, trees), 2, True)
136+
137+
# same file added in both
138+
fa = mkfile('1', shab)
139+
th = mktree(odb, [fa])
140+
fb = mkfile('1', shab)
141+
tm = mktree(odb, [fb])
142+
143+
# expect conflict
144+
trees = [tb, th, tm]
145+
assert_entries(aggressive_tree_merge(odb, trees), 1)
146+
117147
# modify same base file, differently
118148
fa = mkfile(bfn, shab)
119149
th = mktree(odb, [fa])

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.