[PATCH] diff-raw format update take #2.
[git/dscho.git] / t / t4005-diff-rename-2.sh
blob2009aec88cf00449c4b670d088ab7b0ecfe25d90
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 0603b3238a076dc6c8022aedc6648fa523a17178 C1234 COPYING COPYING.1
105 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 06c67961bbaed34a127f76d261f4c0bf73eda471 M COPYING
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.1
122 copy from COPYING
123 copy to COPYING.1
124 --- a/COPYING
125 +++ b/COPYING.1
126 @@ -6 +6 @@
127 - HOWEVER, in order to allow a migration to GPLv3 if that seems like
128 + However, in order to allow a migration to GPLv3 if that seems like
129 diff --git a/COPYING b/COPYING
130 --- a/COPYING
131 +++ b/COPYING
132 @@ -2 +2 @@
133 - Note that the only valid version of the GPL as far as this project
134 + Note that the only valid version of the G.P.L as far as this project
135 @@ -6 +6 @@
136 - HOWEVER, in order to allow a migration to GPLv3 if that seems like
137 + HOWEVER, in order to allow a migration to G.P.Lv3 if that seems like
138 @@ -12 +12 @@
139 - This file is licensed under the GPL v2, or a later version
140 + This file is licensed under the G.P.L v2, or a later version
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 see
151 # unmodified COPYING in the output, so that downstream diff-helper can
152 # notice. We should not say anything about rezrov.
154 git-diff-cache -C $tree >current
155 cat >expected <<\EOF
156 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0603b3238a076dc6c8022aedc6648fa523a17178 C1234 COPYING COPYING.1
157 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 6ff87c4664981e4397625791c8ea3bbb5f2279a3 M COPYING
160 test_expect_success \
161 'validate output from rename/copy detection (#3)' \
162 'compare_diff_raw current expected'
164 # make sure diff-helper can grok it.
165 mv expected diff-raw
166 GIT_DIFF_OPTS=--unified=0 git-diff-helper <diff-raw >current
167 cat >expected <<\EOF
168 diff --git a/COPYING b/COPYING.1
169 copy from COPYING
170 copy to COPYING.1
171 --- a/COPYING
172 +++ b/COPYING.1
173 @@ -6 +6 @@
174 - HOWEVER, in order to allow a migration to GPLv3 if that seems like
175 + However, in order to allow a migration to GPLv3 if that seems like
178 test_expect_success \
179 'validate output from diff-helper (#3)' \
180 'compare_diff_patch current expected'
182 test_done