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

Fix "read-tree -m A B" priming the cache-tree

In 456156d a shortcut to priming the index tree reference was introduced, but the justification for it was completely bogus. "read-tree -m A B" is to take the index (and the working tree) that is largely based on (but does not have to match exactly) A and update it to B, while carrying the local change that does not overlap the difference between A and B, so there is no reason to expect that the resulting index should match the tree B. Noticed and test provided by Heiko Voigt. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jul 8, 2010 at 17:27 UTC b1f47514f207b0601de7b0936cf13b3c0ae70081
2 files changed +16 -5
builtin-read-tree.c
-5
@@ -199,14 +199,9 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
199 * "-m ent" or "--reset ent" form), we can obtain a fully
200 * valid cache-tree because the index must match exactly
201 * what came from the tree.
202 - *
203 - * The same holds true if we are switching between two trees
204 - * using read-tree -m A B. The index must match B after that.
202 */
203 if (nr_trees == 1 && !opts.prefix)
204 prime_cache_tree(&active_cache_tree, trees[0]);
208 - else if (nr_trees == 2 && opts.merge)
209 - prime_cache_tree(&active_cache_tree, trees[1]);
205
206 if (write_cache(newfd, active_cache, active_nr) ||
207 commit_locked_index(&lock_file))
t/t1001-read-tree-m-2way.sh
+16
@@ -392,4 +392,20 @@ test_expect_success \
392 git ls-files --stage | tee >treeMcheck.out &&
393 test_cmp treeM.out treeMcheck.out'
394
395 +test_expect_success '-m references the correct modified tree' '
396 + echo >file-a &&
397 + echo >file-b &&
398 + git add file-a file-b &&
399 + git commit -a -m "test for correct modified tree"
400 + git branch initial-mod &&
401 + echo b >file-b &&
402 + git commit -a -m "B" &&
403 + echo a >file-a &&
404 + git add file-a &&
405 + git ls-tree $(git write-tree) file-a >expect &&
406 + git read-tree -m HEAD initial-mod &&
407 + git ls-tree $(git write-tree) file-a >actual &&
408 + test_cmp expect actual
409 +'
410 +
411 test_done