reset: update cache-tree data when appropriate
In the case of --mixed and --hard, we throw away the old index and rebuild everything from the tree argument (or HEAD). So we have an opportunity here to fill in the cache-tree data, just as read-tree did. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Thomas Rast committed
Dec 6, 2011 at 18:43 UTC
6c52ec8a9ab48b50fc8bf9559467d5a4cf7eee3b
2 files changed
+9
-2
builtin/reset.c
+7
@@ -43,6 +43,7 @@ static int reset_index_file(const unsigned char *sha1, int reset_type, int quiet
43
int nr = 1;
44
int newfd;
45
struct tree_desc desc[2];
46
+ struct tree *tree;
47
struct unpack_trees_options opts;
48
struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
49
@@ -84,6 +85,12 @@ static int reset_index_file(const unsigned char *sha1, int reset_type, int quiet
85
return error(_("Failed to find tree of %s."), sha1_to_hex(sha1));
86
if (unpack_trees(nr, desc, &opts))
87
return -1;
88
+
89
+ if (reset_type == MIXED || reset_type == HARD) {
90
+ tree = parse_tree_indirect(sha1);
91
+ prime_cache_tree(&active_cache_tree, tree);
92
+ }
93
+
94
if (write_cache(newfd, active_cache, active_nr) ||
95
commit_locked_index(lock))
96
return error(_("Could not write new index file."));
t/t0090-cache-tree.sh
+2
-2
@@ -75,13 +75,13 @@ test_expect_success 'second commit has cache-tree' '
75
test_shallow_cache_tree
76
'
77
78
-test_expect_failure 'reset --hard gives cache-tree' '
78
+test_expect_success 'reset --hard gives cache-tree' '
79
test-scrap-cache-tree &&
80
git reset --hard &&
81
test_shallow_cache_tree
82
'
83
84
-test_expect_failure 'reset --hard without index gives cache-tree' '
84
+test_expect_success 'reset --hard without index gives cache-tree' '
85
rm -f .git/index &&
86
git reset --hard &&
87
test_shallow_cache_tree