Skip to content

Commit

Permalink
Merge branch 'jc/maint-1.6.1-add-u-remove-conflicted' into maint-1.6.1
Browse files Browse the repository at this point in the history
* jc/maint-1.6.1-add-u-remove-conflicted:
  add -u: do not fail to resolve a path as deleted
  • Loading branch information
Junio C Hamano committed Mar 13, 2009
2 parents 54e7e78 + 4cc8d6c commit d9b0443
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
20 changes: 20 additions & 0 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
50 changes: 49 additions & 1 deletion t/t2200-add-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

0 comments on commit d9b0443

Please sign in to comment.