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 <gitster@pobox.com>
Junio C Hamano committed
May 12, 2009 at 09:41 UTC
49d833dc07f28bf67119c4060044fc829a7e044f
2 files changed
+29
-8
builtin-checkout.c
+1
-8
@@ -368,17 +368,14 @@ static int merge_working_tree(struct checkout_opts *opts,
368
int ret;
369
struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));
370
int newfd = hold_locked_index(lock_file, 1);
371
- int reprime_cache_tree = 0;
371
372
if (read_cache() < 0)
373
return error("corrupt index file");
374
376
- cache_tree_free(&active_cache_tree);
375
if (opts->force) {
376
ret = reset_tree(new->commit->tree, opts, 1);
377
if (ret)
378
return ret;
381
- reprime_cache_tree = 1;
379
} else {
380
struct tree_desc trees[2];
381
struct tree *tree;
@@ -414,9 +411,7 @@ static int merge_working_tree(struct checkout_opts *opts,
411
init_tree_desc(&trees[1], tree->buffer, tree->size);
412
413
ret = unpack_trees(2, trees, &topts);
417
- if (ret != -1) {
418
- reprime_cache_tree = 1;
419
- } else {
414
+ if (ret == -1) {
415
/*
416
* Unpack couldn't do a trivial merge; either
417
* give up or do a real merge, depending on
@@ -460,8 +455,6 @@ static int merge_working_tree(struct checkout_opts *opts,
455
}
456
}
457
463
- if (reprime_cache_tree)
464
- prime_cache_tree(&active_cache_tree, new->commit->tree);
458
if (write_cache(newfd, active_cache, active_nr) ||
459
commit_locked_index(lock_file))
460
die("unable to write new index file");
t/t2014-switch.sh
new
+28
@@ -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