]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4005-diff-rename-2.sh
git-apply: start using the index file information.
[thirdparty/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
JH
104:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0603b3238a076dc6c8022aedc6648fa523a17178 C1234 COPYING COPYING.1
105:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 06c67961bbaed34a127f76d261f4c0bf73eda471 M COPYING
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
121diff --git a/COPYING b/COPYING.1
122copy from COPYING
123copy 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
129diff --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
141EOF
142
143test_expect_success \
144 'validate output from diff-helper (#2)' \
145 'compare_diff_patch current expected'
146
147################################################################
148
f7c1512a
JH
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.
153
154git-diff-cache -C $tree >current
155cat >expected <<\EOF
b6d8f309
JH
156:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0603b3238a076dc6c8022aedc6648fa523a17178 C1234 COPYING COPYING.1
157:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 6ff87c4664981e4397625791c8ea3bbb5f2279a3 M COPYING
158EOF
159
160test_expect_success \
161 'validate output from rename/copy detection (#3)' \
162 'compare_diff_raw current expected'
163
164# make sure diff-helper can grok it.
165mv expected diff-raw
166GIT_DIFF_OPTS=--unified=0 git-diff-helper <diff-raw >current
167cat >expected <<\EOF
168diff --git a/COPYING b/COPYING.1
169copy from COPYING
170copy 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
f7c1512a
JH
176EOF
177
178test_expect_success \
b6d8f309
JH
179 'validate output from diff-helper (#3)' \
180 'compare_diff_patch current expected'
f7c1512a
JH
181
182test_done