Skip to content

Commit b018ff6

Browse files
peffgitster
authored andcommitted
unpack-trees: fix "read-tree -u --reset A B" with conflicted index
When we call "read-tree --reset -u HEAD ORIG_HEAD", the first thing we do with the index is to call read_cache_unmerged. Originally that would read the index, leaving aside any unmerged entries. However, as of d1a43f2 (reset --hard/read-tree --reset -u: remove unmerged new paths, 2008-10-15), it actually creates a new cache entry to serve as a placeholder, so that we later know to update the working tree. However, we later noticed that the sha1 of that unmerged entry was just copied from some higher stage, leaving you with random content in the index. That was fixed by e11d7b5 ("reset --merge": fix unmerged case, 2009-12-31), which instead puts the null sha1 into the newly created entry, and sets a CE_CONFLICTED flag. At the same time, it teaches the unpack-trees machinery to pay attention to this flag, so that oneway_merge throws away the current value. However, it did not update the code paths for twoway_merge, which is where we end up in the two-way read-tree with --reset. We notice that the HEAD and ORIG_HEAD versions are the same, and say "oh, we can just reuse the current version". But that's not true. The current version is bogus. Notice this case and make sure we do not keep the bogus entry; either we do not have that path in the tree we are moving to (i.e. remove it), or we want to have the cache entry we created for the tree we are moving to (i.e. resolve by explicitly saying the "newtree" version is what we want). [jc: this is from the almost year-old $gmane/212316] Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c479d14 commit b018ff6

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

unpack-trees.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,14 +1728,23 @@ int twoway_merge(struct cache_entry **src, struct unpack_trees_options *o)
17281728
newtree = NULL;
17291729

17301730
if (current) {
1731-
if ((!oldtree && !newtree) || /* 4 and 5 */
1732-
(!oldtree && newtree &&
1733-
same(current, newtree)) || /* 6 and 7 */
1734-
(oldtree && newtree &&
1735-
same(oldtree, newtree)) || /* 14 and 15 */
1736-
(oldtree && newtree &&
1737-
!same(oldtree, newtree) && /* 18 and 19 */
1738-
same(current, newtree))) {
1731+
if (current->ce_flags & CE_CONFLICTED) {
1732+
if (same(oldtree, newtree) || o->reset) {
1733+
if (!newtree)
1734+
return deleted_entry(current, current, o);
1735+
else
1736+
return merged_entry(newtree, current, o);
1737+
}
1738+
return o->gently ? -1 : reject_merge(current, o);
1739+
}
1740+
else if ((!oldtree && !newtree) || /* 4 and 5 */
1741+
(!oldtree && newtree &&
1742+
same(current, newtree)) || /* 6 and 7 */
1743+
(oldtree && newtree &&
1744+
same(oldtree, newtree)) || /* 14 and 15 */
1745+
(oldtree && newtree &&
1746+
!same(oldtree, newtree) && /* 18 and 19 */
1747+
same(current, newtree))) {
17391748
return keep_entry(current, o);
17401749
}
17411750
else if (oldtree && !newtree && same(current, oldtree)) {

0 commit comments

Comments
 (0)