3 test_description
='git blame corner cases'
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 &&
14 for i in 1 2 3 4 5 6 7 8 9
18 for i in 1 2 3 4 5 6 7 8 9 a
22 git add one two tres mouse nine_lines ten_lines &&
24 GIT_AUTHOR_NAME=Initial git commit -m Initial &&
30 git add uno dos tres mouse &&
32 GIT_AUTHOR_NAME=Second git commit -a -m Second &&
37 GIT_AUTHOR_NAME=Third git commit -m Third &&
42 GIT_AUTHOR_NAME=Fourth git commit -m Fourth &&
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 &&
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 &&
136 test_cmp expected current
140 test_expect_success
'blame wholesale copy and more in the index' '
142 cat >horse <<-\EOF &&
150 test_when_finished "git rm -f horse" &&
151 git blame -f -C -C1 -- horse | sed -e "$pick_fc" >current &&
152 cat >expected <<-\EOF &&
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 &&
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 &&
175 git blame -f -C -C1 rodent | sed -e "$pick_fc" >current &&
176 cat >expected <<-\EOF &&
181 test_cmp expected current
184 test_expect_success
'blame path that used to be a directory' '
186 echo A A A A A >path/file &&
187 echo B B B B B >path/elif &&
190 git commit -m "path was a directory" &&
192 echo A A A A A >path &&
195 git commit -m "path is a regular file" &&
196 git blame HEAD^.. -- path
199 test_expect_success
'blame to a commit with no author name' '
200 TREE=$(git rev-parse HEAD:) &&
201 cat >badcommit <<EOF &&
203 author <noname> 1234567890 +0000
204 committer David Reiss <dreiss@facebook.com> 1234567890 +0000
208 COMMIT=$(git hash-object -t commit -w badcommit) &&
209 git --no-pager blame $COMMIT -- uno >/dev/null
212 test_expect_success
'blame -L with invalid start' '
213 test_must_fail git blame -L5 tres 2>errors &&
214 test_i18ngrep "has only 2 lines" errors
217 test_expect_success
'blame -L with invalid end' '
218 git blame -L1,5 tres >out &&
219 test_line_count = 2 out
222 test_expect_success
'blame parses <end> part of -L' '
223 git blame -L1,1 tres >out &&
224 test_line_count = 1 out
227 test_expect_success
'blame -Ln,-(n+1)' '
228 git blame -L3,-4 nine_lines >out &&
229 test_line_count = 3 out
232 test_expect_success
'indent of line numbers, nine lines' '
233 git blame nine_lines >actual &&
234 test $(grep -c " " actual) = 0
237 test_expect_success
'indent of line numbers, ten lines' '
238 git blame ten_lines >actual &&
239 test $(grep -c " " actual) = 9
242 test_expect_success
'setup file with CRLF newlines' '
243 git config core.autocrlf false &&
244 printf "testcase\n" >crlffile &&
246 git commit -m testcase &&
247 printf "testcase\r\n" >crlffile
250 test_expect_success
'blame file with CRLF core.autocrlf true' '
251 git config core.autocrlf true &&
252 git blame crlffile >actual &&
253 grep "A U Thor" actual
256 test_expect_success
'blame file with CRLF attributes text' '
257 git config core.autocrlf false &&
258 echo "crlffile text" >.gitattributes &&
259 git blame crlffile >actual &&
260 grep "A U Thor" actual
263 test_expect_success
'blame file with CRLF core.autocrlf=true' '
264 git config core.autocrlf false &&
265 printf "testcase\r\n" >crlfinrepo &&
267 git add crlfinrepo &&
268 git commit -m "add crlfinrepo" &&
269 git config core.autocrlf true &&
271 git checkout crlfinrepo &&
273 git blame crlfinrepo >actual &&
274 grep "A U Thor" actual
277 # Tests the splitting and merging of blame entries in blame_coalesce().
278 # The output of blame is the same, regardless of whether blame_coalesce() runs
279 # or not, so we'd likely only notice a problem if blame crashes or assigned
280 # blame to the "splitting" commit ('SPLIT' below).
281 test_expect_success
'blame coalesce' '
282 cat >giraffe <<-\EOF &&
287 git commit -m "original file" &&
288 oid=$(git rev-parse HEAD) &&
290 cat >giraffe <<-\EOF &&
296 git commit -m "interior SPLIT line" &&
298 cat >giraffe <<-\EOF &&
303 git commit -m "same contents as original" &&
305 cat >expect <<-EOF &&
309 git -c core.abbrev=40 blame -s giraffe >actual &&
310 test_cmp expect actual