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 &&
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 &&
136 test_cmp expected current
140 test_expect_success
'blame path that used to be a directory' '
142 echo A A A A A >path/file &&
143 echo B B B B B >path/elif &&
146 git commit -m "path was a directory" &&
148 echo A A A A A >path &&
151 git commit -m "path is a regular file" &&
152 git blame HEAD^.. -- path
155 test_expect_success
'blame to a commit with no author name' '
156 TREE=`git rev-parse HEAD:`
159 author <noname> 1234567890 +0000
160 committer David Reiss <dreiss@facebook.com> 1234567890 +0000
164 COMMIT=`git hash-object -t commit -w badcommit`
165 git --no-pager blame $COMMIT -- uno >/dev/null
168 test_expect_success
'blame -L with invalid start' '
169 test_must_fail git blame -L5 tres 2>errors &&
170 grep "has only 2 lines" errors
173 test_expect_success
'blame -L with invalid end' '
174 test_must_fail git blame -L1,5 tres 2>errors &&
175 grep "has only 2 lines" errors
178 test_expect_success
'indent of line numbers, nine lines' '
179 git blame nine_lines >actual &&
180 test $(grep -c " " actual) = 0
183 test_expect_success
'indent of line numbers, ten lines' '
184 git blame ten_lines >actual &&
185 test $(grep -c " " actual) = 9