Skip to content

Commit 49d833d

Browse files
committed
Revert "checkout branch: prime cache-tree fully"
The logic in 83ae209 (checkout branch: prime cache-tree fully, 2009-04-20) is bogus; checkout can switch branches with a dirty index and in such a case the tree won't match HEAD. Add t2014-switch to catch this breakage. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 83ae209 commit 49d833d

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

builtin-checkout.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -368,17 +368,14 @@ static int merge_working_tree(struct checkout_opts *opts,
368368
int ret;
369369
struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));
370370
int newfd = hold_locked_index(lock_file, 1);
371-
int reprime_cache_tree = 0;
372371

373372
if (read_cache() < 0)
374373
return error("corrupt index file");
375374

376-
cache_tree_free(&active_cache_tree);
377375
if (opts->force) {
378376
ret = reset_tree(new->commit->tree, opts, 1);
379377
if (ret)
380378
return ret;
381-
reprime_cache_tree = 1;
382379
} else {
383380
struct tree_desc trees[2];
384381
struct tree *tree;
@@ -414,9 +411,7 @@ static int merge_working_tree(struct checkout_opts *opts,
414411
init_tree_desc(&trees[1], tree->buffer, tree->size);
415412

416413
ret = unpack_trees(2, trees, &topts);
417-
if (ret != -1) {
418-
reprime_cache_tree = 1;
419-
} else {
414+
if (ret == -1) {
420415
/*
421416
* Unpack couldn't do a trivial merge; either
422417
* give up or do a real merge, depending on
@@ -460,8 +455,6 @@ static int merge_working_tree(struct checkout_opts *opts,
460455
}
461456
}
462457

463-
if (reprime_cache_tree)
464-
prime_cache_tree(&active_cache_tree, new->commit->tree);
465458
if (write_cache(newfd, active_cache, active_nr) ||
466459
commit_locked_index(lock_file))
467460
die("unable to write new index file");

t/t2014-switch.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
3+
test_description='Peter MacMillan'
4+
. ./test-lib.sh
5+
6+
test_expect_success setup '
7+
echo Hello >file &&
8+
git add file &&
9+
test_tick &&
10+
git commit -m V1 &&
11+
echo Hello world >file &&
12+
git add file &&
13+
git checkout -b other
14+
'
15+
16+
test_expect_success 'check all changes are staged' '
17+
git diff --exit-code
18+
'
19+
20+
test_expect_success 'second commit' '
21+
git commit -m V2
22+
'
23+
24+
test_expect_success 'check' '
25+
git diff --cached --exit-code
26+
'
27+
28+
test_done

0 commit comments

Comments
 (0)