add -u: do not fail to resolve a path as deleted

After you resolve a conflicted merge to remove the path, "git add -u"
failed to record the removal.  Instead it errored out by saying that the
removed path is not found in the work tree, but that is what the user
already knows, and the wanted to record the removal as the resolution,
so the error does not make sense.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Junio C Hamano 2009-01-28 14:24:53 -08:00
Родитель 02322e1619
Коммит 4cc8d6c62d
2 изменённых файлов: 69 добавлений и 1 удалений

Просмотреть файл

@ -1574,6 +1574,26 @@ static void update_callback(struct diff_queue_struct *q,
default:
die("unexpected diff status %c", p->status);
case DIFF_STATUS_UNMERGED:
/*
* ADD_CACHE_IGNORE_REMOVAL is unset if "git
* add -u" is calling us, In such a case, a
* missing work tree file needs to be removed
* if there is an unmerged entry at stage #2,
* but such a diff record is followed by
* another with DIFF_STATUS_DELETED (and if
* there is no stage #2, we won't see DELETED
* nor MODIFIED). We can simply continue
* either way.
*/
if (!(data->flags & ADD_CACHE_IGNORE_REMOVAL))
continue;
/*
* Otherwise, it is "git add path" is asking
* to explicitly add it; we fall through. A
* missing work tree file is an error and is
* caught by add_file_to_index() in such a
* case.
*/
case DIFF_STATUS_MODIFIED:
case DIFF_STATUS_TYPE_CHANGED:
if (add_file_to_index(&the_index, path, data->flags)) {

Просмотреть файл

@ -12,7 +12,7 @@ and issues a git add -u with path limiting on "dir" to add
only the updates to dir/sub.
Also tested are "git add -u" without limiting, and "git add -u"
without contents changes.'
without contents changes, and other conditions'
. ./test-lib.sh
@ -128,4 +128,52 @@ test_expect_success 'add -n -u should not add but just report' '
'
test_expect_success 'add -u resolves unmerged paths' '
git reset --hard &&
one=$(echo 1 | git hash-object -w --stdin) &&
two=$(echo 2 | git hash-object -w --stdin) &&
three=$(echo 3 | git hash-object -w --stdin) &&
{
for path in path1 path2
do
echo "100644 $one 1 $path"
echo "100644 $two 2 $path"
echo "100644 $three 3 $path"
done
echo "100644 $one 1 path3"
echo "100644 $one 1 path4"
echo "100644 $one 3 path5"
echo "100644 $one 3 path6"
} |
git update-index --index-info &&
echo 3 >path1 &&
echo 2 >path3 &&
echo 2 >path5 &&
git add -u &&
git ls-files -s "path?" >actual &&
{
echo "100644 $three 0 path1"
echo "100644 $one 1 path3"
echo "100644 $one 1 path4"
echo "100644 $one 3 path5"
echo "100644 $one 3 path6"
} >expect &&
test_cmp expect actual &&
# Bonus tests. Explicit resolving
git add path3 path5 &&
test_must_fail git add path4 &&
test_must_fail git add path6 &&
git rm path4 &&
git rm path6 &&
git ls-files -s "path?" >actual &&
{
echo "100644 $three 0 path1"
echo "100644 $two 0 path3"
echo "100644 $two 0 path5"
} >expect
'
test_done