Fix "git add -u" data corruption.
This applies to 'maint' to fix a rather serious data corruption issue. When "git add -u" affects a subdirectory in such a way that the only changes to its contents are path removals, the next tree object written out of that index was bogus, as the remove codepath forgot to invalidate the cache-tree entry. Reported by Salikh Zakirov. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Aug 15, 2007 at 14:12 UTC
a4882c27f8b3793d94b03fd503a0c67ad9772cf6
2 files changed
+44
-16
builtin-add.c
+1
@@ -115,6 +115,7 @@ static void update_callback(struct diff_queue_struct *q,
115
break;
116
case DIFF_STATUS_DELETED:
117
remove_file_from_cache(path);
118
+ cache_tree_invalidate_path(active_cache_tree, path);
119
if (verbose)
120
printf("remove '%s'\n", path);
121
break;
t/t2200-add-update.sh
+43
-16
@@ -13,26 +13,53 @@ only the updates to dir/sub.'
13
14
. ./test-lib.sh
15
16
-test_expect_success 'setup' '
17
-echo initial >top &&
18
-mkdir dir &&
19
-echo initial >dir/sub &&
20
-git-add dir/sub top &&
21
-git-commit -m initial &&
22
-echo changed >top &&
23
-echo changed >dir/sub &&
24
-echo other >dir/other
16
+test_expect_success setup '
17
+ echo initial >check &&
18
+ echo initial >top &&
19
+ mkdir dir1 dir2 &&
20
+ echo initial >dir1/sub1 &&
21
+ echo initial >dir1/sub2 &&
22
+ echo initial >dir2/sub3 &&
23
+ git add check dir1 dir2 top &&
24
+ test_tick
25
+ git-commit -m initial &&
26
+
27
+ echo changed >check &&
28
+ echo changed >top &&
29
+ echo changed >dir2/sub3 &&
30
+ rm -f dir1/sub1 &&
31
+ echo other >dir2/other
32
+'
33
+
34
+test_expect_success update '
35
+ git add -u dir1 dir2
36
'
37
27
-test_expect_success 'update' 'git-add -u dir'
38
+test_expect_success 'update noticed a removal' '
39
+ test "$(git-ls-files dir1/sub1)" = ""
40
+'
41
29
-test_expect_success 'update touched correct path' \
30
- 'test "`git-diff-files --name-status dir/sub`" = ""'
42
+test_expect_success 'update touched correct path' '
43
+ test "$(git-diff-files --name-status dir2/sub3)" = ""
44
+'
45
32
-test_expect_success 'update did not touch other tracked files' \
33
- 'test "`git-diff-files --name-status top`" = "M top"'
46
+test_expect_success 'update did not touch other tracked files' '
47
+ test "$(git-diff-files --name-status check)" = "M check" &&
48
+ test "$(git-diff-files --name-status top)" = "M top"
49
+'
50
35
-test_expect_success 'update did not touch untracked files' \
36
- 'test "`git-diff-files --name-status dir/other`" = ""'
51
+test_expect_success 'update did not touch untracked files' '
52
+ test "$(git-ls-files dir2/other)" = ""
53
+'
54
+
55
+test_expect_success 'cache tree has not been corrupted' '
56
+
57
+ git ls-files -s |
58
+ sed -e "s/ 0 / /" >expect &&
59
+ git ls-tree -r $(git write-tree) |
60
+ sed -e "s/ blob / /" >current &&
61
+ diff -u expect current
62
+
63
+'
64
65
test_done