cocci: apply "pending" index-compatibility to "t/helper/*.c"
[git/debian.git] / t / t8003-blame-corner-cases.sh
blobd751d48b7dae6a3e007d5eb19f92cd41eb445065
1 #!/bin/sh
3 test_description='git blame corner cases'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 . ./test-lib.sh
9 pick_fc='s/^[0-9a-f^]* *\([^ ]*\) *(\([^ ]*\) .*/\1-\2/'
11 test_expect_success setup '
12 echo A A A A A >one &&
13 echo B B B B B >two &&
14 echo C C C C C >tres &&
15 echo ABC >mouse &&
16 test_write_lines 1 2 3 4 5 6 7 8 9 >nine_lines &&
17 test_write_lines 1 2 3 4 5 6 7 8 9 a >ten_lines &&
18 git add one two tres mouse nine_lines ten_lines &&
19 test_tick &&
20 GIT_AUTHOR_NAME=Initial git commit -m Initial &&
22 cat one >uno &&
23 mv two dos &&
24 cat one >>tres &&
25 echo DEF >>mouse &&
26 git add uno dos tres mouse &&
27 test_tick &&
28 GIT_AUTHOR_NAME=Second git commit -a -m Second &&
30 echo GHIJK >>mouse &&
31 git add mouse &&
32 test_tick &&
33 GIT_AUTHOR_NAME=Third git commit -m Third &&
35 cat mouse >cow &&
36 git add cow &&
37 test_tick &&
38 GIT_AUTHOR_NAME=Fourth git commit -m Fourth &&
40 cat >cow <<-\EOF &&
41 ABC
42 DEF
43 XXXX
44 GHIJK
45 EOF
46 git add cow &&
47 test_tick &&
48 GIT_AUTHOR_NAME=Fifth git commit -m Fifth
51 test_expect_success 'straight copy without -C' '
53 git blame uno | grep Second
57 test_expect_success 'straight move without -C' '
59 git blame dos | grep Initial
63 test_expect_success 'straight copy with -C' '
65 git blame -C1 uno | grep Second
69 test_expect_success 'straight move with -C' '
71 git blame -C1 dos | grep Initial
75 test_expect_success 'straight copy with -C -C' '
77 git blame -C -C1 uno | grep Initial
81 test_expect_success 'straight move with -C -C' '
83 git blame -C -C1 dos | grep Initial
87 test_expect_success 'append without -C' '
89 git blame -L2 tres | grep Second
93 test_expect_success 'append with -C' '
95 git blame -L2 -C1 tres | grep Second
99 test_expect_success 'append with -C -C' '
101 git blame -L2 -C -C1 tres | grep Second
105 test_expect_success 'append with -C -C -C' '
107 git blame -L2 -C -C -C1 tres | grep Initial
111 test_expect_success 'blame wholesale copy' '
113 git blame -f -C -C1 HEAD^ -- cow | sed -e "$pick_fc" >current &&
114 cat >expected <<-\EOF &&
115 mouse-Initial
116 mouse-Second
117 mouse-Third
119 test_cmp expected current
123 test_expect_success 'blame wholesale copy and more' '
125 git blame -f -C -C1 HEAD -- cow | sed -e "$pick_fc" >current &&
126 cat >expected <<-\EOF &&
127 mouse-Initial
128 mouse-Second
129 cow-Fifth
130 mouse-Third
132 test_cmp expected current
136 test_expect_success 'blame wholesale copy and more in the index' '
138 cat >horse <<-\EOF &&
141 XXXX
142 YYYY
143 GHIJK
145 git add horse &&
146 test_when_finished "git rm -f horse" &&
147 git blame -f -C -C1 -- horse | sed -e "$pick_fc" >current &&
148 cat >expected <<-\EOF &&
149 mouse-Initial
150 mouse-Second
151 cow-Fifth
152 horse-Not
153 mouse-Third
155 test_cmp expected current
159 test_expect_success 'blame during cherry-pick with file rename conflict' '
161 test_when_finished "git reset --hard && git checkout main" &&
162 git checkout HEAD~3 &&
163 echo MOUSE >> mouse &&
164 git mv mouse rodent &&
165 git add rodent &&
166 GIT_AUTHOR_NAME=Rodent git commit -m "rodent" &&
167 git checkout --detach main &&
168 (git cherry-pick HEAD@{1} || test $? -eq 1) &&
169 git show HEAD@{1}:rodent > rodent &&
170 git add rodent &&
171 git blame -f -C -C1 rodent | sed -e "$pick_fc" >current &&
172 cat >expected <<-\EOF &&
173 mouse-Initial
174 mouse-Second
175 rodent-Not
177 test_cmp expected current
180 test_expect_success 'blame path that used to be a directory' '
181 mkdir path &&
182 echo A A A A A >path/file &&
183 echo B B B B B >path/elif &&
184 git add path &&
185 test_tick &&
186 git commit -m "path was a directory" &&
187 rm -fr path &&
188 echo A A A A A >path &&
189 git add path &&
190 test_tick &&
191 git commit -m "path is a regular file" &&
192 git blame HEAD^.. -- path
195 test_expect_success 'blame to a commit with no author name' '
196 TREE=$(git rev-parse HEAD:) &&
197 cat >badcommit <<EOF &&
198 tree $TREE
199 author <noname> 1234567890 +0000
200 committer David Reiss <dreiss@facebook.com> 1234567890 +0000
202 some message
204 COMMIT=$(git hash-object -t commit -w badcommit) &&
205 git --no-pager blame $COMMIT -- uno >/dev/null
208 test_expect_success 'blame -L with invalid start' '
209 test_must_fail git blame -L5 tres 2>errors &&
210 test_i18ngrep "has only 2 lines" errors
213 test_expect_success 'blame -L with invalid end' '
214 git blame -L1,5 tres >out &&
215 test_line_count = 2 out
218 test_expect_success 'blame parses <end> part of -L' '
219 git blame -L1,1 tres >out &&
220 test_line_count = 1 out
223 test_expect_success 'blame -Ln,-(n+1)' '
224 git blame -L3,-4 nine_lines >out &&
225 test_line_count = 3 out
228 test_expect_success 'indent of line numbers, nine lines' '
229 git blame nine_lines >actual &&
230 test $(grep -c " " actual) = 0
233 test_expect_success 'indent of line numbers, ten lines' '
234 git blame ten_lines >actual &&
235 test $(grep -c " " actual) = 9
238 test_expect_success 'setup file with CRLF newlines' '
239 git config core.autocrlf false &&
240 printf "testcase\n" >crlffile &&
241 git add crlffile &&
242 git commit -m testcase &&
243 printf "testcase\r\n" >crlffile
246 test_expect_success 'blame file with CRLF core.autocrlf true' '
247 git config core.autocrlf true &&
248 git blame crlffile >actual &&
249 grep "A U Thor" actual
252 test_expect_success 'blame file with CRLF attributes text' '
253 git config core.autocrlf false &&
254 echo "crlffile text" >.gitattributes &&
255 git blame crlffile >actual &&
256 grep "A U Thor" actual
259 test_expect_success 'blame file with CRLF core.autocrlf=true' '
260 git config core.autocrlf false &&
261 printf "testcase\r\n" >crlfinrepo &&
262 >.gitattributes &&
263 git add crlfinrepo &&
264 git commit -m "add crlfinrepo" &&
265 git config core.autocrlf true &&
266 mv crlfinrepo tmp &&
267 git checkout crlfinrepo &&
268 rm tmp &&
269 git blame crlfinrepo >actual &&
270 grep "A U Thor" actual
273 test_expect_success 'setup coalesce tests' '
274 cat >giraffe <<-\EOF &&
278 git add giraffe &&
279 git commit -m "original file" &&
280 orig=$(git rev-parse HEAD) &&
282 cat >giraffe <<-\EOF &&
284 SPLIT
287 git add giraffe &&
288 git commit -m "interior SPLIT line" &&
289 split=$(git rev-parse HEAD) &&
291 cat >giraffe <<-\EOF &&
295 git add giraffe &&
296 git commit -m "same contents as original" &&
297 final=$(git rev-parse HEAD)
300 test_expect_success 'blame coalesce' '
301 cat >expect <<-EOF &&
302 $orig 1 1 2
303 $orig 2 2
305 git blame --porcelain $final giraffe >actual.raw &&
306 grep "^$orig" actual.raw >actual &&
307 test_cmp expect actual
310 test_expect_success 'blame does not coalesce non-adjacent result lines' '
311 cat >expect <<-EOF &&
312 $orig 1) ABC
313 $orig 3) DEF
315 git blame --no-abbrev -s -L1,1 -L3,3 $split giraffe >actual &&
316 test_cmp expect actual
319 test_done