t4001-diff-rename: wrap file creations in a test
[git/raj.git] / t / t4001-diff-rename.sh
blob06b8828a6d5734738260303031a09f5b5b2250be
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='Test rename detection in diff engine.
9 . ./test-lib.sh
10 . "$TEST_DIRECTORY"/diff-lib.sh
12 test_expect_success 'setup' '
13 cat >path0 <<-\EOF &&
14 Line 1
15 Line 2
16 Line 3
17 Line 4
18 Line 5
19 Line 6
20 Line 7
21 Line 8
22 Line 9
23 Line 10
24 line 11
25 Line 12
26 Line 13
27 Line 14
28 Line 15
29 EOF
30 cat >expected <<-\EOF
31 diff --git a/path0 b/path1
32 rename from path0
33 rename to path1
34 --- a/path0
35 +++ b/path1
36 @@ -8,7 +8,7 @@ Line 7
37 Line 8
38 Line 9
39 Line 10
40 -line 11
41 +Line 11
42 Line 12
43 Line 13
44 Line 14
45 EOF
48 test_expect_success \
49 'update-index --add a file.' \
50 'git update-index --add path0'
52 test_expect_success \
53 'write that tree.' \
54 'tree=$(git write-tree) && echo $tree'
56 sed -e 's/line/Line/' <path0 >path1
57 rm -f path0
58 test_expect_success \
59 'renamed and edited the file.' \
60 'git update-index --add --remove path0 path1'
62 test_expect_success \
63 'git diff-index -p -M after rename and editing.' \
64 'git diff-index -p -M $tree >current'
67 test_expect_success \
68 'validate the output.' \
69 'compare_diff_patch current expected'
71 test_expect_success 'favour same basenames over different ones' '
72 cp path1 another-path &&
73 git add another-path &&
74 git commit -m 1 &&
75 git rm path1 &&
76 mkdir subdir &&
77 git mv another-path subdir/path1 &&
78 git status | test_i18ngrep "renamed: .*path1 -> subdir/path1"'
80 test_expect_success 'favour same basenames even with minor differences' '
81 git show HEAD:path1 | sed "s/15/16/" > subdir/path1 &&
82 git status | test_i18ngrep "renamed: .*path1 -> subdir/path1"'
84 test_expect_success 'setup for many rename source candidates' '
85 git reset --hard &&
86 for i in 0 1 2 3 4 5 6 7 8 9;
88 for j in 0 1 2 3 4 5 6 7 8 9;
90 echo "$i$j" >"path$i$j"
91 done
92 done &&
93 git add "path??" &&
94 test_tick &&
95 git commit -m "hundred" &&
96 (cat path1; echo new) >new-path &&
97 echo old >>path1 &&
98 git add new-path path1 &&
99 git diff -l 4 -C -C --cached --name-status >actual 2>actual.err &&
100 sed -e "s/^\([CM]\)[0-9]* /\1 /" actual >actual.munged &&
101 cat >expect <<-EOF &&
102 C path1 new-path
103 M path1
105 test_cmp expect actual.munged &&
106 grep warning actual.err
109 test_expect_success 'rename pretty print with nothing in common' '
110 mkdir -p a/b/ &&
111 : >a/b/c &&
112 git add a/b/c &&
113 git commit -m "create a/b/c" &&
114 mkdir -p c/b/ &&
115 git mv a/b/c c/b/a &&
116 git commit -m "a/b/c -> c/b/a" &&
117 git diff -M --summary HEAD^ HEAD >output &&
118 test_i18ngrep " a/b/c => c/b/a " output &&
119 git diff -M --stat HEAD^ HEAD >output &&
120 test_i18ngrep " a/b/c => c/b/a " output
123 test_expect_success 'rename pretty print with common prefix' '
124 mkdir -p c/d &&
125 git mv c/b/a c/d/e &&
126 git commit -m "c/b/a -> c/d/e" &&
127 git diff -M --summary HEAD^ HEAD >output &&
128 test_i18ngrep " c/{b/a => d/e} " output &&
129 git diff -M --stat HEAD^ HEAD >output &&
130 test_i18ngrep " c/{b/a => d/e} " output
133 test_expect_success 'rename pretty print with common suffix' '
134 mkdir d &&
135 git mv c/d/e d/e &&
136 git commit -m "c/d/e -> d/e" &&
137 git diff -M --summary HEAD^ HEAD >output &&
138 test_i18ngrep " {c/d => d}/e " output &&
139 git diff -M --stat HEAD^ HEAD >output &&
140 test_i18ngrep " {c/d => d}/e " output
143 test_expect_success 'rename pretty print with common prefix and suffix' '
144 mkdir d/f &&
145 git mv d/e d/f/e &&
146 git commit -m "d/e -> d/f/e" &&
147 git diff -M --summary HEAD^ HEAD >output &&
148 test_i18ngrep " d/{ => f}/e " output &&
149 git diff -M --stat HEAD^ HEAD >output &&
150 test_i18ngrep " d/{ => f}/e " output
153 test_expect_success 'rename pretty print common prefix and suffix overlap' '
154 mkdir d/f/f &&
155 git mv d/f/e d/f/f/e &&
156 git commit -m "d/f/e d/f/f/e" &&
157 git diff -M --summary HEAD^ HEAD >output &&
158 test_i18ngrep " d/f/{ => f}/e " output &&
159 git diff -M --stat HEAD^ HEAD >output &&
160 test_i18ngrep " d/f/{ => f}/e " output
163 test_done