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