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