environment: rename 'template' variables
[alt-git.git] / t / t8003-blame-corner-cases.sh
blob661f9d430d28834b8a006fa0bcc958f52c95258b
1 #!/bin/sh
3 test_description='git blame corner cases'
4 . ./test-lib.sh
6 pick_fc='s/^[0-9a-f^]* *\([^ ]*\) *(\([^ ]*\) .*/\1-\2/'
8 test_expect_success setup '
10 echo A A A A A >one &&
11 echo B B B B B >two &&
12 echo C C C C C >tres &&
13 echo ABC >mouse &&
14 for i in 1 2 3 4 5 6 7 8 9
16 echo $i
17 done >nine_lines &&
18 for i in 1 2 3 4 5 6 7 8 9 a
20 echo $i
21 done >ten_lines &&
22 git add one two tres mouse nine_lines ten_lines &&
23 test_tick &&
24 GIT_AUTHOR_NAME=Initial git commit -m Initial &&
26 cat one >uno &&
27 mv two dos &&
28 cat one >>tres &&
29 echo DEF >>mouse &&
30 git add uno dos tres mouse &&
31 test_tick &&
32 GIT_AUTHOR_NAME=Second git commit -a -m Second &&
34 echo GHIJK >>mouse &&
35 git add mouse &&
36 test_tick &&
37 GIT_AUTHOR_NAME=Third git commit -m Third &&
39 cat mouse >cow &&
40 git add cow &&
41 test_tick &&
42 GIT_AUTHOR_NAME=Fourth git commit -m Fourth &&
44 cat >cow <<-\EOF &&
45 ABC
46 DEF
47 XXXX
48 GHIJK
49 EOF
50 git add cow &&
51 test_tick &&
52 GIT_AUTHOR_NAME=Fifth git commit -m Fifth
55 test_expect_success 'straight copy without -C' '
57 git blame uno | grep Second
61 test_expect_success 'straight move without -C' '
63 git blame dos | grep Initial
67 test_expect_success 'straight copy with -C' '
69 git blame -C1 uno | grep Second
73 test_expect_success 'straight move with -C' '
75 git blame -C1 dos | grep Initial
79 test_expect_success 'straight copy with -C -C' '
81 git blame -C -C1 uno | grep Initial
85 test_expect_success 'straight move with -C -C' '
87 git blame -C -C1 dos | grep Initial
91 test_expect_success 'append without -C' '
93 git blame -L2 tres | grep Second
97 test_expect_success 'append with -C' '
99 git blame -L2 -C1 tres | grep Second
103 test_expect_success 'append with -C -C' '
105 git blame -L2 -C -C1 tres | grep Second
109 test_expect_success 'append with -C -C -C' '
111 git blame -L2 -C -C -C1 tres | grep Initial
115 test_expect_success 'blame wholesale copy' '
117 git blame -f -C -C1 HEAD^ -- cow | sed -e "$pick_fc" >current &&
118 cat >expected <<-\EOF &&
119 mouse-Initial
120 mouse-Second
121 mouse-Third
123 test_cmp expected current
127 test_expect_success 'blame wholesale copy and more' '
129 git blame -f -C -C1 HEAD -- cow | sed -e "$pick_fc" >current &&
130 cat >expected <<-\EOF &&
131 mouse-Initial
132 mouse-Second
133 cow-Fifth
134 mouse-Third
136 test_cmp expected current
140 test_expect_success 'blame wholesale copy and more in the index' '
142 cat >horse <<-\EOF &&
145 XXXX
146 YYYY
147 GHIJK
149 git add horse &&
150 test_when_finished "git rm -f horse" &&
151 git blame -f -C -C1 -- horse | sed -e "$pick_fc" >current &&
152 cat >expected <<-\EOF &&
153 mouse-Initial
154 mouse-Second
155 cow-Fifth
156 horse-Not
157 mouse-Third
159 test_cmp expected current
163 test_expect_success 'blame during cherry-pick with file rename conflict' '
165 test_when_finished "git reset --hard && git checkout master" &&
166 git checkout HEAD~3 &&
167 echo MOUSE >> mouse &&
168 git mv mouse rodent &&
169 git add rodent &&
170 GIT_AUTHOR_NAME=Rodent git commit -m "rodent" &&
171 git checkout --detach master &&
172 (git cherry-pick HEAD@{1} || test $? -eq 1) &&
173 git show HEAD@{1}:rodent > rodent &&
174 git add rodent &&
175 git blame -f -C -C1 rodent | sed -e "$pick_fc" >current &&
176 cat current &&
177 cat >expected <<-\EOF &&
178 mouse-Initial
179 mouse-Second
180 rodent-Not
182 test_cmp expected current
185 test_expect_success 'blame path that used to be a directory' '
186 mkdir path &&
187 echo A A A A A >path/file &&
188 echo B B B B B >path/elif &&
189 git add path &&
190 test_tick &&
191 git commit -m "path was a directory" &&
192 rm -fr path &&
193 echo A A A A A >path &&
194 git add path &&
195 test_tick &&
196 git commit -m "path is a regular file" &&
197 git blame HEAD^.. -- path
200 test_expect_success 'blame to a commit with no author name' '
201 TREE=$(git rev-parse HEAD:) &&
202 cat >badcommit <<EOF &&
203 tree $TREE
204 author <noname> 1234567890 +0000
205 committer David Reiss <dreiss@facebook.com> 1234567890 +0000
207 some message
209 COMMIT=$(git hash-object -t commit -w badcommit) &&
210 git --no-pager blame $COMMIT -- uno >/dev/null
213 test_expect_success 'blame -L with invalid start' '
214 test_must_fail git blame -L5 tres 2>errors &&
215 test_i18ngrep "has only 2 lines" errors
218 test_expect_success 'blame -L with invalid end' '
219 test_must_fail git blame -L1,5 tres 2>errors &&
220 test_i18ngrep "has only 2 lines" errors
223 test_expect_success 'blame parses <end> part of -L' '
224 git blame -L1,1 tres >out &&
225 cat out &&
226 test $(wc -l < out) -eq 1
229 test_expect_success 'indent of line numbers, nine lines' '
230 git blame nine_lines >actual &&
231 test $(grep -c " " actual) = 0
234 test_expect_success 'indent of line numbers, ten lines' '
235 git blame ten_lines >actual &&
236 test $(grep -c " " actual) = 9
239 test_expect_success 'setup file with CRLF newlines' '
240 git config core.autocrlf false &&
241 printf "testcase\n" >crlffile &&
242 git add crlffile &&
243 git commit -m testcase &&
244 printf "testcase\r\n" >crlffile
247 test_expect_success 'blame file with CRLF core.autocrlf true' '
248 git config core.autocrlf true &&
249 git blame crlffile >actual &&
250 grep "A U Thor" actual
253 test_expect_success 'blame file with CRLF attributes text' '
254 git config core.autocrlf false &&
255 echo "crlffile text" >.gitattributes &&
256 git blame crlffile >actual &&
257 grep "A U Thor" actual
260 test_expect_success 'blame file with CRLF core.autocrlf=true' '
261 git config core.autocrlf false &&
262 printf "testcase\r\n" >crlfinrepo &&
263 >.gitattributes &&
264 git add crlfinrepo &&
265 git commit -m "add crlfinrepo" &&
266 git config core.autocrlf true &&
267 mv crlfinrepo tmp &&
268 git checkout crlfinrepo &&
269 rm tmp &&
270 git blame crlfinrepo >actual &&
271 grep "A U Thor" actual
274 test_done