Skip to content

Commit 6c52ec8

Browse files
trastgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 11c8a74 commit 6c52ec8

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

builtin/reset.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ static int reset_index_file(const unsigned char *sha1, int reset_type, int quiet
4343
int nr = 1;
4444
int newfd;
4545
struct tree_desc desc[2];
46+
struct tree *tree;
4647
struct unpack_trees_options opts;
4748
struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
4849

@@ -84,6 +85,12 @@ static int reset_index_file(const unsigned char *sha1, int reset_type, int quiet
8485
return error(_("Failed to find tree of %s."), sha1_to_hex(sha1));
8586
if (unpack_trees(nr, desc, &opts))
8687
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+
8794
if (write_cache(newfd, active_cache, active_nr) ||
8895
commit_locked_index(lock))
8996
return error(_("Could not write new index file."));

t/t0090-cache-tree.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ test_expect_success 'second commit has cache-tree' '
7575
test_shallow_cache_tree
7676
'
7777

78-
test_expect_failure 'reset --hard gives cache-tree' '
78+
test_expect_success 'reset --hard gives cache-tree' '
7979
test-scrap-cache-tree &&
8080
git reset --hard &&
8181
test_shallow_cache_tree
8282
'
8383

84-
test_expect_failure 'reset --hard without index gives cache-tree' '
84+
test_expect_success 'reset --hard without index gives cache-tree' '
8585
rm -f .git/index &&
8686
git reset --hard &&
8787
test_shallow_cache_tree

0 commit comments

Comments
 (0)