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>
Junio C Hamano committed
Jan 28, 2009 at 14:24 UTC
4cc8d6c62db1f82b3c98468806d2ee54c7e037ca
2 files changed
+69
-1
read-cache.c
+20
@@ -1574,6 +1574,26 @@ static void update_callback(struct diff_queue_struct *q,
1574
default:
1575
die("unexpected diff status %c", p->status);
1576
case DIFF_STATUS_UNMERGED:
1577
+ /*
1578
+ * ADD_CACHE_IGNORE_REMOVAL is unset if "git
1579
+ * add -u" is calling us, In such a case, a
1580
+ * missing work tree file needs to be removed
1581
+ * if there is an unmerged entry at stage #2,
1582
+ * but such a diff record is followed by
1583
+ * another with DIFF_STATUS_DELETED (and if
1584
+ * there is no stage #2, we won't see DELETED
1585
+ * nor MODIFIED). We can simply continue
1586
+ * either way.
1587
+ */
1588
+ if (!(data->flags & ADD_CACHE_IGNORE_REMOVAL))
1589
+ continue;
1590
+ /*
1591
+ * Otherwise, it is "git add path" is asking
1592
+ * to explicitly add it; we fall through. A
1593
+ * missing work tree file is an error and is
1594
+ * caught by add_file_to_index() in such a
1595
+ * case.
1596
+ */
1597
case DIFF_STATUS_MODIFIED:
1598
case DIFF_STATUS_TYPE_CHANGED:
1599
if (add_file_to_index(&the_index, path, data->flags)) {
t/t2200-add-update.sh
+49
-1
@@ -12,7 +12,7 @@ and issues a git add -u with path limiting on "dir" to add
12
only the updates to dir/sub.
13
14
Also tested are "git add -u" without limiting, and "git add -u"
15
-without contents changes.'
15
+without contents changes, and other conditions'
16
17
. ./test-lib.sh
18
@@ -128,4 +128,52 @@ test_expect_success 'add -n -u should not add but just report' '
128
129
'
130
131
+test_expect_success 'add -u resolves unmerged paths' '
132
+ git reset --hard &&
133
+ one=$(echo 1 | git hash-object -w --stdin) &&
134
+ two=$(echo 2 | git hash-object -w --stdin) &&
135
+ three=$(echo 3 | git hash-object -w --stdin) &&
136
+ {
137
+ for path in path1 path2
138
+ do
139
+ echo "100644 $one 1 $path"
140
+ echo "100644 $two 2 $path"
141
+ echo "100644 $three 3 $path"
142
+ done
143
+ echo "100644 $one 1 path3"
144
+ echo "100644 $one 1 path4"
145
+ echo "100644 $one 3 path5"
146
+ echo "100644 $one 3 path6"
147
+ } |
148
+ git update-index --index-info &&
149
+ echo 3 >path1 &&
150
+ echo 2 >path3 &&
151
+ echo 2 >path5 &&
152
+ git add -u &&
153
+ git ls-files -s "path?" >actual &&
154
+ {
155
+ echo "100644 $three 0 path1"
156
+ echo "100644 $one 1 path3"
157
+ echo "100644 $one 1 path4"
158
+ echo "100644 $one 3 path5"
159
+ echo "100644 $one 3 path6"
160
+ } >expect &&
161
+ test_cmp expect actual &&
162
+
163
+ # Bonus tests. Explicit resolving
164
+ git add path3 path5 &&
165
+ test_must_fail git add path4 &&
166
+ test_must_fail git add path6 &&
167
+ git rm path4 &&
168
+ git rm path6 &&
169
+
170
+ git ls-files -s "path?" >actual &&
171
+ {
172
+ echo "100644 $three 0 path1"
173
+ echo "100644 $two 0 path3"
174
+ echo "100644 $two 0 path5"
175
+ } >expect
176
+
177
+'
178
+
179
test_done