git-init-db: set up the full default environment
[git.git] / t / t4005-diff-rename-2.sh
bloba51985518251f6c3f677438c3cb51b9716c20296
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='Same rename detection as t4003 but testing diff-raw.
9 . ./test-lib.sh
11 compare_diff_raw () {
12 # When heuristics are improved, the score numbers would change.
13 # Ignore them while comparing.
14 sed -e 's/ \([CR]\)[0-9]* /\1#/' <"$1" >.tmp-1
15 sed -e 's/ \([CR]\)[0-9]* /\1#/' <"$2" >.tmp-2
16 diff -u .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2
19 compare_diff_patch () {
20 # When heuristics are improved, the score numbers would change.
21 # Ignore them while comparing.
22 sed -e '/^similarity index [0-9]*%$/d' <"$1" >.tmp-1
23 sed -e '/^similarity index [0-9]*%$/d' <"$2" >.tmp-2
24 diff -u .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2
27 test_expect_success \
28 'prepare reference tree' \
29 'cat ../../COPYING >COPYING &&
30 echo frotz >rezrov &&
31 git-update-cache --add COPYING rezrov &&
32 tree=$(git-write-tree) &&
33 echo $tree'
35 test_expect_success \
36 'prepare work tree' \
37 'sed -e 's/HOWEVER/However/' <COPYING >COPYING.1 &&
38 sed -e 's/GPL/G.P.L/g' <COPYING >COPYING.2 &&
39 rm -f COPYING &&
40 git-update-cache --add --remove COPYING COPYING.?'
42 # tree has COPYING and rezrov. work tree has COPYING.1 and COPYING.2,
43 # both are slightly edited, and unchanged rezrov. We say COPYING.1
44 # and COPYING.2 are based on COPYING, and do not say anything about
45 # rezrov.
47 git-diff-cache -M $tree >current
49 cat >expected <<\EOF
50 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0603b3238a076dc6c8022aedc6648fa523a17178 C1234 COPYING COPYING.1
51 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 06c67961bbaed34a127f76d261f4c0bf73eda471 R1234 COPYING COPYING.2
52 EOF
54 test_expect_success \
55 'validate output from rename/copy detection (#1)' \
56 'compare_diff_raw current expected'
58 # make sure diff-helper can grok it.
59 mv expected diff-raw
60 GIT_DIFF_OPTS=--unified=0 git-diff-helper <diff-raw >current
61 cat >expected <<\EOF
62 diff --git a/COPYING b/COPYING.1
63 copy from COPYING
64 copy to COPYING.1
65 --- a/COPYING
66 +++ b/COPYING.1
67 @@ -6 +6 @@
68 - HOWEVER, in order to allow a migration to GPLv3 if that seems like
69 + However, in order to allow a migration to GPLv3 if that seems like
70 diff --git a/COPYING b/COPYING.2
71 rename old COPYING
72 rename new COPYING.2
73 --- a/COPYING
74 +++ b/COPYING.2
75 @@ -2 +2 @@
76 - Note that the only valid version of the GPL as far as this project
77 + Note that the only valid version of the G.P.L as far as this project
78 @@ -6 +6 @@
79 - HOWEVER, in order to allow a migration to GPLv3 if that seems like
80 + HOWEVER, in order to allow a migration to G.P.Lv3 if that seems like
81 @@ -12 +12 @@
82 - This file is licensed under the GPL v2, or a later version
83 + This file is licensed under the G.P.L v2, or a later version
84 EOF
86 test_expect_success \
87 'validate output from diff-helper (#1)' \
88 'compare_diff_patch current expected'
90 ################################################################
92 test_expect_success \
93 'prepare work tree again' \
94 'mv COPYING.2 COPYING &&
95 git-update-cache --add --remove COPYING COPYING.1 COPYING.2'
97 # tree has COPYING and rezrov. work tree has COPYING and COPYING.1,
98 # both are slightly edited, and unchanged rezrov. We say COPYING.1
99 # is based on COPYING and COPYING is still there, and do not say anything
100 # about rezrov.
102 git-diff-cache -C $tree >current
103 cat >expected <<\EOF
104 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 06c67961bbaed34a127f76d261f4c0bf73eda471 M COPYING
105 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0603b3238a076dc6c8022aedc6648fa523a17178 C1234 COPYING COPYING.1
108 test_expect_success \
109 'validate output from rename/copy detection (#2)' \
110 'compare_diff_raw current expected'
112 test_expect_success \
113 'prepare work tree once again' \
114 'cat ../../COPYING >COPYING &&
115 git-update-cache --add --remove COPYING COPYING.1'
117 # make sure diff-helper can grok it.
118 mv expected diff-raw
119 GIT_DIFF_OPTS=--unified=0 git-diff-helper <diff-raw >current
120 cat >expected <<\EOF
121 diff --git a/COPYING b/COPYING
122 --- a/COPYING
123 +++ b/COPYING
124 @@ -2 +2 @@
125 - Note that the only valid version of the GPL as far as this project
126 + Note that the only valid version of the G.P.L as far as this project
127 @@ -6 +6 @@
128 - HOWEVER, in order to allow a migration to GPLv3 if that seems like
129 + HOWEVER, in order to allow a migration to G.P.Lv3 if that seems like
130 @@ -12 +12 @@
131 - This file is licensed under the GPL v2, or a later version
132 + This file is licensed under the G.P.L v2, or a later version
133 diff --git a/COPYING b/COPYING.1
134 copy from COPYING
135 copy to COPYING.1
136 --- a/COPYING
137 +++ b/COPYING.1
138 @@ -6 +6 @@
139 - HOWEVER, in order to allow a migration to GPLv3 if that seems like
140 + However, in order to allow a migration to GPLv3 if that seems like
143 test_expect_success \
144 'validate output from diff-helper (#2)' \
145 'compare_diff_patch current expected'
147 ################################################################
149 # tree has COPYING and rezrov. work tree has the same COPYING and
150 # copy-edited COPYING.1, and unchanged rezrov. We should not say
151 # anything about rezrov nor COPYING, since the revised again diff-raw
152 # nows how to say Copy.
154 git-diff-cache -C $tree >current
155 cat >expected <<\EOF
156 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0603b3238a076dc6c8022aedc6648fa523a17178 C1234 COPYING COPYING.1
159 test_expect_success \
160 'validate output from rename/copy detection (#3)' \
161 'compare_diff_raw current expected'
163 # make sure diff-helper can grok it.
164 mv expected diff-raw
165 GIT_DIFF_OPTS=--unified=0 git-diff-helper <diff-raw >current
166 cat >expected <<\EOF
167 diff --git a/COPYING b/COPYING.1
168 copy from COPYING
169 copy to COPYING.1
170 --- a/COPYING
171 +++ b/COPYING.1
172 @@ -6 +6 @@
173 - HOWEVER, in order to allow a migration to GPLv3 if that seems like
174 + However, in order to allow a migration to GPLv3 if that seems like
177 test_expect_success \
178 'validate output from diff-helper (#3)' \
179 'compare_diff_patch current expected'
181 test_done