Raw
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Junio C Hamano
4 #
5
6 test_description='Rename interaction with pathspec.
7
8 '
9
10 . ./test-lib.sh
11 . "$TEST_DIRECTORY"/lib-diff.sh ;# test-lib chdir's into trash
12
13 test_expect_success 'prepare reference tree' '
14 mkdir path0 path1 &&
15 COPYING_test_data >path0/COPYING &&
16 git update-index --add path0/COPYING &&
17 tree=$(git write-tree) &&
18 blob=$(git rev-parse :path0/COPYING)
19 '
20
21 test_expect_success 'prepare work tree' '
22 cp path0/COPYING path1/COPYING &&
23 git update-index --add --remove path0/COPYING path1/COPYING
24 '
25
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.
29
30 cat >expected <<EOF
31 :100644 100644 $blob $blob C100 path0/COPYING path1/COPYING
32 EOF
33
34 test_expect_success 'copy detection' '
35 git diff-index -C --find-copies-harder $tree >current &&
36 compare_diff_raw current expected
37 '
38
39 test_expect_success 'copy detection, cached' '
40 git diff-index -C --find-copies-harder --cached $tree >current &&
41 compare_diff_raw current expected
42 '
43
44 test_expect_success 'exit code of quiet copy detection' '
45 test_expect_code 1 \
46 git diff --quiet --cached --find-copies-harder $tree
47 '
48
49 test_expect_success 'exit code of quiet copy detection with --no-ext-diff' '
50 test_expect_code 1 \
51 git diff --quiet --cached --find-copies-harder --no-ext-diff $tree
52 '
53
54 # In the tree, there is only path0/COPYING. In the cache, path0 and
55 # path1 both have COPYING and the latter is a copy of path0/COPYING.
56 # However when we say we care only about path1, we should just see
57 # path1/COPYING suddenly appearing from nowhere, not detected as
58 # a copy from path0/COPYING.
59
60 cat >expected <<EOF
61 :000000 100644 $ZERO_OID $blob A path1/COPYING
62 EOF
63
64 test_expect_success 'copy, limited to a subtree' '
65 git diff-index -C --find-copies-harder $tree path1 >current &&
66 compare_diff_raw current expected
67 '
68
69 test_expect_success 'tweak work tree' '
70 rm -f path0/COPYING
71 '
72
73 cat >expected <<EOF
74 :100644 100644 $blob $blob C100 path1/COPYING path0/COPYING
75 EOF
76
77 # The cache has path0/COPYING and path1/COPYING, the working tree only
78 # path1/COPYING. This is a deletion -- we don't treat deduplication
79 # specially. In reverse it should be detected as a copy, though.
80 test_expect_success 'copy detection, files to index' '
81 git diff-files -C --find-copies-harder -R >current &&
82 compare_diff_raw current expected
83 '
84
85 test_expect_success 'copy detection, files to preloaded index' '
86 GIT_TEST_PRELOAD_INDEX=1 \
87 git diff-files -C --find-copies-harder -R >current &&
88 compare_diff_raw current expected
89 '
90
91 test_expect_success 'tweak index' '
92 git update-index --remove path0/COPYING
93 '
94 # In the tree, there is only path0/COPYING. In the cache, path0 does
95 # not have COPYING anymore and path1 has COPYING which is a copy of
96 # path0/COPYING. Showing the full tree with cache should tell us about
97 # the rename.
98
99 cat >expected <<EOF
100 :100644 100644 $blob $blob R100 path0/COPYING path1/COPYING
101 EOF
102
103 test_expect_success 'rename detection' '
104 git diff-index -C --find-copies-harder $tree >current &&
105 compare_diff_raw current expected
106 '
107
108 # In the tree, there is only path0/COPYING. In the cache, path0 does
109 # not have COPYING anymore and path1 has COPYING which is a copy of
110 # path0/COPYING. When we say we care only about path1, we should just
111 # see path1/COPYING appearing from nowhere.
112
113 cat >expected <<EOF
114 :000000 100644 $ZERO_OID $blob A path1/COPYING
115 EOF
116
117 test_expect_success 'rename, limited to a subtree' '
118 git diff-index -C --find-copies-harder $tree path1 >current &&
119 compare_diff_raw current expected
120 '
121
122 test_done