3 # Copyright (c) 2007 Kristian Høgsberg <krh@redhat.com>
6 # FIXME: Test the various index usages, -i and -o, test reflog,
9 test_description='git commit'
11 . "$TEST_DIRECTORY/diff-lib.sh"
13 author='The Real Author <someguy@his.email.org>'
17 test_expect_success 'initial status' '
18 echo bongo bongo >file &&
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' '
32 test_expect_success '-m and -F do not mix' '
33 test_must_fail git commit -m foo -m bar -F file
36 test_expect_success '-m and -C do not mix' '
37 test_must_fail git commit -C HEAD -m illegal
40 test_expect_success 'paths and -a do not mix' '
41 echo King of the bongo >file &&
42 test_must_fail git commit -m foo -a file
45 test_expect_success PERL 'can use paths with --interactive' '
46 echo bong-o-bong >file &&
47 # 2: update, 1:st path, that is all, 7: quit
48 ( echo 2; echo 1; echo; echo 7 ) |
49 git commit -m foo --interactive file &&
50 git reset --hard HEAD^
53 test_expect_success 'using invalid commit with -C' '
54 test_must_fail git commit -C bogus
57 test_expect_success 'nothing to commit' '
58 test_must_fail git commit -m initial
61 test_expect_success 'setup: non-initial commit' '
62 echo bongo bongo bongo >file &&
66 test_expect_success 'commit message from non-existing file' '
67 echo more bongo: bongo bongo bongo bongo >file &&
68 test_must_fail git commit -F gah -a
71 test_expect_success 'empty commit message' '
72 # Empty except stray tabs and spaces on a few lines.
73 sed -e "s/@//g" >msg <<-\EOF &&
79 test_must_fail git commit -F msg -a
82 test_expect_success 'setup: commit message from file' '
83 echo this is the commit message, coming from a file >msg &&
87 test_expect_success 'amend commit' '
88 cat >editor <<-\EOF &&
90 sed -e "s/a file/an amend commit/g" < "$1" > "$1-"
94 EDITOR=./editor git commit --amend
97 test_expect_success '-m and -F do not mix' '
98 echo enough with the bongos >file &&
99 test_must_fail git commit -F msg -m amending .
102 test_expect_success 'using message from other commit' '
103 git commit -C HEAD^ .
106 test_expect_success 'editing message from other commit' '
107 cat >editor <<-\EOF &&
109 sed -e "s/amend/older/g" < "$1" > "$1-"
113 echo hula hula >file &&
114 EDITOR=./editor git commit -c HEAD^ -a
117 test_expect_success 'message from stdin' '
118 echo silly new contents >file &&
119 echo commit message from stdin |
123 test_expect_success 'overriding author from command line' '
125 git commit -m author \
126 --author "Rubber Duck <rduck@convoy.org>" -a >output 2>&1 &&
127 grep Rubber.Duck output
130 test_expect_success PERL 'interactive add' '
132 git commit --interactive |
136 test_expect_success PERL "commit --interactive doesn't change index if editor aborts" '
138 test_must_fail git diff --exit-code >diff1 &&
139 (echo u ; echo "*" ; echo q) |
143 test_must_fail git commit --interactive
146 compare_diff_patch diff1 diff2
149 test_expect_success 'editor not invoked if -F is given' '
150 cat >editor <<-\EOF &&
152 sed -e s/good/bad/g <"$1" >"$1-"
157 echo A good commit message. >msg &&
160 EDITOR=./editor git commit -a -F msg &&
161 git show -s --pretty=format:%s >subject &&
162 grep -q good subject &&
165 echo Another good message. |
166 EDITOR=./editor git commit -a -F - &&
167 git show -s --pretty=format:%s >subject &&
171 test_expect_success 'partial commit that involves removal (1)' '
173 git rm --cached file &&
176 git commit -m "Partial: add elif" elif &&
177 git diff-tree --name-status HEAD^ HEAD >current &&
178 echo "A elif" >expected &&
179 test_cmp expected current
183 test_expect_success 'partial commit that involves removal (2)' '
185 git commit -m "Partial: remove file" file &&
186 git diff-tree --name-status HEAD^ HEAD >current &&
187 echo "D file" >expected &&
188 test_cmp expected current
192 test_expect_success 'partial commit that involves removal (3)' '
194 git rm --cached elif &&
196 git commit -m "Partial: modify elif" elif &&
197 git diff-tree --name-status HEAD^ HEAD >current &&
198 echo "M elif" >expected &&
199 test_cmp expected current
203 test_expect_success 'amend commit to fix author' '
205 oldtick=$GIT_AUTHOR_DATE &&
208 git cat-file -p HEAD |
209 sed -e "s/author.*/author $author $oldtick/" \
210 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
212 git commit --amend --author="$author" &&
213 git cat-file -p HEAD > current &&
214 test_cmp expected current
218 test_expect_success 'amend commit to fix date' '
221 newtick=$GIT_AUTHOR_DATE &&
223 git cat-file -p HEAD |
224 sed -e "s/author.*/author $author $newtick/" \
225 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
227 git commit --amend --date="$newtick" &&
228 git cat-file -p HEAD > current &&
229 test_cmp expected current
233 test_expect_success 'commit complains about bogus date' '
234 test_must_fail git commit --amend --date=10.11.2010
237 test_expect_success 'sign off (1)' '
241 git commit -s -m "thank you" &&
242 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
246 git var GIT_COMMITTER_IDENT |
247 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
249 test_cmp expected actual
253 test_expect_success 'sign off (2)' '
257 existing="Signed-off-by: Watch This <watchthis@example.com>" &&
258 git commit -s -m "thank you
261 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
266 git var GIT_COMMITTER_IDENT |
267 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
269 test_cmp expected actual
273 test_expect_success 'signoff gap' '
277 alt="Alt-RFC-822-Header: Value" &&
278 git commit -s -m "welcome
281 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
286 git var GIT_COMMITTER_IDENT |
287 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
289 test_cmp expected actual
292 test_expect_success 'signoff gap 2' '
297 git commit -s -m "welcome
301 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
308 git var GIT_COMMITTER_IDENT |
309 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
311 test_cmp expected actual
314 test_expect_success 'multiple -m' '
318 git commit -m "one" -m "two" -m "three" &&
319 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
327 test_cmp expected actual
331 test_expect_success 'amend commit to fix author' '
333 oldtick=$GIT_AUTHOR_DATE &&
336 git cat-file -p HEAD |
337 sed -e "s/author.*/author $author $oldtick/" \
338 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
340 git commit --amend --author="$author" &&
341 git cat-file -p HEAD > current &&
342 test_cmp expected current
346 test_expect_success 'git commit <file> with dirty index' '
347 echo tacocat > elif &&
348 echo tehlulz > chz &&
350 git commit elif -m "tacocat is a palindrome" &&
351 git show --stat | grep elif &&
352 git diff --cached | grep chz
355 test_expect_success 'same tree (single parent)' '
358 test_must_fail git commit -m empty
362 test_expect_success 'same tree (single parent) --allow-empty' '
364 git commit --allow-empty -m "forced empty" &&
365 git cat-file commit HEAD | grep forced
369 test_expect_success 'same tree (merge and amend merge)' '
371 git checkout -b side HEAD^ &&
374 git commit -m "add zero" &&
375 git checkout master &&
377 git merge -s ours side -m "empty ok" &&
378 git diff HEAD^ HEAD >actual &&
380 test_cmp expected actual &&
382 git commit --amend -m "empty really ok" &&
383 git diff HEAD^ HEAD >actual &&
385 test_cmp expected actual
389 test_expect_success 'amend using the message from another commit' '
393 git commit --allow-empty -m "old commit" &&
394 old=$(git rev-parse --verify HEAD) &&
396 git commit --allow-empty -m "new commit" &&
397 new=$(git rev-parse --verify HEAD) &&
399 git commit --allow-empty --amend -C "$old" &&
400 git show --pretty="format:%ad %s" "$old" >expected &&
401 git show --pretty="format:%ad %s" HEAD >actual &&
402 test_cmp expected actual
406 test_expect_success 'amend using the message from a commit named with tag' '
410 git commit --allow-empty -m "old commit" &&
411 old=$(git rev-parse --verify HEAD) &&
412 git tag -a -m "tag on old" tagged-old HEAD &&
414 git commit --allow-empty -m "new commit" &&
415 new=$(git rev-parse --verify HEAD) &&
417 git commit --allow-empty --amend -C tagged-old &&
418 git show --pretty="format:%ad %s" "$old" >expected &&
419 git show --pretty="format:%ad %s" HEAD >actual &&
420 test_cmp expected actual
424 test_expect_success 'amend can copy notes' '
426 git config notes.rewrite.amend true &&
427 git config notes.rewriteRef "refs/notes/*" &&
429 git notes add -m"a note" &&
431 git commit --amend -m"new foo" &&
432 test "$(git notes show)" = "a note"