mirror of
https://github.com/git/git
synced 2024-10-31 08:44:08 +00:00
ad3762042a
read_index_unmerged() has two intended purposes: * return 1 if there are any unmerged entries, 0 otherwise * drops any higher-stage entries down to stage #0 There are several callers of read_index_unmerged() that check the return value to see if it is non-zero, all of which then die() if that condition is met. For these callers, dropping higher-stage entries down to stage #0 is a waste of resources, and returning immediately on first unmerged entry would be better. But it's probably only a very minor difference and isn't the focus of this series. The remaining callers ignore the return value and call this function for the side effect of dropping higher-stage entries down to stage #0. As mentioned in commite11d7b5969
("'reset --merge': fix unmerged case", 2009-12-31), The _only_ reason we want to keep a previously unmerged entry in the index at stage #0 is so that we don't forget the fact that we have corresponding file in the work tree in order to be able to remove it when the tree we are resetting to does not have the path. In fact, prior to commitd1a43f2aa4
("reset --hard/read-tree --reset -u: remove unmerged new paths", 2008-10-15), read_index_unmerged() did just remove unmerged entries from the cache immediately but that had the unwanted effect of leaving around new untracked files in the tree from aborted merges. So, that's the intended purpose of this function. The problem is that when directory/files conflicts are present, trying to add the file to the index at stage 0 fails (because there is still a directory in the way), and the function returns early with a -1 return code to signify the error. As noted above, none of the callers who want the drop-to-stage-0 behavior check the return status, though, so this means all remaining unmerged entries remain in the index and the callers proceed assuming otherwise. Users then see errors of the form: error: 'DIR-OR-FILE' appears as both a file and as a directory error: DIR-OR-FILE: cannot drop to stage #0 and potentially also messages about other unmerged entries which came lexicographically later than whatever pathname was both a file and a directory. Google finds a few hits searching for those messages, suggesting there were probably a couple people who hit this besides me. Luckily, calling `git reset --hard` multiple times would workaround this bug. Since the whole purpose here is to just put the entry *temporarily* into the index so that any associated file in the working copy can be removed, we can just skip the DFCHECK and allow both the file and directory to appear in the index. The temporary simultaneous appearance of the directory and file entries in the index will be removed by the callers by calling unpack_trees(), which excludes these unmerged entries marked with CE_CONFLICTED flag from the resulting index, before they attempt to write the index anywhere. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
107 lines
2.2 KiB
Bash
Executable file
107 lines
2.2 KiB
Bash
Executable file
#!/bin/sh
|
|
#
|
|
# Copyright (c) 2005 Fredrik Kuivinen
|
|
#
|
|
|
|
test_description='Test merge with directory/file conflicts'
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success 'prepare repository' '
|
|
echo Hello >init &&
|
|
git add init &&
|
|
git commit -m initial &&
|
|
|
|
git branch B &&
|
|
mkdir dir &&
|
|
echo foo >dir/foo &&
|
|
git add dir/foo &&
|
|
git commit -m "File: dir/foo" &&
|
|
|
|
git checkout B &&
|
|
echo file dir >dir &&
|
|
git add dir &&
|
|
git commit -m "File: dir"
|
|
'
|
|
|
|
test_expect_success 'Merge with d/f conflicts' '
|
|
test_expect_code 1 git merge -m "merge msg" master
|
|
'
|
|
|
|
test_expect_success 'F/D conflict' '
|
|
git reset --hard &&
|
|
git checkout master &&
|
|
rm .git/index &&
|
|
|
|
mkdir before &&
|
|
echo FILE >before/one &&
|
|
echo FILE >after &&
|
|
git add . &&
|
|
git commit -m first &&
|
|
|
|
rm -f after &&
|
|
git mv before after &&
|
|
git commit -m move &&
|
|
|
|
git checkout -b para HEAD^ &&
|
|
echo COMPLETELY ANOTHER FILE >another &&
|
|
git add . &&
|
|
git commit -m para &&
|
|
|
|
git merge master
|
|
'
|
|
|
|
test_expect_success 'setup modify/delete + directory/file conflict' '
|
|
git checkout --orphan modify &&
|
|
git rm -rf . &&
|
|
git clean -fdqx &&
|
|
|
|
printf "a\nb\nc\nd\ne\nf\ng\nh\n" >letters &&
|
|
git add letters &&
|
|
git commit -m initial &&
|
|
|
|
# Throw in letters.txt for sorting order fun
|
|
# ("letters.txt" sorts between "letters" and "letters/file")
|
|
echo i >>letters &&
|
|
echo "version 2" >letters.txt &&
|
|
git add letters letters.txt &&
|
|
git commit -m modified &&
|
|
|
|
git checkout -b delete HEAD^ &&
|
|
git rm letters &&
|
|
mkdir letters &&
|
|
>letters/file &&
|
|
echo "version 1" >letters.txt &&
|
|
git add letters letters.txt &&
|
|
git commit -m deleted
|
|
'
|
|
|
|
test_expect_success 'modify/delete + directory/file conflict' '
|
|
git checkout delete^0 &&
|
|
test_must_fail git merge modify &&
|
|
|
|
test 5 -eq $(git ls-files -s | wc -l) &&
|
|
test 4 -eq $(git ls-files -u | wc -l) &&
|
|
test 1 -eq $(git ls-files -o | wc -l) &&
|
|
|
|
test -f letters/file &&
|
|
test -f letters.txt &&
|
|
test -f letters~modify
|
|
'
|
|
|
|
test_expect_success 'modify/delete + directory/file conflict; other way' '
|
|
git reset --hard &&
|
|
git clean -f &&
|
|
git checkout modify^0 &&
|
|
|
|
test_must_fail git merge delete &&
|
|
|
|
test 5 -eq $(git ls-files -s | wc -l) &&
|
|
test 4 -eq $(git ls-files -u | wc -l) &&
|
|
test 1 -eq $(git ls-files -o | wc -l) &&
|
|
|
|
test -f letters/file &&
|
|
test -f letters.txt &&
|
|
test -f letters~HEAD
|
|
'
|
|
|
|
test_done
|