Skip to content

Commit c9a9766

Browse files
committed
Merge branch 'jc/read-tree-cache-tree-fix'
* jc/read-tree-cache-tree-fix: Fix "read-tree -m A B" priming the cache-tree
2 parents c7d1d1b + 037c43c commit c9a9766

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

builtin/read-tree.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,9 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
219219
* "-m ent" or "--reset ent" form), we can obtain a fully
220220
* valid cache-tree because the index must match exactly
221221
* what came from the tree.
222-
*
223-
* The same holds true if we are switching between two trees
224-
* using read-tree -m A B. The index must match B after that.
225222
*/
226223
if (nr_trees == 1 && !opts.prefix)
227224
prime_cache_tree(&active_cache_tree, trees[0]);
228-
else if (nr_trees == 2 && opts.merge)
229-
prime_cache_tree(&active_cache_tree, trees[1]);
230225

231226
if (write_cache(newfd, active_cache, active_nr) ||
232227
commit_locked_index(&lock_file))

t/t1001-read-tree-m-2way.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,4 +390,20 @@ test_expect_success \
390390
git ls-files --stage | tee >treeMcheck.out &&
391391
test_cmp treeM.out treeMcheck.out'
392392

393+
test_expect_success '-m references the correct modified tree' '
394+
echo >file-a &&
395+
echo >file-b &&
396+
git add file-a file-b &&
397+
git commit -a -m "test for correct modified tree"
398+
git branch initial-mod &&
399+
echo b >file-b &&
400+
git commit -a -m "B" &&
401+
echo a >file-a &&
402+
git add file-a &&
403+
git ls-tree $(git write-tree) file-a >expect &&
404+
git read-tree -m HEAD initial-mod &&
405+
git ls-tree $(git write-tree) file-a >actual &&
406+
test_cmp expect actual
407+
'
408+
393409
test_done

0 commit comments

Comments
 (0)