@matheusbsbs / matheus-bagliano / commits / f5ed3b30e0
Fork 0

git-reset --hard and git-read-tree --reset: fix read_cache_unmerged()

When invalidating unmerged entries in the index, we used to set their ce_mode to 0 to note the fact that they do not matter anymore which also made sure that later unpack_trees() call would not reuse them. Instead just remove them from the index. Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Feb 21, 2008 at 11:33 UTC f5ed3b30e0091421408a0119fa75148955c4fc6a
2 files changed +47 -1
builtin-read-tree.c
+1 -1
@@ -45,7 +45,7 @@ static int read_cache_unmerged(void)
45 continue;
46 cache_tree_invalidate_path(active_cache_tree, ce->name);
47 last = ce;
48 - ce->ce_flags |= CE_REMOVE;
48 + continue;
49 }
50 *dst++ = ce;
51 }
t/t7104-reset.sh new
+46
@@ -0,0 +1,46 @@
1 +#!/bin/sh
2 +
3 +test_description='reset --hard unmerged'
4 +
5 +. ./test-lib.sh
6 +
7 +test_expect_success setup '
8 +
9 + mkdir before later &&
10 + >before/1 &&
11 + >before/2 &&
12 + >hello &&
13 + >later/3 &&
14 + git add before hello later &&
15 + git commit -m world &&
16 +
17 + H=$(git rev-parse :hello) &&
18 + git rm --cached hello &&
19 + echo "100644 $H 2 hello" | git update-index --index-info &&
20 +
21 + rm -f hello &&
22 + mkdir -p hello &&
23 + >hello/world &&
24 + test "$(git ls-files -o)" = hello/world
25 +
26 +'
27 +
28 +test_expect_success 'reset --hard should restore unmerged ones' '
29 +
30 + git reset --hard &&
31 + git ls-files --error-unmatch before/1 before/2 hello later/3 &&
32 + test -f hello
33 +
34 +'
35 +
36 +test_expect_success 'reset --hard did not corrupt index nor cached-tree' '
37 +
38 + T=$(git write-tree) &&
39 + rm -f .git/index &&
40 + git add before hello later &&
41 + U=$(git write-tree) &&
42 + test "$T" = "$U"
43 +
44 +'
45 +
46 +test_done