config doc: remove confusion about relative GIT_DIR from FILES section
[git/debian/pape.git] / t / t7501-commit.sh
blobb20ca0eace9dd8f9a11227ebfb932e0446278ea1
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 'set up editor' '
112 cat >editor <<-\EOF &&
113 #!/bin/sh
114 sed -e "s/unamended/amended/g" <"$1" >"$1-"
115 mv "$1-" "$1"
117 chmod 755 editor
120 test_expect_success 'amend without launching editor' '
121 echo unamended >expect &&
122 git commit --allow-empty -m "unamended" &&
123 echo needs more bongo >file &&
124 git add file &&
125 EDITOR=./editor git commit --no-edit --amend &&
126 git diff --exit-code HEAD -- file &&
127 git diff-tree -s --format=%s HEAD >msg &&
128 test_cmp expect msg
131 test_expect_success '--amend --edit' '
132 echo amended >expect &&
133 git commit --allow-empty -m "unamended" &&
134 echo bongo again >file &&
135 git add file &&
136 EDITOR=./editor git commit --edit --amend &&
137 git diff-tree -s --format=%s HEAD >msg &&
138 test_cmp expect msg
141 test_expect_success '-m --edit' '
142 echo amended >expect &&
143 git commit --allow-empty -m buffer &&
144 echo bongo bongo >file &&
145 git add file &&
146 EDITOR=./editor git commit -m unamended --edit &&
147 git diff-tree -s --format=%s HEAD >msg &&
148 test_cmp expect msg
151 test_expect_success '-m and -F do not mix' '
152 echo enough with the bongos >file &&
153 test_must_fail git commit -F msg -m amending .
156 test_expect_success 'using message from other commit' '
157 git commit -C HEAD^ .
160 test_expect_success 'editing message from other commit' '
161 cat >editor <<-\EOF &&
162 #!/bin/sh
163 sed -e "s/amend/older/g" < "$1" > "$1-"
164 mv "$1-" "$1"
166 chmod 755 editor &&
167 echo hula hula >file &&
168 EDITOR=./editor git commit -c HEAD^ -a
171 test_expect_success 'message from stdin' '
172 echo silly new contents >file &&
173 echo commit message from stdin |
174 git commit -F - -a
177 test_expect_success 'overriding author from command line' '
178 echo gak >file &&
179 git commit -m author \
180 --author "Rubber Duck <rduck@convoy.org>" -a >output 2>&1 &&
181 grep Rubber.Duck output
184 test_expect_success PERL 'interactive add' '
185 echo 7 |
186 git commit --interactive |
187 grep "What now"
190 test_expect_success PERL "commit --interactive doesn't change index if editor aborts" '
191 echo zoo >file &&
192 test_must_fail git diff --exit-code >diff1 &&
193 (echo u ; echo "*" ; echo q) |
195 EDITOR=: &&
196 export EDITOR &&
197 test_must_fail git commit --interactive
198 ) &&
199 git diff >diff2 &&
200 compare_diff_patch diff1 diff2
203 test_expect_success 'editor not invoked if -F is given' '
204 cat >editor <<-\EOF &&
205 #!/bin/sh
206 sed -e s/good/bad/g <"$1" >"$1-"
207 mv "$1-" "$1"
209 chmod 755 editor &&
211 echo A good commit message. >msg &&
212 echo moo >file &&
214 EDITOR=./editor git commit -a -F msg &&
215 git show -s --pretty=format:%s >subject &&
216 grep -q good subject &&
218 echo quack >file &&
219 echo Another good message. |
220 EDITOR=./editor git commit -a -F - &&
221 git show -s --pretty=format:%s >subject &&
222 grep -q good subject
225 test_expect_success 'partial commit that involves removal (1)' '
227 git rm --cached file &&
228 mv file elif &&
229 git add elif &&
230 git commit -m "Partial: add elif" elif &&
231 git diff-tree --name-status HEAD^ HEAD >current &&
232 echo "A elif" >expected &&
233 test_cmp expected current
237 test_expect_success 'partial commit that involves removal (2)' '
239 git commit -m "Partial: remove file" file &&
240 git diff-tree --name-status HEAD^ HEAD >current &&
241 echo "D file" >expected &&
242 test_cmp expected current
246 test_expect_success 'partial commit that involves removal (3)' '
248 git rm --cached elif &&
249 echo elif >elif &&
250 git commit -m "Partial: modify elif" elif &&
251 git diff-tree --name-status HEAD^ HEAD >current &&
252 echo "M elif" >expected &&
253 test_cmp expected current
257 test_expect_success 'amend commit to fix author' '
259 oldtick=$GIT_AUTHOR_DATE &&
260 test_tick &&
261 git reset --hard &&
262 git cat-file -p HEAD |
263 sed -e "s/author.*/author $author $oldtick/" \
264 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
265 expected &&
266 git commit --amend --author="$author" &&
267 git cat-file -p HEAD > current &&
268 test_cmp expected current
272 test_expect_success 'amend commit to fix date' '
274 test_tick &&
275 newtick=$GIT_AUTHOR_DATE &&
276 git reset --hard &&
277 git cat-file -p HEAD |
278 sed -e "s/author.*/author $author $newtick/" \
279 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
280 expected &&
281 git commit --amend --date="$newtick" &&
282 git cat-file -p HEAD > current &&
283 test_cmp expected current
287 test_expect_success 'commit complains about bogus date' '
288 test_must_fail git commit --amend --date=10.11.2010
291 test_expect_success 'sign off (1)' '
293 echo 1 >positive &&
294 git add positive &&
295 git commit -s -m "thank you" &&
296 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
298 echo thank you
299 echo
300 git var GIT_COMMITTER_IDENT |
301 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
302 ) >expected &&
303 test_cmp expected actual
307 test_expect_success 'sign off (2)' '
309 echo 2 >positive &&
310 git add positive &&
311 existing="Signed-off-by: Watch This <watchthis@example.com>" &&
312 git commit -s -m "thank you
314 $existing" &&
315 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
317 echo thank you
318 echo
319 echo $existing
320 git var GIT_COMMITTER_IDENT |
321 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
322 ) >expected &&
323 test_cmp expected actual
327 test_expect_success 'signoff gap' '
329 echo 3 >positive &&
330 git add positive &&
331 alt="Alt-RFC-822-Header: Value" &&
332 git commit -s -m "welcome
334 $alt" &&
335 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
337 echo welcome
338 echo
339 echo $alt
340 git var GIT_COMMITTER_IDENT |
341 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
342 ) >expected &&
343 test_cmp expected actual
346 test_expect_success 'signoff gap 2' '
348 echo 4 >positive &&
349 git add positive &&
350 alt="fixed: 34" &&
351 git commit -s -m "welcome
353 We have now
354 $alt" &&
355 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
357 echo welcome
358 echo
359 echo We have now
360 echo $alt
361 echo
362 git var GIT_COMMITTER_IDENT |
363 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
364 ) >expected &&
365 test_cmp expected actual
368 test_expect_success 'multiple -m' '
370 >negative &&
371 git add negative &&
372 git commit -m "one" -m "two" -m "three" &&
373 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
375 echo one
376 echo
377 echo two
378 echo
379 echo three
380 ) >expected &&
381 test_cmp expected actual
385 test_expect_success 'amend commit to fix author' '
387 oldtick=$GIT_AUTHOR_DATE &&
388 test_tick &&
389 git reset --hard &&
390 git cat-file -p HEAD |
391 sed -e "s/author.*/author $author $oldtick/" \
392 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
393 expected &&
394 git commit --amend --author="$author" &&
395 git cat-file -p HEAD > current &&
396 test_cmp expected current
400 test_expect_success 'git commit <file> with dirty index' '
401 echo tacocat > elif &&
402 echo tehlulz > chz &&
403 git add chz &&
404 git commit elif -m "tacocat is a palindrome" &&
405 git show --stat | grep elif &&
406 git diff --cached | grep chz
409 test_expect_success 'same tree (single parent)' '
411 git reset --hard &&
412 test_must_fail git commit -m empty
416 test_expect_success 'same tree (single parent) --allow-empty' '
418 git commit --allow-empty -m "forced empty" &&
419 git cat-file commit HEAD | grep forced
423 test_expect_success 'same tree (merge and amend merge)' '
425 git checkout -b side HEAD^ &&
426 echo zero >zero &&
427 git add zero &&
428 git commit -m "add zero" &&
429 git checkout master &&
431 git merge -s ours side -m "empty ok" &&
432 git diff HEAD^ HEAD >actual &&
433 : >expected &&
434 test_cmp expected actual &&
436 git commit --amend -m "empty really ok" &&
437 git diff HEAD^ HEAD >actual &&
438 : >expected &&
439 test_cmp expected actual
443 test_expect_success 'amend using the message from another commit' '
445 git reset --hard &&
446 test_tick &&
447 git commit --allow-empty -m "old commit" &&
448 old=$(git rev-parse --verify HEAD) &&
449 test_tick &&
450 git commit --allow-empty -m "new commit" &&
451 new=$(git rev-parse --verify HEAD) &&
452 test_tick &&
453 git commit --allow-empty --amend -C "$old" &&
454 git show --pretty="format:%ad %s" "$old" >expected &&
455 git show --pretty="format:%ad %s" HEAD >actual &&
456 test_cmp expected actual
460 test_expect_success 'amend using the message from a commit named with tag' '
462 git reset --hard &&
463 test_tick &&
464 git commit --allow-empty -m "old commit" &&
465 old=$(git rev-parse --verify HEAD) &&
466 git tag -a -m "tag on old" tagged-old HEAD &&
467 test_tick &&
468 git commit --allow-empty -m "new commit" &&
469 new=$(git rev-parse --verify HEAD) &&
470 test_tick &&
471 git commit --allow-empty --amend -C tagged-old &&
472 git show --pretty="format:%ad %s" "$old" >expected &&
473 git show --pretty="format:%ad %s" HEAD >actual &&
474 test_cmp expected actual
478 test_expect_success 'amend can copy notes' '
480 git config notes.rewrite.amend true &&
481 git config notes.rewriteRef "refs/notes/*" &&
482 test_commit foo &&
483 git notes add -m"a note" &&
484 test_tick &&
485 git commit --amend -m"new foo" &&
486 test "$(git notes show)" = "a note"
490 test_done