[PATCH] Redo rename/copy detection logic.
[git/git.git] / t / t4005-diff-rename-2.sh
CommitLineData
f7c1512a
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
6test_description='Same rename detection as t4003 but testing diff-raw.
7
8'
9. ./test-lib.sh
10
b6d8f309
JH
11compare_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
17}
18
19compare_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
25}
26
f7c1512a
JH
27test_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'
34
35test_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.?'
41
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.
46
47git-diff-cache -M $tree >current
48
49cat >expected <<\EOF
b6d8f309
JH
50:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0603b3238a076dc6c8022aedc6648fa523a17178 C1234 COPYING COPYING.1
51:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 06c67961bbaed34a127f76d261f4c0bf73eda471 R1234 COPYING COPYING.2
f7c1512a
JH
52EOF
53
54test_expect_success \
b6d8f309
JH
55 'validate output from rename/copy detection (#1)' \
56 'compare_diff_raw current expected'
57
58# make sure diff-helper can grok it.
59mv expected diff-raw
60GIT_DIFF_OPTS=--unified=0 git-diff-helper <diff-raw >current
61cat >expected <<\EOF
62diff --git a/COPYING b/COPYING.1
63copy from COPYING
64copy 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
70diff --git a/COPYING b/COPYING.2
71rename old COPYING
72rename 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
84EOF
85
86test_expect_success \
87 'validate output from diff-helper (#1)' \
88 'compare_diff_patch current expected'
89
90################################################################
f7c1512a
JH
91
92test_expect_success \
93 'prepare work tree again' \
94 'mv COPYING.2 COPYING &&
95 git-update-cache --add --remove COPYING COPYING.1 COPYING.2'
96
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.
101
102git-diff-cache -C $tree >current
103cat >expected <<\EOF
b6d8f309 104:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 06c67961bbaed34a127f76d261f4c0bf73eda471 M COPYING
25d5ea41 105:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0603b3238a076dc6c8022aedc6648fa523a17178 C1234 COPYING COPYING.1
f7c1512a
JH
106EOF
107
108test_expect_success \
b6d8f309
JH
109 'validate output from rename/copy detection (#2)' \
110 'compare_diff_raw current expected'
f7c1512a
JH
111
112test_expect_success \
113 'prepare work tree once again' \
114 'cat ../../COPYING >COPYING &&
115 git-update-cache --add --remove COPYING COPYING.1'
116
b6d8f309
JH
117# make sure diff-helper can grok it.
118mv expected diff-raw
119GIT_DIFF_OPTS=--unified=0 git-diff-helper <diff-raw >current
120cat >expected <<\EOF
b6d8f309
JH
121diff --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
25d5ea41
JH
133diff --git a/COPYING b/COPYING.1
134copy from COPYING
135copy 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
b6d8f309
JH
141EOF
142
143test_expect_success \
144 'validate output from diff-helper (#2)' \
145 'compare_diff_patch current expected'
146
147################################################################
148
f7c1512a 149# tree has COPYING and rezrov. work tree has the same COPYING and
bceafe75
JH
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.
f7c1512a
JH
153
154git-diff-cache -C $tree >current
155cat >expected <<\EOF
b6d8f309 156:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0603b3238a076dc6c8022aedc6648fa523a17178 C1234 COPYING COPYING.1
b6d8f309
JH
157EOF
158
159test_expect_success \
160 'validate output from rename/copy detection (#3)' \
161 'compare_diff_raw current expected'
162
163# make sure diff-helper can grok it.
164mv expected diff-raw
165GIT_DIFF_OPTS=--unified=0 git-diff-helper <diff-raw >current
166cat >expected <<\EOF
167diff --git a/COPYING b/COPYING.1
168copy from COPYING
169copy 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
f7c1512a
JH
175EOF
176
177test_expect_success \
b6d8f309
JH
178 'validate output from diff-helper (#3)' \
179 'compare_diff_patch current expected'
f7c1512a
JH
180
181test_done