]>
Commit | Line | Data |
---|---|---|
c2a06369 JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='git blame corner cases' | |
747f6c68 | 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
6 | ||
c2a06369 JH |
7 | . ./test-lib.sh |
8 | ||
9 | pick_fc='s/^[0-9a-f^]* *\([^ ]*\) *(\([^ ]*\) .*/\1-\2/' | |
10 | ||
11 | test_expect_success setup ' | |
c2a06369 JH |
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 && | |
00fb3d21 RS |
16 | for i in 1 2 3 4 5 6 7 8 9 |
17 | do | |
18 | echo $i | |
19 | done >nine_lines && | |
20 | for i in 1 2 3 4 5 6 7 8 9 a | |
21 | do | |
22 | echo $i | |
23 | done >ten_lines && | |
24 | git add one two tres mouse nine_lines ten_lines && | |
c2a06369 JH |
25 | test_tick && |
26 | GIT_AUTHOR_NAME=Initial git commit -m Initial && | |
27 | ||
28 | cat one >uno && | |
29 | mv two dos && | |
30 | cat one >>tres && | |
99094a7a | 31 | echo DEF >>mouse && |
c2a06369 JH |
32 | git add uno dos tres mouse && |
33 | test_tick && | |
34 | GIT_AUTHOR_NAME=Second git commit -a -m Second && | |
35 | ||
36 | echo GHIJK >>mouse && | |
37 | git add mouse && | |
38 | test_tick && | |
39 | GIT_AUTHOR_NAME=Third git commit -m Third && | |
40 | ||
41 | cat mouse >cow && | |
42 | git add cow && | |
43 | test_tick && | |
44 | GIT_AUTHOR_NAME=Fourth git commit -m Fourth && | |
45 | ||
c66b4700 MH |
46 | cat >cow <<-\EOF && |
47 | ABC | |
48 | DEF | |
49 | XXXX | |
50 | GHIJK | |
51 | EOF | |
c2a06369 JH |
52 | git add cow && |
53 | test_tick && | |
54 | GIT_AUTHOR_NAME=Fifth git commit -m Fifth | |
55 | ' | |
56 | ||
57 | test_expect_success 'straight copy without -C' ' | |
58 | ||
59 | git blame uno | grep Second | |
60 | ||
61 | ' | |
62 | ||
63 | test_expect_success 'straight move without -C' ' | |
64 | ||
65 | git blame dos | grep Initial | |
66 | ||
67 | ' | |
68 | ||
69 | test_expect_success 'straight copy with -C' ' | |
70 | ||
71 | git blame -C1 uno | grep Second | |
72 | ||
73 | ' | |
74 | ||
75 | test_expect_success 'straight move with -C' ' | |
76 | ||
77 | git blame -C1 dos | grep Initial | |
78 | ||
79 | ' | |
80 | ||
81 | test_expect_success 'straight copy with -C -C' ' | |
82 | ||
83 | git blame -C -C1 uno | grep Initial | |
84 | ||
85 | ' | |
86 | ||
87 | test_expect_success 'straight move with -C -C' ' | |
88 | ||
89 | git blame -C -C1 dos | grep Initial | |
90 | ||
91 | ' | |
92 | ||
93 | test_expect_success 'append without -C' ' | |
94 | ||
95 | git blame -L2 tres | grep Second | |
96 | ||
97 | ' | |
98 | ||
99 | test_expect_success 'append with -C' ' | |
100 | ||
101 | git blame -L2 -C1 tres | grep Second | |
102 | ||
103 | ' | |
104 | ||
105 | test_expect_success 'append with -C -C' ' | |
106 | ||
107 | git blame -L2 -C -C1 tres | grep Second | |
108 | ||
109 | ' | |
110 | ||
111 | test_expect_success 'append with -C -C -C' ' | |
112 | ||
113 | git blame -L2 -C -C -C1 tres | grep Initial | |
114 | ||
115 | ' | |
116 | ||
117 | test_expect_success 'blame wholesale copy' ' | |
118 | ||
119 | git blame -f -C -C1 HEAD^ -- cow | sed -e "$pick_fc" >current && | |
c66b4700 MH |
120 | cat >expected <<-\EOF && |
121 | mouse-Initial | |
122 | mouse-Second | |
123 | mouse-Third | |
124 | EOF | |
82ebb0b6 | 125 | test_cmp expected current |
c2a06369 JH |
126 | |
127 | ' | |
128 | ||
129 | test_expect_success 'blame wholesale copy and more' ' | |
130 | ||
131 | git blame -f -C -C1 HEAD -- cow | sed -e "$pick_fc" >current && | |
c66b4700 MH |
132 | cat >expected <<-\EOF && |
133 | mouse-Initial | |
134 | mouse-Second | |
135 | cow-Fifth | |
136 | mouse-Third | |
137 | EOF | |
82ebb0b6 | 138 | test_cmp expected current |
c2a06369 JH |
139 | |
140 | ' | |
141 | ||
3b75ee93 MH |
142 | test_expect_success 'blame wholesale copy and more in the index' ' |
143 | ||
144 | cat >horse <<-\EOF && | |
145 | ABC | |
146 | DEF | |
147 | XXXX | |
148 | YYYY | |
149 | GHIJK | |
150 | EOF | |
151 | git add horse && | |
152 | test_when_finished "git rm -f horse" && | |
153 | git blame -f -C -C1 -- horse | sed -e "$pick_fc" >current && | |
154 | cat >expected <<-\EOF && | |
155 | mouse-Initial | |
156 | mouse-Second | |
157 | cow-Fifth | |
158 | horse-Not | |
159 | mouse-Third | |
160 | EOF | |
161 | test_cmp expected current | |
162 | ||
163 | ' | |
164 | ||
165 | test_expect_success 'blame during cherry-pick with file rename conflict' ' | |
166 | ||
747f6c68 | 167 | test_when_finished "git reset --hard && git checkout main" && |
3b75ee93 MH |
168 | git checkout HEAD~3 && |
169 | echo MOUSE >> mouse && | |
170 | git mv mouse rodent && | |
171 | git add rodent && | |
172 | GIT_AUTHOR_NAME=Rodent git commit -m "rodent" && | |
747f6c68 | 173 | git checkout --detach main && |
3b75ee93 MH |
174 | (git cherry-pick HEAD@{1} || test $? -eq 1) && |
175 | git show HEAD@{1}:rodent > rodent && | |
176 | git add rodent && | |
177 | git blame -f -C -C1 rodent | sed -e "$pick_fc" >current && | |
3b75ee93 MH |
178 | cat >expected <<-\EOF && |
179 | mouse-Initial | |
180 | mouse-Second | |
181 | rodent-Not | |
182 | EOF | |
183 | test_cmp expected current | |
184 | ' | |
185 | ||
a9b2d424 JH |
186 | test_expect_success 'blame path that used to be a directory' ' |
187 | mkdir path && | |
188 | echo A A A A A >path/file && | |
189 | echo B B B B B >path/elif && | |
190 | git add path && | |
191 | test_tick && | |
192 | git commit -m "path was a directory" && | |
193 | rm -fr path && | |
194 | echo A A A A A >path && | |
195 | git add path && | |
196 | test_tick && | |
197 | git commit -m "path is a regular file" && | |
198 | git blame HEAD^.. -- path | |
199 | ' | |
200 | ||
c8cba791 | 201 | test_expect_success 'blame to a commit with no author name' ' |
844116d9 | 202 | TREE=$(git rev-parse HEAD:) && |
99094a7a | 203 | cat >badcommit <<EOF && |
c8cba791 DR |
204 | tree $TREE |
205 | author <noname> 1234567890 +0000 | |
206 | committer David Reiss <dreiss@facebook.com> 1234567890 +0000 | |
207 | ||
208 | some message | |
209 | EOF | |
844116d9 | 210 | COMMIT=$(git hash-object -t commit -w badcommit) && |
c8cba791 DR |
211 | git --no-pager blame $COMMIT -- uno >/dev/null |
212 | ' | |
213 | ||
92f9e273 | 214 | test_expect_success 'blame -L with invalid start' ' |
33f0ea42 | 215 | test_must_fail git blame -L5 tres 2>errors && |
e3f54bff | 216 | test_i18ngrep "has only 2 lines" errors |
92f9e273 JS |
217 | ' |
218 | ||
219 | test_expect_success 'blame -L with invalid end' ' | |
96cfa94e IS |
220 | git blame -L1,5 tres >out && |
221 | test_line_count = 2 out | |
92f9e273 JS |
222 | ' |
223 | ||
25ed3412 BY |
224 | test_expect_success 'blame parses <end> part of -L' ' |
225 | git blame -L1,1 tres >out && | |
96cfa94e IS |
226 | test_line_count = 1 out |
227 | ' | |
228 | ||
229 | test_expect_success 'blame -Ln,-(n+1)' ' | |
230 | git blame -L3,-4 nine_lines >out && | |
231 | test_line_count = 3 out | |
25ed3412 BY |
232 | ' |
233 | ||
00fb3d21 RS |
234 | test_expect_success 'indent of line numbers, nine lines' ' |
235 | git blame nine_lines >actual && | |
236 | test $(grep -c " " actual) = 0 | |
237 | ' | |
238 | ||
239 | test_expect_success 'indent of line numbers, ten lines' ' | |
240 | git blame ten_lines >actual && | |
241 | test $(grep -c " " actual) = 9 | |
242 | ' | |
243 | ||
4bf256d6 | 244 | test_expect_success 'setup file with CRLF newlines' ' |
4d4813a5 | 245 | git config core.autocrlf false && |
4bf256d6 | 246 | printf "testcase\n" >crlffile && |
4d4813a5 | 247 | git add crlffile && |
248 | git commit -m testcase && | |
4bf256d6 TB |
249 | printf "testcase\r\n" >crlffile |
250 | ' | |
251 | ||
252 | test_expect_success 'blame file with CRLF core.autocrlf true' ' | |
253 | git config core.autocrlf true && | |
254 | git blame crlffile >actual && | |
255 | grep "A U Thor" actual | |
256 | ' | |
257 | ||
258 | test_expect_success 'blame file with CRLF attributes text' ' | |
259 | git config core.autocrlf false && | |
260 | echo "crlffile text" >.gitattributes && | |
261 | git blame crlffile >actual && | |
4d4813a5 | 262 | grep "A U Thor" actual |
263 | ' | |
264 | ||
a08feb8e TB |
265 | test_expect_success 'blame file with CRLF core.autocrlf=true' ' |
266 | git config core.autocrlf false && | |
267 | printf "testcase\r\n" >crlfinrepo && | |
268 | >.gitattributes && | |
269 | git add crlfinrepo && | |
270 | git commit -m "add crlfinrepo" && | |
271 | git config core.autocrlf true && | |
272 | mv crlfinrepo tmp && | |
273 | git checkout crlfinrepo && | |
274 | rm tmp && | |
275 | git blame crlfinrepo >actual && | |
276 | grep "A U Thor" actual | |
277 | ' | |
278 | ||
dd7c6111 | 279 | test_expect_success 'setup coalesce tests' ' |
f0cbe742 BR |
280 | cat >giraffe <<-\EOF && |
281 | ABC | |
282 | DEF | |
283 | EOF | |
284 | git add giraffe && | |
285 | git commit -m "original file" && | |
dd7c6111 | 286 | orig=$(git rev-parse HEAD) && |
f0cbe742 BR |
287 | |
288 | cat >giraffe <<-\EOF && | |
289 | ABC | |
290 | SPLIT | |
291 | DEF | |
292 | EOF | |
293 | git add giraffe && | |
294 | git commit -m "interior SPLIT line" && | |
dd7c6111 | 295 | split=$(git rev-parse HEAD) && |
f0cbe742 BR |
296 | |
297 | cat >giraffe <<-\EOF && | |
298 | ABC | |
299 | DEF | |
300 | EOF | |
301 | git add giraffe && | |
302 | git commit -m "same contents as original" && | |
dd7c6111 JK |
303 | final=$(git rev-parse HEAD) |
304 | ' | |
f0cbe742 | 305 | |
dd7c6111 | 306 | test_expect_success 'blame coalesce' ' |
f0cbe742 | 307 | cat >expect <<-EOF && |
dd7c6111 JK |
308 | $orig 1 1 2 |
309 | $orig 2 2 | |
f0cbe742 | 310 | EOF |
dd7c6111 JK |
311 | git blame --porcelain $final giraffe >actual.raw && |
312 | grep "^$orig" actual.raw >actual && | |
f0cbe742 BR |
313 | test_cmp expect actual |
314 | ' | |
f0cbe742 | 315 | |
c2ebaa27 | 316 | test_expect_success 'blame does not coalesce non-adjacent result lines' ' |
f0cbe742 | 317 | cat >expect <<-EOF && |
c2ebaa27 JK |
318 | $orig 1) ABC |
319 | $orig 3) DEF | |
f0cbe742 | 320 | EOF |
c2ebaa27 | 321 | git blame --no-abbrev -s -L1,1 -L3,3 $split giraffe >actual && |
f0cbe742 BR |
322 | test_cmp expect actual |
323 | ' | |
324 | ||
c2a06369 | 325 | test_done |