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'
16 "echo 'bongo bongo' >file &&
19 test_expect_success C_LOCALE_OUTPUT \
20 "Constructing initial commit" \
21 "git status | grep 'Initial commit'"
24 "fail initial amend" \
25 "test_must_fail git commit --amend"
29 "git commit -m initial"
33 "test_must_fail git commit -m foo -m bar -F file"
37 "test_must_fail git commit -C HEAD -m illegal"
40 "using paths with -a" \
41 "echo King of the bongo >file &&
42 test_must_fail git commit -m foo -a file"
44 test_expect_success PERL \
45 "using paths with --interactive" \
46 "echo bong-o-bong >file &&
47 ! (echo 7 | git commit -m foo --interactive file)"
50 "using invalid commit with -C" \
51 "test_must_fail git commit -C bogus"
54 "testing nothing to commit" \
55 "test_must_fail git commit -m initial"
59 "echo 'bongo bongo bongo' >file \
60 git commit -m next -a"
63 "commit message from non-existing file" \
64 "echo 'more bongo: bongo bongo bongo bongo' >file && \
65 test_must_fail git commit -F gah -a"
67 # Empty except stray tabs and spaces on a few lines.
68 sed -e 's/@$//' >msg
<<EOF
75 "empty commit message" \
76 "test_must_fail git commit -F msg -a"
79 "commit message from file" \
80 "echo 'this is the commit message, coming from a file' >msg && \
85 sed -e "s/a file/an amend commit/g" < "$1" > "$1-"
92 "EDITOR=./editor git commit --amend"
96 "echo 'enough with the bongos' >file && \
97 test_must_fail git commit -F msg -m amending ."
100 "using message from other commit" \
101 "git commit -C HEAD^ ."
105 sed -e "s/amend/older/g" < "$1" > "$1-"
110 test_expect_success \
111 "editing message from other commit" \
112 "echo 'hula hula' >file && \
113 EDITOR=./editor git commit -c HEAD^ -a"
115 test_expect_success \
116 "message from stdin" \
117 "echo 'silly new contents' >file && \
118 echo commit message from stdin | git commit -F - -a"
120 test_expect_success \
121 "overriding author from command line" \
122 "echo 'gak' >file && \
123 git commit -m 'author' --author 'Rubber Duck <rduck@convoy.org>' -a >output 2>&1"
125 test_expect_success \
126 "commit --author output mentions author" \
127 "grep Rubber.Duck output"
129 test_expect_success PERL \
131 "echo 7 | git commit --interactive | grep 'What now'"
133 test_expect_success \
134 "showing committed revisions" \
135 "git rev-list HEAD >current"
139 sed -e "s/good/bad/g" < "$1" > "$1-"
145 A good commit message.
148 test_expect_success \
149 'editor not invoked if -F is given' '
151 EDITOR=./editor git commit -a -F msg &&
152 git show -s --pretty=format:"%s" | grep -q good &&
153 echo "quack" >file &&
154 echo "Another good message." | EDITOR=./editor git commit -a -F - &&
155 git show -s --pretty=format:"%s" | grep -q good
157 # We could just check the head sha1, but checking each commit makes it
158 # easier to isolate bugs.
161 72c0dc9855b0c9dadcbfd5a31cab072e0cb774ca
162 9b88fc14ce6b32e3d9ee021531a54f18a5cf38a2
163 3536bbb352c3a1ef9a420f5b4242d48578b92aa7
164 d381ac431806e53f3dd7ac2f1ae0534f36d738b9
165 4fd44095ad6334f3ef72e4c5ec8ddf108174b54a
166 402702b49136e7587daa9280e91e4bb7cb2179f7
169 test_expect_success \
170 'validate git rev-list output.' \
171 'test_cmp expected current'
173 test_expect_success
'partial commit that involves removal (1)' '
175 git rm --cached file &&
178 git commit -m "Partial: add elif" elif &&
179 git diff-tree --name-status HEAD^ HEAD >current &&
180 echo "A elif" >expected &&
181 test_cmp expected current
185 test_expect_success
'partial commit that involves removal (2)' '
187 git commit -m "Partial: remove file" file &&
188 git diff-tree --name-status HEAD^ HEAD >current &&
189 echo "D file" >expected &&
190 test_cmp expected current
194 test_expect_success
'partial commit that involves removal (3)' '
196 git rm --cached elif &&
198 git commit -m "Partial: modify elif" elif &&
199 git diff-tree --name-status HEAD^ HEAD >current &&
200 echo "M elif" >expected &&
201 test_cmp expected current
205 author
="The Real Author <someguy@his.email.org>"
206 test_expect_success
'amend commit to fix author' '
208 oldtick=$GIT_AUTHOR_DATE &&
211 git cat-file -p HEAD |
212 sed -e "s/author.*/author $author $oldtick/" \
213 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
215 git commit --amend --author="$author" &&
216 git cat-file -p HEAD > current &&
217 test_cmp expected current
221 test_expect_success
'amend commit to fix date' '
224 newtick=$GIT_AUTHOR_DATE &&
226 git cat-file -p HEAD |
227 sed -e "s/author.*/author $author $newtick/" \
228 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
230 git commit --amend --date="$newtick" &&
231 git cat-file -p HEAD > current &&
232 test_cmp expected current
236 test_expect_success
'commit complains about bogus date' '
237 test_must_fail git commit --amend --date=10.11.2010
240 test_expect_success
'sign off (1)' '
244 git commit -s -m "thank you" &&
245 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
249 git var GIT_COMMITTER_IDENT |
250 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
252 test_cmp expected actual
256 test_expect_success
'sign off (2)' '
260 existing="Signed-off-by: Watch This <watchthis@example.com>" &&
261 git commit -s -m "thank you
264 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
269 git var GIT_COMMITTER_IDENT |
270 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
272 test_cmp expected actual
276 test_expect_success
'signoff gap' '
280 alt="Alt-RFC-822-Header: Value" &&
281 git commit -s -m "welcome
284 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
289 git var GIT_COMMITTER_IDENT |
290 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
292 test_cmp expected actual
295 test_expect_success
'signoff gap 2' '
300 git commit -s -m "welcome
304 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
311 git var GIT_COMMITTER_IDENT |
312 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
314 test_cmp expected actual
317 test_expect_success
'multiple -m' '
321 git commit -m "one" -m "two" -m "three" &&
322 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
330 test_cmp expected actual
334 author
="The Real Author <someguy@his.email.org>"
335 test_expect_success
'amend commit to fix author' '
337 oldtick=$GIT_AUTHOR_DATE &&
340 git cat-file -p HEAD |
341 sed -e "s/author.*/author $author $oldtick/" \
342 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
344 git commit --amend --author="$author" &&
345 git cat-file -p HEAD > current &&
346 test_cmp expected current
350 test_expect_success
'git commit <file> with dirty index' '
351 echo tacocat > elif &&
352 echo tehlulz > chz &&
354 git commit elif -m "tacocat is a palindrome" &&
355 git show --stat | grep elif &&
356 git diff --cached | grep chz
359 test_expect_success
'same tree (single parent)' '
363 if git commit -m empty
365 echo oops -- should have complained
373 test_expect_success
'same tree (single parent) --allow-empty' '
375 git commit --allow-empty -m "forced empty" &&
376 git cat-file commit HEAD | grep forced
380 test_expect_success
'same tree (merge and amend merge)' '
382 git checkout -b side HEAD^ &&
385 git commit -m "add zero" &&
386 git checkout master &&
388 git merge -s ours side -m "empty ok" &&
389 git diff HEAD^ HEAD >actual &&
391 test_cmp expected actual &&
393 git commit --amend -m "empty really ok" &&
394 git diff HEAD^ HEAD >actual &&
396 test_cmp expected actual
400 test_expect_success
'amend using the message from another commit' '
404 git commit --allow-empty -m "old commit" &&
405 old=$(git rev-parse --verify HEAD) &&
407 git commit --allow-empty -m "new commit" &&
408 new=$(git rev-parse --verify HEAD) &&
410 git commit --allow-empty --amend -C "$old" &&
411 git show --pretty="format:%ad %s" "$old" >expected &&
412 git show --pretty="format:%ad %s" HEAD >actual &&
413 test_cmp expected actual
417 test_expect_success
'amend using the message from a commit named with tag' '
421 git commit --allow-empty -m "old commit" &&
422 old=$(git rev-parse --verify HEAD) &&
423 git tag -a -m "tag on old" tagged-old HEAD &&
425 git commit --allow-empty -m "new commit" &&
426 new=$(git rev-parse --verify HEAD) &&
428 git commit --allow-empty --amend -C tagged-old &&
429 git show --pretty="format:%ad %s" "$old" >expected &&
430 git show --pretty="format:%ad %s" HEAD >actual &&
431 test_cmp expected actual
435 test_expect_success
'amend can copy notes' '
437 git config notes.rewrite.amend true &&
438 git config notes.rewriteRef "refs/notes/*" &&
440 git notes add -m"a note" &&
442 git commit --amend -m"new foo" &&
443 test "$(git notes show)" = "a note"