]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4003-diff-rename-1.sh
git-apply: more consistency checks on gitdiff filenames
[thirdparty/git.git] / t / t4003-diff-rename-1.sh
CommitLineData
427dcb4b
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
6test_description='More rename detection
7
8'
9. ./test-lib.sh
10
b6d8f309
JH
11compare_diff_patch () {
12 # When heuristics are improved, the score numbers would change.
13 # Ignore them while comparing.
14 sed -e '/^similarity index [0-9]*%$/d' <"$1" >.tmp-1
15 sed -e '/^similarity index [0-9]*%$/d' <"$2" >.tmp-2
16 diff -u .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2
17}
18
427dcb4b
JH
19test_expect_success \
20 'prepare reference tree' \
21 'cat ../../COPYING >COPYING &&
f7c1512a
JH
22 echo frotz >rezrov &&
23 git-update-cache --add COPYING rezrov &&
427dcb4b
JH
24 tree=$(git-write-tree) &&
25 echo $tree'
26
27test_expect_success \
28 'prepare work tree' \
29 'sed -e 's/HOWEVER/However/' <COPYING >COPYING.1 &&
30 sed -e 's/GPL/G.P.L/g' <COPYING >COPYING.2 &&
31 rm -f COPYING &&
32 git-update-cache --add --remove COPYING COPYING.?'
33
f7c1512a
JH
34# tree has COPYING and rezrov. work tree has COPYING.1 and COPYING.2,
35# both are slightly edited, and unchanged rezrov. So we say you
36# copy-and-edit one, and rename-and-edit the other. We do not say
37# anything about rezrov.
c3e7fbcb 38
b6d8f309 39GIT_DIFF_OPTS=--unified=0 git-diff-cache -M -p $tree >current
427dcb4b 40cat >expected <<\EOF
b6d8f309 41diff --git a/COPYING b/COPYING.1
427dcb4b 42copy from COPYING
b6d8f309 43copy to COPYING.1
427dcb4b 44--- a/COPYING
b6d8f309
JH
45+++ b/COPYING.1
46@@ -6 +6 @@
47- HOWEVER, in order to allow a migration to GPLv3 if that seems like
48+ However, in order to allow a migration to GPLv3 if that seems like
49diff --git a/COPYING b/COPYING.2
427dcb4b 50rename old COPYING
b6d8f309 51rename new COPYING.2
427dcb4b 52--- a/COPYING
b6d8f309
JH
53+++ b/COPYING.2
54@@ -2 +2 @@
427dcb4b
JH
55- Note that the only valid version of the GPL as far as this project
56+ Note that the only valid version of the G.P.L as far as this project
b6d8f309
JH
57@@ -6 +6 @@
58- HOWEVER, in order to allow a migration to GPLv3 if that seems like
59+ HOWEVER, in order to allow a migration to G.P.Lv3 if that seems like
60@@ -12 +12 @@
61- This file is licensed under the GPL v2, or a later version
62+ This file is licensed under the G.P.L v2, or a later version
427dcb4b
JH
63EOF
64
65test_expect_success \
b6d8f309
JH
66 'validate output from rename/copy detection (#1)' \
67 'compare_diff_patch current expected'
427dcb4b
JH
68
69test_expect_success \
70 'prepare work tree again' \
71 'mv COPYING.2 COPYING &&
c3e7fbcb
JH
72 git-update-cache --add --remove COPYING COPYING.1 COPYING.2'
73
f7c1512a
JH
74# tree has COPYING and rezrov. work tree has COPYING and COPYING.1,
75# both are slightly edited, and unchanged rezrov. So we say you
76# edited one, and copy-and-edit the other. We do not say
77# anything about rezrov.
427dcb4b 78
b6d8f309 79GIT_DIFF_OPTS=--unified=0 git-diff-cache -C -p $tree >current
427dcb4b 80cat >expected <<\EOF
b6d8f309 81diff --git a/COPYING b/COPYING.1
427dcb4b 82copy from COPYING
b6d8f309 83copy to COPYING.1
427dcb4b 84--- a/COPYING
b6d8f309
JH
85+++ b/COPYING.1
86@@ -6 +6 @@
87- HOWEVER, in order to allow a migration to GPLv3 if that seems like
88+ However, in order to allow a migration to GPLv3 if that seems like
427dcb4b
JH
89diff --git a/COPYING b/COPYING
90--- a/COPYING
91+++ b/COPYING
b6d8f309 92@@ -2 +2 @@
427dcb4b
JH
93- Note that the only valid version of the GPL as far as this project
94+ Note that the only valid version of the G.P.L as far as this project
b6d8f309
JH
95@@ -6 +6 @@
96- HOWEVER, in order to allow a migration to GPLv3 if that seems like
97+ HOWEVER, in order to allow a migration to G.P.Lv3 if that seems like
98@@ -12 +12 @@
99- This file is licensed under the GPL v2, or a later version
100+ This file is licensed under the G.P.L v2, or a later version
427dcb4b
JH
101EOF
102
c3e7fbcb 103test_expect_success \
b6d8f309
JH
104 'validate output from rename/copy detection (#2)' \
105 'compare_diff_patch current expected'
c3e7fbcb
JH
106
107test_expect_success \
108 'prepare work tree once again' \
109 'cat ../../COPYING >COPYING &&
110 git-update-cache --add --remove COPYING COPYING.1'
111
f7c1512a
JH
112# tree has COPYING and rezrov. work tree has COPYING and COPYING.1,
113# but COPYING is not edited. We say you copy-and-edit COPYING.1; this
114# is only possible because -C mode now reports the unmodified file to
115# the diff-core. Unchanged rezrov, although being fed to
116# git-diff-cache as well, should not be mentioned.
c3e7fbcb 117
b6d8f309 118GIT_DIFF_OPTS=--unified=0 git-diff-cache -C -p $tree >current
c3e7fbcb 119cat >expected <<\EOF
b6d8f309 120diff --git a/COPYING b/COPYING.1
c3e7fbcb 121copy from COPYING
b6d8f309 122copy to COPYING.1
c3e7fbcb 123--- a/COPYING
b6d8f309
JH
124+++ b/COPYING.1
125@@ -6 +6 @@
126- HOWEVER, in order to allow a migration to GPLv3 if that seems like
127+ However, in order to allow a migration to GPLv3 if that seems like
c3e7fbcb
JH
128EOF
129
427dcb4b 130test_expect_success \
b6d8f309
JH
131 'validate output from rename/copy detection (#3)' \
132 'compare_diff_patch current expected'
427dcb4b
JH
133
134test_done