Update dtaft release notes to 1.8.3
[git/jnareb-git.git] / t / t7501-commit.sh
blob195e7477d883f39d51f5740b5b309a489dd92d3d
1 #!/bin/sh
3 # Copyright (c) 2007 Kristian Høgsberg <krh@redhat.com>
6 # FIXME: Test the various index usages, -i and -o, test reflog,
7 # signoff
9 test_description='git commit'
10 . ./test-lib.sh
11 . "$TEST_DIRECTORY/diff-lib.sh"
13 author='The Real Author <someguy@his.email.org>'
15 test_tick
17 test_expect_success 'initial status' '
18 echo bongo bongo >file &&
19 git add file &&
20 git status >actual &&
21 test_i18ngrep "Initial commit" actual
24 test_expect_success 'fail initial amend' '
25 test_must_fail git commit --amend
28 test_expect_success 'setup: initial commit' '
29 git commit -m initial
32 test_expect_success '-m and -F do not mix' '
33 git checkout HEAD file && echo >>file && git add file &&
34 test_must_fail git commit -m foo -m bar -F file
37 test_expect_success '-m and -C do not mix' '
38 git checkout HEAD file && echo >>file && git add file &&
39 test_must_fail git commit -C HEAD -m illegal
42 test_expect_success 'paths and -a do not mix' '
43 echo King of the bongo >file &&
44 test_must_fail git commit -m foo -a file
47 test_expect_success PERL 'can use paths with --interactive' '
48 echo bong-o-bong >file &&
49 # 2: update, 1:st path, that is all, 7: quit
50 ( echo 2; echo 1; echo; echo 7 ) |
51 git commit -m foo --interactive file &&
52 git reset --hard HEAD^
55 test_expect_success 'using invalid commit with -C' '
56 test_must_fail git commit -C bogus
59 test_expect_success 'nothing to commit' '
60 test_must_fail git commit -m initial
63 test_expect_success 'setup: non-initial commit' '
64 echo bongo bongo bongo >file &&
65 git commit -m next -a
68 test_expect_success 'commit message from non-existing file' '
69 echo more bongo: bongo bongo bongo bongo >file &&
70 test_must_fail git commit -F gah -a
73 test_expect_success 'empty commit message' '
74 # Empty except stray tabs and spaces on a few lines.
75 sed -e "s/@//g" >msg <<-\EOF &&
76 @ @
78 @ @
79 @Signed-off-by: hula@
80 EOF
81 test_must_fail git commit -F msg -a
84 test_expect_success 'template "emptyness" check does not kick in with -F' '
85 git checkout HEAD file && echo >>file && git add file &&
86 git commit -t file -F file
89 test_expect_success 'template "emptyness" check' '
90 git checkout HEAD file && echo >>file && git add file &&
91 test_must_fail git commit -t file 2>err &&
92 test_i18ngrep "did not edit" err
95 test_expect_success 'setup: commit message from file' '
96 git checkout HEAD file && echo >>file && git add file &&
97 echo this is the commit message, coming from a file >msg &&
98 git commit -F msg -a
101 test_expect_success 'amend commit' '
102 cat >editor <<-\EOF &&
103 #!/bin/sh
104 sed -e "s/a file/an amend commit/g" < "$1" > "$1-"
105 mv "$1-" "$1"
107 chmod 755 editor &&
108 EDITOR=./editor git commit --amend
111 test_expect_success 'amend --only ignores staged contents' '
112 cp file file.expect &&
113 echo changed >file &&
114 git add file &&
115 git commit --no-edit --amend --only &&
116 git cat-file blob HEAD:file >file.actual &&
117 test_cmp file.expect file.actual &&
118 git diff --exit-code
121 test_expect_success 'set up editor' '
122 cat >editor <<-\EOF &&
123 #!/bin/sh
124 sed -e "s/unamended/amended/g" <"$1" >"$1-"
125 mv "$1-" "$1"
127 chmod 755 editor
130 test_expect_success 'amend without launching editor' '
131 echo unamended >expect &&
132 git commit --allow-empty -m "unamended" &&
133 echo needs more bongo >file &&
134 git add file &&
135 EDITOR=./editor git commit --no-edit --amend &&
136 git diff --exit-code HEAD -- file &&
137 git diff-tree -s --format=%s HEAD >msg &&
138 test_cmp expect msg
141 test_expect_success '--amend --edit' '
142 echo amended >expect &&
143 git commit --allow-empty -m "unamended" &&
144 echo bongo again >file &&
145 git add file &&
146 EDITOR=./editor git commit --edit --amend &&
147 git diff-tree -s --format=%s HEAD >msg &&
148 test_cmp expect msg
151 test_expect_success '--amend --edit of empty message' '
152 cat >replace <<-\EOF &&
153 #!/bin/sh
154 echo "amended" >"$1"
156 chmod 755 replace &&
157 git commit --allow-empty --allow-empty-message -m "" &&
158 echo more bongo >file &&
159 git add file &&
160 EDITOR=./replace git commit --edit --amend &&
161 git diff-tree -s --format=%s HEAD >msg &&
162 ./replace expect &&
163 test_cmp expect msg
166 test_expect_success '-m --edit' '
167 echo amended >expect &&
168 git commit --allow-empty -m buffer &&
169 echo bongo bongo >file &&
170 git add file &&
171 EDITOR=./editor git commit -m unamended --edit &&
172 git diff-tree -s --format=%s HEAD >msg &&
173 test_cmp expect msg
176 test_expect_success '-m and -F do not mix' '
177 echo enough with the bongos >file &&
178 test_must_fail git commit -F msg -m amending .
181 test_expect_success 'using message from other commit' '
182 git commit -C HEAD^ .
185 test_expect_success 'editing message from other commit' '
186 cat >editor <<-\EOF &&
187 #!/bin/sh
188 sed -e "s/amend/older/g" < "$1" > "$1-"
189 mv "$1-" "$1"
191 chmod 755 editor &&
192 echo hula hula >file &&
193 EDITOR=./editor git commit -c HEAD^ -a
196 test_expect_success 'message from stdin' '
197 echo silly new contents >file &&
198 echo commit message from stdin |
199 git commit -F - -a
202 test_expect_success 'overriding author from command line' '
203 echo gak >file &&
204 git commit -m author \
205 --author "Rubber Duck <rduck@convoy.org>" -a >output 2>&1 &&
206 grep Rubber.Duck output
209 test_expect_success PERL 'interactive add' '
210 echo 7 |
211 git commit --interactive |
212 grep "What now"
215 test_expect_success PERL "commit --interactive doesn't change index if editor aborts" '
216 echo zoo >file &&
217 test_must_fail git diff --exit-code >diff1 &&
218 (echo u ; echo "*" ; echo q) |
220 EDITOR=: &&
221 export EDITOR &&
222 test_must_fail git commit --interactive
223 ) &&
224 git diff >diff2 &&
225 compare_diff_patch diff1 diff2
228 test_expect_success 'editor not invoked if -F is given' '
229 cat >editor <<-\EOF &&
230 #!/bin/sh
231 sed -e s/good/bad/g <"$1" >"$1-"
232 mv "$1-" "$1"
234 chmod 755 editor &&
236 echo A good commit message. >msg &&
237 echo moo >file &&
239 EDITOR=./editor git commit -a -F msg &&
240 git show -s --pretty=format:%s >subject &&
241 grep -q good subject &&
243 echo quack >file &&
244 echo Another good message. |
245 EDITOR=./editor git commit -a -F - &&
246 git show -s --pretty=format:%s >subject &&
247 grep -q good subject
250 test_expect_success 'partial commit that involves removal (1)' '
252 git rm --cached file &&
253 mv file elif &&
254 git add elif &&
255 git commit -m "Partial: add elif" elif &&
256 git diff-tree --name-status HEAD^ HEAD >current &&
257 echo "A elif" >expected &&
258 test_cmp expected current
262 test_expect_success 'partial commit that involves removal (2)' '
264 git commit -m "Partial: remove file" file &&
265 git diff-tree --name-status HEAD^ HEAD >current &&
266 echo "D file" >expected &&
267 test_cmp expected current
271 test_expect_success 'partial commit that involves removal (3)' '
273 git rm --cached elif &&
274 echo elif >elif &&
275 git commit -m "Partial: modify elif" elif &&
276 git diff-tree --name-status HEAD^ HEAD >current &&
277 echo "M elif" >expected &&
278 test_cmp expected current
282 test_expect_success 'amend commit to fix author' '
284 oldtick=$GIT_AUTHOR_DATE &&
285 test_tick &&
286 git reset --hard &&
287 git cat-file -p HEAD |
288 sed -e "s/author.*/author $author $oldtick/" \
289 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
290 expected &&
291 git commit --amend --author="$author" &&
292 git cat-file -p HEAD > current &&
293 test_cmp expected current
297 test_expect_success 'amend commit to fix date' '
299 test_tick &&
300 newtick=$GIT_AUTHOR_DATE &&
301 git reset --hard &&
302 git cat-file -p HEAD |
303 sed -e "s/author.*/author $author $newtick/" \
304 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
305 expected &&
306 git commit --amend --date="$newtick" &&
307 git cat-file -p HEAD > current &&
308 test_cmp expected current
312 test_expect_success 'commit complains about bogus date' '
313 test_must_fail git commit --amend --date=10.11.2010
316 test_expect_success 'sign off (1)' '
318 echo 1 >positive &&
319 git add positive &&
320 git commit -s -m "thank you" &&
321 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
323 echo thank you
324 echo
325 git var GIT_COMMITTER_IDENT |
326 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
327 ) >expected &&
328 test_cmp expected actual
332 test_expect_success 'sign off (2)' '
334 echo 2 >positive &&
335 git add positive &&
336 existing="Signed-off-by: Watch This <watchthis@example.com>" &&
337 git commit -s -m "thank you
339 $existing" &&
340 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
342 echo thank you
343 echo
344 echo $existing
345 git var GIT_COMMITTER_IDENT |
346 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
347 ) >expected &&
348 test_cmp expected actual
352 test_expect_success 'signoff gap' '
354 echo 3 >positive &&
355 git add positive &&
356 alt="Alt-RFC-822-Header: Value" &&
357 git commit -s -m "welcome
359 $alt" &&
360 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
362 echo welcome
363 echo
364 echo $alt
365 git var GIT_COMMITTER_IDENT |
366 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
367 ) >expected &&
368 test_cmp expected actual
371 test_expect_success 'signoff gap 2' '
373 echo 4 >positive &&
374 git add positive &&
375 alt="fixed: 34" &&
376 git commit -s -m "welcome
378 We have now
379 $alt" &&
380 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
382 echo welcome
383 echo
384 echo We have now
385 echo $alt
386 echo
387 git var GIT_COMMITTER_IDENT |
388 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
389 ) >expected &&
390 test_cmp expected actual
393 test_expect_success 'multiple -m' '
395 >negative &&
396 git add negative &&
397 git commit -m "one" -m "two" -m "three" &&
398 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
400 echo one
401 echo
402 echo two
403 echo
404 echo three
405 ) >expected &&
406 test_cmp expected actual
410 test_expect_success 'amend commit to fix author' '
412 oldtick=$GIT_AUTHOR_DATE &&
413 test_tick &&
414 git reset --hard &&
415 git cat-file -p HEAD |
416 sed -e "s/author.*/author $author $oldtick/" \
417 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
418 expected &&
419 git commit --amend --author="$author" &&
420 git cat-file -p HEAD > current &&
421 test_cmp expected current
425 test_expect_success 'git commit <file> with dirty index' '
426 echo tacocat > elif &&
427 echo tehlulz > chz &&
428 git add chz &&
429 git commit elif -m "tacocat is a palindrome" &&
430 git show --stat | grep elif &&
431 git diff --cached | grep chz
434 test_expect_success 'same tree (single parent)' '
436 git reset --hard &&
437 test_must_fail git commit -m empty
441 test_expect_success 'same tree (single parent) --allow-empty' '
443 git commit --allow-empty -m "forced empty" &&
444 git cat-file commit HEAD | grep forced
448 test_expect_success 'same tree (merge and amend merge)' '
450 git checkout -b side HEAD^ &&
451 echo zero >zero &&
452 git add zero &&
453 git commit -m "add zero" &&
454 git checkout master &&
456 git merge -s ours side -m "empty ok" &&
457 git diff HEAD^ HEAD >actual &&
458 : >expected &&
459 test_cmp expected actual &&
461 git commit --amend -m "empty really ok" &&
462 git diff HEAD^ HEAD >actual &&
463 : >expected &&
464 test_cmp expected actual
468 test_expect_success 'amend using the message from another commit' '
470 git reset --hard &&
471 test_tick &&
472 git commit --allow-empty -m "old commit" &&
473 old=$(git rev-parse --verify HEAD) &&
474 test_tick &&
475 git commit --allow-empty -m "new commit" &&
476 new=$(git rev-parse --verify HEAD) &&
477 test_tick &&
478 git commit --allow-empty --amend -C "$old" &&
479 git show --pretty="format:%ad %s" "$old" >expected &&
480 git show --pretty="format:%ad %s" HEAD >actual &&
481 test_cmp expected actual
485 test_expect_success 'amend using the message from a commit named with tag' '
487 git reset --hard &&
488 test_tick &&
489 git commit --allow-empty -m "old commit" &&
490 old=$(git rev-parse --verify HEAD) &&
491 git tag -a -m "tag on old" tagged-old HEAD &&
492 test_tick &&
493 git commit --allow-empty -m "new commit" &&
494 new=$(git rev-parse --verify HEAD) &&
495 test_tick &&
496 git commit --allow-empty --amend -C tagged-old &&
497 git show --pretty="format:%ad %s" "$old" >expected &&
498 git show --pretty="format:%ad %s" HEAD >actual &&
499 test_cmp expected actual
503 test_expect_success 'amend can copy notes' '
505 git config notes.rewrite.amend true &&
506 git config notes.rewriteRef "refs/notes/*" &&
507 test_commit foo &&
508 git notes add -m"a note" &&
509 test_tick &&
510 git commit --amend -m"new foo" &&
511 test "$(git notes show)" = "a note"
515 test_expect_success 'commit a file whose name is a dash' '
516 git reset --hard &&
517 for i in 1 2 3 4 5
519 echo $i
520 done >./- &&
521 git add ./- &&
522 test_tick &&
523 git commit -m "add dash" >output </dev/null &&
524 test_i18ngrep " changed, 5 insertions" output
527 test_done