Seventh batch for 2.20
[git/debian.git] / t / t4007-rename-3.sh
blobb187b7f6c66b8ade9d0ef73aa346a9205df153bc
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='Rename interaction with pathspec.
9 . ./test-lib.sh
10 . "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
12 test_expect_success 'prepare reference tree' '
13 mkdir path0 path1 &&
14 cp "$TEST_DIRECTORY"/diff-lib/COPYING path0/COPYING &&
15 git update-index --add path0/COPYING &&
16 tree=$(git write-tree) &&
17 echo $tree
20 blob=$(git hash-object "$TEST_DIRECTORY/diff-lib/COPYING")
21 test_expect_success 'prepare work tree' '
22 cp path0/COPYING path1/COPYING &&
23 git update-index --add --remove path0/COPYING path1/COPYING
26 # In the tree, there is only path0/COPYING. In the cache, path0 and
27 # path1 both have COPYING and the latter is a copy of path0/COPYING.
28 # Comparing the full tree with cache should tell us so.
30 cat >expected <<EOF
31 :100644 100644 $blob $blob C100 path0/COPYING path1/COPYING
32 EOF
34 test_expect_success 'copy detection' '
35 git diff-index -C --find-copies-harder $tree >current &&
36 compare_diff_raw current expected
39 test_expect_success 'copy detection, cached' '
40 git diff-index -C --find-copies-harder --cached $tree >current &&
41 compare_diff_raw current expected
44 # In the tree, there is only path0/COPYING. In the cache, path0 and
45 # path1 both have COPYING and the latter is a copy of path0/COPYING.
46 # However when we say we care only about path1, we should just see
47 # path1/COPYING suddenly appearing from nowhere, not detected as
48 # a copy from path0/COPYING.
50 cat >expected <<EOF
51 :000000 100644 $ZERO_OID $blob A path1/COPYING
52 EOF
54 test_expect_success 'copy, limited to a subtree' '
55 git diff-index -C --find-copies-harder $tree path1 >current &&
56 compare_diff_raw current expected
59 test_expect_success 'tweak work tree' '
60 rm -f path0/COPYING &&
61 git update-index --remove path0/COPYING
63 # In the tree, there is only path0/COPYING. In the cache, path0 does
64 # not have COPYING anymore and path1 has COPYING which is a copy of
65 # path0/COPYING. Showing the full tree with cache should tell us about
66 # the rename.
68 cat >expected <<EOF
69 :100644 100644 $blob $blob R100 path0/COPYING path1/COPYING
70 EOF
72 test_expect_success 'rename detection' '
73 git diff-index -C --find-copies-harder $tree >current &&
74 compare_diff_raw current expected
77 # In the tree, there is only path0/COPYING. In the cache, path0 does
78 # not have COPYING anymore and path1 has COPYING which is a copy of
79 # path0/COPYING. When we say we care only about path1, we should just
80 # see path1/COPYING appearing from nowhere.
82 cat >expected <<EOF
83 :000000 100644 $ZERO_OID $blob A path1/COPYING
84 EOF
86 test_expect_success 'rename, limited to a subtree' '
87 git diff-index -C --find-copies-harder $tree path1 >current &&
88 compare_diff_raw current expected
91 test_done