]>
Commit | Line | Data |
---|---|---|
12ace0b2 KH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Kristian Høgsberg <krh@redhat.com> | |
4 | # | |
5 | ||
cab11f4e | 6 | # FIXME: Test the various index usages, test reflog |
12ace0b2 | 7 | |
47a528ad | 8 | test_description='git commit' |
1e2ae142 | 9 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
10 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
11 | ||
12ace0b2 | 12 | . ./test-lib.sh |
ebd73f50 | 13 | . "$TEST_DIRECTORY/lib-diff.sh" |
12ace0b2 | 14 | |
1af524eb | 15 | author='The Real Author <someguy@his.email.org>' |
12ace0b2 | 16 | |
1af524eb | 17 | test_tick |
b3b298af | 18 | |
1af524eb JN |
19 | test_expect_success 'initial status' ' |
20 | echo bongo bongo >file && | |
21 | git add file && | |
32177ba6 | 22 | git status >actual && |
6789275d | 23 | test_grep "No commits yet" actual |
32177ba6 | 24 | ' |
12ace0b2 | 25 | |
1af524eb JN |
26 | test_expect_success 'fail initial amend' ' |
27 | test_must_fail git commit --amend | |
28 | ' | |
12ace0b2 | 29 | |
1af524eb JN |
30 | test_expect_success 'setup: initial commit' ' |
31 | git commit -m initial | |
32 | ' | |
12ace0b2 | 33 | |
1af524eb | 34 | test_expect_success '-m and -F do not mix' ' |
c65dc351 | 35 | git checkout HEAD file && echo >>file && git add file && |
1af524eb JN |
36 | test_must_fail git commit -m foo -m bar -F file |
37 | ' | |
12ace0b2 | 38 | |
1af524eb | 39 | test_expect_success '-m and -C do not mix' ' |
c65dc351 | 40 | git checkout HEAD file && echo >>file && git add file && |
1af524eb JN |
41 | test_must_fail git commit -C HEAD -m illegal |
42 | ' | |
12ace0b2 | 43 | |
1af524eb JN |
44 | test_expect_success 'paths and -a do not mix' ' |
45 | echo King of the bongo >file && | |
46 | test_must_fail git commit -m foo -a file | |
47 | ' | |
9d87442f | 48 | |
e41fcfe9 | 49 | test_expect_success PERL 'can use paths with --interactive' ' |
587ac8c9 JK |
50 | echo bong-o-bong >file && |
51 | # 2: update, 1:st path, that is all, 7: quit | |
0590ff26 | 52 | test_write_lines 2 1 "" 7 | |
e41fcfe9 CI |
53 | git commit -m foo --interactive file && |
54 | git reset --hard HEAD^ | |
587ac8c9 | 55 | ' |
9d87442f | 56 | |
86238e07 BW |
57 | test_expect_success 'removed files and relative paths' ' |
58 | test_when_finished "rm -rf foo" && | |
59 | git init foo && | |
60 | >foo/foo.txt && | |
61 | git -C foo add foo.txt && | |
62 | git -C foo commit -m first && | |
63 | git -C foo rm foo.txt && | |
64 | ||
65 | mkdir -p foo/bar && | |
66 | git -C foo/bar commit -m second ../foo.txt | |
67 | ' | |
68 | ||
1af524eb | 69 | test_expect_success 'using invalid commit with -C' ' |
0bb0c155 | 70 | test_must_fail git commit --allow-empty -C bogus |
1af524eb | 71 | ' |
12ace0b2 | 72 | |
1af524eb | 73 | test_expect_success 'nothing to commit' ' |
088304bf | 74 | git reset --hard && |
1af524eb JN |
75 | test_must_fail git commit -m initial |
76 | ' | |
12ace0b2 | 77 | |
9cbcc2a7 TRC |
78 | test_expect_success '--dry-run fails with nothing to commit' ' |
79 | test_must_fail git commit -m initial --dry-run | |
80 | ' | |
81 | ||
82 | test_expect_success '--short fails with nothing to commit' ' | |
83 | test_must_fail git commit -m initial --short | |
84 | ' | |
85 | ||
86 | test_expect_success '--porcelain fails with nothing to commit' ' | |
87 | test_must_fail git commit -m initial --porcelain | |
88 | ' | |
89 | ||
90 | test_expect_success '--long fails with nothing to commit' ' | |
91 | test_must_fail git commit -m initial --long | |
92 | ' | |
93 | ||
4e4f576b GT |
94 | test_expect_success 'fail to commit untracked file (even with --include/--only)' ' |
95 | echo content >baz && | |
96 | error="error: pathspec .baz. did not match any file(s) known to git" && | |
97 | ||
98 | test_must_fail git commit -m "baz" baz 2>err && | |
99 | test_grep -e "$error" err && | |
100 | ||
101 | test_must_fail git commit --only -m "baz" baz 2>err && | |
102 | test_grep -e "$error" err && | |
103 | ||
4e4f576b | 104 | test_must_fail git commit --include -m "baz" baz 2>err && |
ac5946e6 | 105 | test_grep -e "$error" err |
4e4f576b GT |
106 | ' |
107 | ||
1af524eb JN |
108 | test_expect_success 'setup: non-initial commit' ' |
109 | echo bongo bongo bongo >file && | |
110 | git commit -m next -a | |
111 | ' | |
12ace0b2 | 112 | |
9cbcc2a7 TRC |
113 | test_expect_success '--dry-run with stuff to commit returns ok' ' |
114 | echo bongo bongo bongo >>file && | |
115 | git commit -m next -a --dry-run | |
116 | ' | |
117 | ||
f3bd35fa | 118 | test_expect_success '--short with stuff to commit returns ok' ' |
9cbcc2a7 TRC |
119 | echo bongo bongo bongo >>file && |
120 | git commit -m next -a --short | |
121 | ' | |
122 | ||
f3bd35fa | 123 | test_expect_success '--porcelain with stuff to commit returns ok' ' |
9cbcc2a7 TRC |
124 | echo bongo bongo bongo >>file && |
125 | git commit -m next -a --porcelain | |
126 | ' | |
127 | ||
128 | test_expect_success '--long with stuff to commit returns ok' ' | |
129 | echo bongo bongo bongo >>file && | |
130 | git commit -m next -a --long | |
131 | ' | |
132 | ||
4e4f576b GT |
133 | for opt in "" "-o" "--only" |
134 | do | |
135 | test_expect_success 'exclude additional staged changes when given pathspec' ' | |
136 | echo content >>file && | |
137 | echo content >>baz && | |
138 | git add baz && | |
139 | git commit $opt -m "file" file && | |
140 | ||
141 | git diff --name-only >actual && | |
142 | test_must_be_empty actual && | |
143 | ||
144 | test_write_lines baz >expect && | |
145 | git diff --name-only --cached >actual && | |
146 | test_cmp expect actual && | |
147 | ||
148 | test_write_lines file >expect && | |
149 | git diff --name-only HEAD^ HEAD >actual && | |
150 | test_cmp expect actual | |
151 | ' | |
152 | done | |
153 | ||
154 | test_expect_success '-i/--include includes staged changes' ' | |
155 | echo content >>file && | |
156 | echo content >>baz && | |
157 | git add file && | |
158 | ||
159 | # baz is in the index, therefore, it will be committed | |
160 | git commit --include -m "file and baz" baz && | |
161 | ||
162 | git diff --name-only HEAD >remaining && | |
163 | test_must_be_empty remaining && | |
164 | ||
165 | test_write_lines baz file >expect && | |
166 | git diff --name-only HEAD^ HEAD >actual && | |
167 | test_cmp expect actual | |
168 | ' | |
169 | ||
170 | test_expect_success '--include and --only do not mix' ' | |
171 | test_when_finished "git reset --hard" && | |
172 | echo content >>file && | |
173 | echo content >>baz && | |
174 | test_must_fail git commit --include --only -m "file baz" file baz 2>actual && | |
175 | test_grep -e "fatal: options .-i/--include. and .-o/--only. cannot be used together" actual | |
176 | ' | |
177 | ||
1af524eb JN |
178 | test_expect_success 'commit message from non-existing file' ' |
179 | echo more bongo: bongo bongo bongo bongo >file && | |
180 | test_must_fail git commit -F gah -a | |
181 | ' | |
12ace0b2 | 182 | |
1af524eb JN |
183 | test_expect_success 'empty commit message' ' |
184 | # Empty except stray tabs and spaces on a few lines. | |
185 | sed -e "s/@//g" >msg <<-\EOF && | |
186 | @ @ | |
187 | @@ | |
188 | @ @ | |
189 | @Signed-off-by: hula@ | |
190 | EOF | |
191 | test_must_fail git commit -F msg -a | |
192 | ' | |
12ace0b2 | 193 | |
010c7dbc JH |
194 | test_expect_success 'template "emptyness" check does not kick in with -F' ' |
195 | git checkout HEAD file && echo >>file && git add file && | |
196 | git commit -t file -F file | |
197 | ' | |
198 | ||
b2eda9bd JH |
199 | test_expect_success 'template "emptyness" check' ' |
200 | git checkout HEAD file && echo >>file && git add file && | |
201 | test_must_fail git commit -t file 2>err && | |
6789275d | 202 | test_grep "did not edit" err |
b2eda9bd JH |
203 | ' |
204 | ||
1af524eb | 205 | test_expect_success 'setup: commit message from file' ' |
010c7dbc | 206 | git checkout HEAD file && echo >>file && git add file && |
1af524eb JN |
207 | echo this is the commit message, coming from a file >msg && |
208 | git commit -F msg -a | |
209 | ' | |
12ace0b2 | 210 | |
1af524eb JN |
211 | test_expect_success 'amend commit' ' |
212 | cat >editor <<-\EOF && | |
213 | #!/bin/sh | |
38c1aa01 | 214 | sed -e "s/a file/an amend commit/g" <"$1" >"$1-" |
1af524eb JN |
215 | mv "$1-" "$1" |
216 | EOF | |
217 | chmod 755 editor && | |
218 | EDITOR=./editor git commit --amend | |
219 | ' | |
12ace0b2 | 220 | |
ea2d4ed3 JK |
221 | test_expect_success 'amend --only ignores staged contents' ' |
222 | cp file file.expect && | |
223 | echo changed >file && | |
224 | git add file && | |
225 | git commit --no-edit --amend --only && | |
226 | git cat-file blob HEAD:file >file.actual && | |
227 | test_cmp file.expect file.actual && | |
228 | git diff --exit-code | |
229 | ' | |
230 | ||
319d8352 AK |
231 | test_expect_success 'allow-empty --only ignores staged contents' ' |
232 | echo changed-again >file && | |
233 | git add file && | |
234 | git commit --allow-empty --only -m "empty" && | |
235 | git cat-file blob HEAD:file >file.actual && | |
236 | test_cmp file.expect file.actual && | |
ea2d4ed3 JK |
237 | git diff --exit-code |
238 | ' | |
239 | ||
bc821899 JN |
240 | test_expect_success 'set up editor' ' |
241 | cat >editor <<-\EOF && | |
242 | #!/bin/sh | |
243 | sed -e "s/unamended/amended/g" <"$1" >"$1-" | |
244 | mv "$1-" "$1" | |
245 | EOF | |
246 | chmod 755 editor | |
247 | ' | |
248 | ||
249 | test_expect_success 'amend without launching editor' ' | |
250 | echo unamended >expect && | |
251 | git commit --allow-empty -m "unamended" && | |
252 | echo needs more bongo >file && | |
253 | git add file && | |
254 | EDITOR=./editor git commit --no-edit --amend && | |
255 | git diff --exit-code HEAD -- file && | |
256 | git diff-tree -s --format=%s HEAD >msg && | |
257 | test_cmp expect msg | |
258 | ' | |
259 | ||
260 | test_expect_success '--amend --edit' ' | |
261 | echo amended >expect && | |
262 | git commit --allow-empty -m "unamended" && | |
263 | echo bongo again >file && | |
264 | git add file && | |
265 | EDITOR=./editor git commit --edit --amend && | |
266 | git diff-tree -s --format=%s HEAD >msg && | |
267 | test_cmp expect msg | |
268 | ' | |
269 | ||
d9a93575 CW |
270 | test_expect_success '--amend --edit of empty message' ' |
271 | cat >replace <<-\EOF && | |
272 | #!/bin/sh | |
273 | echo "amended" >"$1" | |
274 | EOF | |
275 | chmod 755 replace && | |
276 | git commit --allow-empty --allow-empty-message -m "" && | |
277 | echo more bongo >file && | |
278 | git add file && | |
279 | EDITOR=./replace git commit --edit --amend && | |
280 | git diff-tree -s --format=%s HEAD >msg && | |
281 | ./replace expect && | |
282 | test_cmp expect msg | |
283 | ' | |
284 | ||
27014cbc JK |
285 | test_expect_success '--amend to set message to empty' ' |
286 | echo bata >file && | |
178e8143 AD |
287 | git add file && |
288 | git commit -m "unamended" && | |
289 | git commit --amend --allow-empty-message -m "" && | |
290 | git diff-tree -s --format=%s HEAD >msg && | |
291 | echo "" >expect && | |
292 | test_cmp expect msg | |
293 | ' | |
294 | ||
27014cbc | 295 | test_expect_success '--amend to set empty message needs --allow-empty-message' ' |
178e8143 AD |
296 | echo conga >file && |
297 | git add file && | |
298 | git commit -m "unamended" && | |
299 | test_must_fail git commit --amend -m "" && | |
300 | git diff-tree -s --format=%s HEAD >msg && | |
301 | echo "unamended" >expect && | |
302 | test_cmp expect msg | |
303 | ' | |
304 | ||
bc821899 JN |
305 | test_expect_success '-m --edit' ' |
306 | echo amended >expect && | |
307 | git commit --allow-empty -m buffer && | |
308 | echo bongo bongo >file && | |
309 | git add file && | |
310 | EDITOR=./editor git commit -m unamended --edit && | |
311 | git diff-tree -s --format=%s HEAD >msg && | |
312 | test_cmp expect msg | |
313 | ' | |
314 | ||
1af524eb JN |
315 | test_expect_success '-m and -F do not mix' ' |
316 | echo enough with the bongos >file && | |
317 | test_must_fail git commit -F msg -m amending . | |
318 | ' | |
319 | ||
320 | test_expect_success 'using message from other commit' ' | |
321 | git commit -C HEAD^ . | |
322 | ' | |
12ace0b2 | 323 | |
1af524eb JN |
324 | test_expect_success 'editing message from other commit' ' |
325 | cat >editor <<-\EOF && | |
326 | #!/bin/sh | |
38c1aa01 | 327 | sed -e "s/amend/older/g" <"$1" >"$1-" |
1af524eb JN |
328 | mv "$1-" "$1" |
329 | EOF | |
330 | chmod 755 editor && | |
331 | echo hula hula >file && | |
332 | EDITOR=./editor git commit -c HEAD^ -a | |
333 | ' | |
12ace0b2 | 334 | |
1af524eb JN |
335 | test_expect_success 'message from stdin' ' |
336 | echo silly new contents >file && | |
337 | echo commit message from stdin | | |
338 | git commit -F - -a | |
339 | ' | |
12ace0b2 | 340 | |
1af524eb JN |
341 | test_expect_success 'overriding author from command line' ' |
342 | echo gak >file && | |
343 | git commit -m author \ | |
344 | --author "Rubber Duck <rduck@convoy.org>" -a >output 2>&1 && | |
345 | grep Rubber.Duck output | |
346 | ' | |
12ace0b2 | 347 | |
1af524eb | 348 | test_expect_success PERL 'interactive add' ' |
756ee7fc DL |
349 | echo 7 | test_must_fail git commit --interactive >out && |
350 | grep "What now" out | |
1af524eb JN |
351 | ' |
352 | ||
353 | test_expect_success PERL "commit --interactive doesn't change index if editor aborts" ' | |
354 | echo zoo >file && | |
02a481fc | 355 | test_must_fail git diff --exit-code >diff1 && |
0590ff26 | 356 | test_write_lines u "*" q | |
1af524eb JN |
357 | ( |
358 | EDITOR=: && | |
359 | export EDITOR && | |
360 | test_must_fail git commit --interactive | |
361 | ) && | |
02a481fc | 362 | git diff >diff2 && |
1af524eb JN |
363 | compare_diff_patch diff1 diff2 |
364 | ' | |
12ace0b2 | 365 | |
1af524eb JN |
366 | test_expect_success 'editor not invoked if -F is given' ' |
367 | cat >editor <<-\EOF && | |
368 | #!/bin/sh | |
369 | sed -e s/good/bad/g <"$1" >"$1-" | |
370 | mv "$1-" "$1" | |
371 | EOF | |
372 | chmod 755 editor && | |
373 | ||
374 | echo A good commit message. >msg && | |
375 | echo moo >file && | |
376 | ||
377 | EDITOR=./editor git commit -a -F msg && | |
378 | git show -s --pretty=format:%s >subject && | |
379 | grep -q good subject && | |
380 | ||
381 | echo quack >file && | |
382 | echo Another good message. | | |
383 | EDITOR=./editor git commit -a -F - && | |
384 | git show -s --pretty=format:%s >subject && | |
385 | grep -q good subject | |
386 | ' | |
12ace0b2 | 387 | |
db33af0a | 388 | test_expect_success 'partial commit that involves removal (1)' ' |
80bffaf7 JH |
389 | |
390 | git rm --cached file && | |
391 | mv file elif && | |
392 | git add elif && | |
393 | git commit -m "Partial: add elif" elif && | |
394 | git diff-tree --name-status HEAD^ HEAD >current && | |
395 | echo "A elif" >expected && | |
1e368681 | 396 | test_cmp expected current |
80bffaf7 JH |
397 | |
398 | ' | |
399 | ||
db33af0a | 400 | test_expect_success 'partial commit that involves removal (2)' ' |
80bffaf7 JH |
401 | |
402 | git commit -m "Partial: remove file" file && | |
403 | git diff-tree --name-status HEAD^ HEAD >current && | |
404 | echo "D file" >expected && | |
1e368681 | 405 | test_cmp expected current |
80bffaf7 JH |
406 | |
407 | ' | |
408 | ||
db33af0a JH |
409 | test_expect_success 'partial commit that involves removal (3)' ' |
410 | ||
411 | git rm --cached elif && | |
412 | echo elif >elif && | |
413 | git commit -m "Partial: modify elif" elif && | |
414 | git diff-tree --name-status HEAD^ HEAD >current && | |
415 | echo "M elif" >expected && | |
1e368681 | 416 | test_cmp expected current |
db33af0a JH |
417 | |
418 | ' | |
419 | ||
5aa5cd46 JH |
420 | test_expect_success 'amend commit to fix author' ' |
421 | ||
422 | oldtick=$GIT_AUTHOR_DATE && | |
423 | test_tick && | |
424 | git reset --hard && | |
756ee7fc | 425 | git cat-file -p HEAD >commit && |
5aa5cd46 | 426 | sed -e "s/author.*/author $author $oldtick/" \ |
756ee7fc DL |
427 | -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \ |
428 | commit >expected && | |
5aa5cd46 | 429 | git commit --amend --author="$author" && |
38c1aa01 | 430 | git cat-file -p HEAD >current && |
1e368681 | 431 | test_cmp expected current |
5aa5cd46 JH |
432 | |
433 | ' | |
434 | ||
02b47cd7 MV |
435 | test_expect_success 'amend commit to fix date' ' |
436 | ||
437 | test_tick && | |
438 | newtick=$GIT_AUTHOR_DATE && | |
439 | git reset --hard && | |
756ee7fc | 440 | git cat-file -p HEAD >commit && |
02b47cd7 | 441 | sed -e "s/author.*/author $author $newtick/" \ |
756ee7fc DL |
442 | -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \ |
443 | commit >expected && | |
02b47cd7 | 444 | git commit --amend --date="$newtick" && |
38c1aa01 | 445 | git cat-file -p HEAD >current && |
02b47cd7 MV |
446 | test_cmp expected current |
447 | ||
448 | ' | |
449 | ||
cab11f4e GT |
450 | test_expect_success 'amend commit to add signoff' ' |
451 | ||
452 | test_commit "msg" file content && | |
453 | git commit --amend --signoff && | |
454 | test_commit_message HEAD <<-EOF | |
455 | msg | |
456 | ||
457 | Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> | |
458 | EOF | |
459 | ' | |
460 | ||
461 | test_expect_success 'amend does not add signoff if it already exists' ' | |
462 | ||
463 | test_commit --signoff "tenor" file newcontent && | |
464 | git commit --amend --signoff && | |
465 | test_commit_message HEAD <<-EOF | |
466 | tenor | |
467 | ||
468 | Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> | |
469 | EOF | |
470 | ' | |
471 | ||
b7242b8c JK |
472 | test_expect_success 'commit mentions forced date in output' ' |
473 | git commit --amend --date=2010-01-02T03:04:05 >output && | |
474 | grep "Date: *Sat Jan 2 03:04:05 2010" output | |
475 | ' | |
476 | ||
14ac2864 JK |
477 | test_expect_success 'commit complains about completely bogus dates' ' |
478 | test_must_fail git commit --amend --date=seventeen | |
479 | ' | |
480 | ||
481 | test_expect_success 'commit --date allows approxidate' ' | |
482 | git commit --amend \ | |
483 | --date="midnight the 12th of october, anno domini 1979" && | |
484 | echo "Fri Oct 12 00:00:00 1979 +0000" >expect && | |
485 | git log -1 --format=%ad >actual && | |
486 | test_cmp expect actual | |
4579bb41 JK |
487 | ' |
488 | ||
5aa5cd46 JH |
489 | test_expect_success 'sign off (1)' ' |
490 | ||
491 | echo 1 >positive && | |
492 | git add positive && | |
493 | git commit -s -m "thank you" && | |
756ee7fc DL |
494 | git cat-file commit HEAD >commit && |
495 | sed -e "1,/^\$/d" commit >actual && | |
5aa5cd46 | 496 | ( |
e974e06d ES |
497 | echo thank you && |
498 | echo && | |
756ee7fc DL |
499 | git var GIT_COMMITTER_IDENT >ident && |
500 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident | |
5aa5cd46 | 501 | ) >expected && |
82ebb0b6 | 502 | test_cmp expected actual |
5aa5cd46 JH |
503 | |
504 | ' | |
505 | ||
506 | test_expect_success 'sign off (2)' ' | |
507 | ||
508 | echo 2 >positive && | |
509 | git add positive && | |
510 | existing="Signed-off-by: Watch This <watchthis@example.com>" && | |
511 | git commit -s -m "thank you | |
512 | ||
513 | $existing" && | |
756ee7fc DL |
514 | git cat-file commit HEAD >commit && |
515 | sed -e "1,/^\$/d" commit >actual && | |
5aa5cd46 | 516 | ( |
e974e06d ES |
517 | echo thank you && |
518 | echo && | |
519 | echo $existing && | |
756ee7fc DL |
520 | git var GIT_COMMITTER_IDENT >ident && |
521 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident | |
5aa5cd46 | 522 | ) >expected && |
82ebb0b6 | 523 | test_cmp expected actual |
5aa5cd46 JH |
524 | |
525 | ' | |
526 | ||
c1e01b0c DB |
527 | test_expect_success 'signoff gap' ' |
528 | ||
529 | echo 3 >positive && | |
530 | git add positive && | |
531 | alt="Alt-RFC-822-Header: Value" && | |
532 | git commit -s -m "welcome | |
533 | ||
534 | $alt" && | |
756ee7fc DL |
535 | git cat-file commit HEAD >commit && |
536 | sed -e "1,/^\$/d" commit >actual && | |
c1e01b0c | 537 | ( |
e974e06d ES |
538 | echo welcome && |
539 | echo && | |
540 | echo $alt && | |
756ee7fc DL |
541 | git var GIT_COMMITTER_IDENT >ident && |
542 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident | |
c1e01b0c DB |
543 | ) >expected && |
544 | test_cmp expected actual | |
545 | ' | |
546 | ||
547 | test_expect_success 'signoff gap 2' ' | |
548 | ||
549 | echo 4 >positive && | |
550 | git add positive && | |
551 | alt="fixed: 34" && | |
552 | git commit -s -m "welcome | |
553 | ||
554 | We have now | |
555 | $alt" && | |
756ee7fc DL |
556 | git cat-file commit HEAD >commit && |
557 | sed -e "1,/^\$/d" commit >actual && | |
c1e01b0c | 558 | ( |
e974e06d ES |
559 | echo welcome && |
560 | echo && | |
561 | echo We have now && | |
562 | echo $alt && | |
563 | echo && | |
756ee7fc DL |
564 | git var GIT_COMMITTER_IDENT >ident && |
565 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident | |
c1e01b0c DB |
566 | ) >expected && |
567 | test_cmp expected actual | |
568 | ' | |
569 | ||
967dfd4d JT |
570 | test_expect_success 'signoff respects trailer config' ' |
571 | ||
572 | echo 5 >positive && | |
573 | git add positive && | |
574 | git commit -s -m "subject | |
575 | ||
576 | non-trailer line | |
577 | Myfooter: x" && | |
756ee7fc DL |
578 | git cat-file commit HEAD >commit && |
579 | sed -e "1,/^\$/d" commit >actual && | |
967dfd4d | 580 | ( |
e974e06d ES |
581 | echo subject && |
582 | echo && | |
583 | echo non-trailer line && | |
584 | echo Myfooter: x && | |
585 | echo && | |
967dfd4d JT |
586 | echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" |
587 | ) >expected && | |
588 | test_cmp expected actual && | |
589 | ||
590 | echo 6 >positive && | |
591 | git add positive && | |
592 | git -c "trailer.Myfooter.ifexists=add" commit -s -m "subject | |
593 | ||
594 | non-trailer line | |
595 | Myfooter: x" && | |
756ee7fc DL |
596 | git cat-file commit HEAD >commit && |
597 | sed -e "1,/^\$/d" commit >actual && | |
967dfd4d | 598 | ( |
e974e06d ES |
599 | echo subject && |
600 | echo && | |
601 | echo non-trailer line && | |
602 | echo Myfooter: x && | |
967dfd4d JT |
603 | echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" |
604 | ) >expected && | |
605 | test_cmp expected actual | |
606 | ' | |
607 | ||
ffce7f59 JK |
608 | test_expect_success 'signoff not confused by ---' ' |
609 | cat >expected <<-EOF && | |
610 | subject | |
611 | ||
612 | body | |
613 | --- | |
614 | these dashes confuse the parser! | |
615 | ||
616 | Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> | |
617 | EOF | |
618 | # should be a noop, since we already signed | |
619 | git commit --allow-empty --signoff -F expected && | |
620 | git log -1 --pretty=format:%B >actual && | |
621 | test_cmp expected actual | |
622 | ' | |
623 | ||
5aa5cd46 JH |
624 | test_expect_success 'multiple -m' ' |
625 | ||
626 | >negative && | |
627 | git add negative && | |
628 | git commit -m "one" -m "two" -m "three" && | |
756ee7fc DL |
629 | git cat-file commit HEAD >commit && |
630 | sed -e "1,/^\$/d" commit >actual && | |
5aa5cd46 | 631 | ( |
e974e06d ES |
632 | echo one && |
633 | echo && | |
634 | echo two && | |
635 | echo && | |
5aa5cd46 JH |
636 | echo three |
637 | ) >expected && | |
82ebb0b6 | 638 | test_cmp expected actual |
5aa5cd46 JH |
639 | |
640 | ' | |
641 | ||
d63c2fd1 KH |
642 | test_expect_success 'amend commit to fix author' ' |
643 | ||
644 | oldtick=$GIT_AUTHOR_DATE && | |
645 | test_tick && | |
646 | git reset --hard && | |
756ee7fc | 647 | git cat-file -p HEAD >commit && |
d63c2fd1 | 648 | sed -e "s/author.*/author $author $oldtick/" \ |
756ee7fc DL |
649 | -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \ |
650 | commit >expected && | |
d63c2fd1 | 651 | git commit --amend --author="$author" && |
38c1aa01 | 652 | git cat-file -p HEAD >current && |
1e368681 | 653 | test_cmp expected current |
d63c2fd1 KH |
654 | |
655 | ' | |
1200993a KH |
656 | |
657 | test_expect_success 'git commit <file> with dirty index' ' | |
38c1aa01 DL |
658 | echo tacocat >elif && |
659 | echo tehlulz >chz && | |
1200993a KH |
660 | git add chz && |
661 | git commit elif -m "tacocat is a palindrome" && | |
756ee7fc DL |
662 | git show --stat >stat && |
663 | grep elif stat && | |
664 | git diff --cached >diff && | |
665 | grep chz diff | |
1200993a KH |
666 | ' |
667 | ||
13aba1e5 JS |
668 | test_expect_success 'same tree (single parent)' ' |
669 | ||
1af524eb JN |
670 | git reset --hard && |
671 | test_must_fail git commit -m empty | |
13aba1e5 JS |
672 | |
673 | ' | |
674 | ||
36863af1 JH |
675 | test_expect_success 'same tree (single parent) --allow-empty' ' |
676 | ||
677 | git commit --allow-empty -m "forced empty" && | |
756ee7fc DL |
678 | git cat-file commit HEAD >commit && |
679 | grep forced commit | |
36863af1 JH |
680 | |
681 | ' | |
682 | ||
13aba1e5 JS |
683 | test_expect_success 'same tree (merge and amend merge)' ' |
684 | ||
685 | git checkout -b side HEAD^ && | |
686 | echo zero >zero && | |
687 | git add zero && | |
688 | git commit -m "add zero" && | |
1e2ae142 | 689 | git checkout main && |
13aba1e5 JS |
690 | |
691 | git merge -s ours side -m "empty ok" && | |
692 | git diff HEAD^ HEAD >actual && | |
1c5e94f4 | 693 | test_must_be_empty actual && |
13aba1e5 JS |
694 | |
695 | git commit --amend -m "empty really ok" && | |
696 | git diff HEAD^ HEAD >actual && | |
1c5e94f4 | 697 | test_must_be_empty actual |
13aba1e5 JS |
698 | |
699 | ' | |
700 | ||
1eb1e9ee JH |
701 | test_expect_success 'amend using the message from another commit' ' |
702 | ||
703 | git reset --hard && | |
704 | test_tick && | |
705 | git commit --allow-empty -m "old commit" && | |
706 | old=$(git rev-parse --verify HEAD) && | |
707 | test_tick && | |
708 | git commit --allow-empty -m "new commit" && | |
709 | new=$(git rev-parse --verify HEAD) && | |
710 | test_tick && | |
711 | git commit --allow-empty --amend -C "$old" && | |
712 | git show --pretty="format:%ad %s" "$old" >expected && | |
713 | git show --pretty="format:%ad %s" HEAD >actual && | |
82ebb0b6 | 714 | test_cmp expected actual |
1eb1e9ee JH |
715 | |
716 | ' | |
717 | ||
8a2f8733 JH |
718 | test_expect_success 'amend using the message from a commit named with tag' ' |
719 | ||
720 | git reset --hard && | |
721 | test_tick && | |
722 | git commit --allow-empty -m "old commit" && | |
723 | old=$(git rev-parse --verify HEAD) && | |
724 | git tag -a -m "tag on old" tagged-old HEAD && | |
725 | test_tick && | |
726 | git commit --allow-empty -m "new commit" && | |
727 | new=$(git rev-parse --verify HEAD) && | |
728 | test_tick && | |
729 | git commit --allow-empty --amend -C tagged-old && | |
730 | git show --pretty="format:%ad %s" "$old" >expected && | |
731 | git show --pretty="format:%ad %s" HEAD >actual && | |
82ebb0b6 | 732 | test_cmp expected actual |
8a2f8733 JH |
733 | |
734 | ' | |
735 | ||
6360d343 TR |
736 | test_expect_success 'amend can copy notes' ' |
737 | ||
738 | git config notes.rewrite.amend true && | |
739 | git config notes.rewriteRef "refs/notes/*" && | |
740 | test_commit foo && | |
741 | git notes add -m"a note" && | |
742 | test_tick && | |
743 | git commit --amend -m"new foo" && | |
744 | test "$(git notes show)" = "a note" | |
745 | ||
746 | ' | |
747 | ||
4682d852 JH |
748 | test_expect_success 'commit a file whose name is a dash' ' |
749 | git reset --hard && | |
08495412 | 750 | test_write_lines 1 2 3 4 5 >./- && |
4682d852 JH |
751 | git add ./- && |
752 | test_tick && | |
753 | git commit -m "add dash" >output </dev/null && | |
6789275d | 754 | test_grep " changed, 5 insertions" output |
4682d852 JH |
755 | ' |
756 | ||
f0c73200 TR |
757 | test_expect_success '--only works on to-be-born branch' ' |
758 | # This test relies on having something in the index, as it | |
759 | # would not otherwise actually prove much. So check this. | |
760 | test -n "$(git ls-files)" && | |
761 | git checkout --orphan orphan && | |
762 | echo foo >newfile && | |
763 | git add newfile && | |
764 | git commit --only newfile -m"--only on unborn branch" && | |
765 | echo newfile >expected && | |
766 | git ls-tree -r --name-only HEAD >actual && | |
767 | test_cmp expected actual | |
768 | ' | |
769 | ||
8dc874b2 SS |
770 | test_expect_success '--dry-run with conflicts fixed from a merge' ' |
771 | # setup two branches with conflicting information | |
772 | # in the same file, resolve the conflict, | |
773 | # call commit with --dry-run | |
774 | echo "Initial contents, unimportant" >test-file && | |
775 | git add test-file && | |
776 | git commit -m "Initial commit" && | |
777 | echo "commit-1-state" >test-file && | |
778 | git commit -m "commit 1" -i test-file && | |
779 | git tag commit-1 && | |
780 | git checkout -b branch-2 HEAD^1 && | |
781 | echo "commit-2-state" >test-file && | |
782 | git commit -m "commit 2" -i test-file && | |
15da7537 | 783 | test_must_fail git merge --no-commit commit-1 && |
8dc874b2 SS |
784 | echo "commit-2-state" >test-file && |
785 | git add test-file && | |
786 | git commit --dry-run && | |
787 | git commit -m "conflicts fixed from merge." | |
788 | ' | |
789 | ||
f3bd35fa | 790 | test_expect_success '--dry-run --short' ' |
8282f59f SS |
791 | >test-file && |
792 | git add test-file && | |
793 | git commit --dry-run --short | |
794 | ' | |
795 | ||
12ace0b2 | 796 | test_done |