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
'cannot use paths with --interactive' '
45 echo bong-o-bong >file &&
46 # 2: update, 1:st path, that is all, 7: quit
47 ( echo 2; echo 1; echo; echo 7 ) |
48 test_must_fail git commit -m foo --interactive file
52 "using invalid commit with -C" \
53 "test_must_fail git commit -C bogus"
56 "testing nothing to commit" \
57 "test_must_fail git commit -m initial"
61 "echo 'bongo bongo bongo' >file \
62 git commit -m next -a"
65 "commit message from non-existing file" \
66 "echo 'more bongo: bongo bongo bongo bongo' >file && \
67 test_must_fail git commit -F gah -a"
69 # Empty except stray tabs and spaces on a few lines.
70 sed -e 's/@$//' >msg
<<EOF
77 "empty commit message" \
78 "test_must_fail git commit -F msg -a"
81 "commit message from file" \
82 "echo 'this is the commit message, coming from a file' >msg && \
87 sed -e "s/a file/an amend commit/g" < "$1" > "$1-"
94 "EDITOR=./editor git commit --amend"
98 "echo 'enough with the bongos' >file && \
99 test_must_fail git commit -F msg -m amending ."
101 test_expect_success \
102 "using message from other commit" \
103 "git commit -C HEAD^ ."
107 sed -e "s/amend/older/g" < "$1" > "$1-"
112 test_expect_success \
113 "editing message from other commit" \
114 "echo 'hula hula' >file && \
115 EDITOR=./editor git commit -c HEAD^ -a"
117 test_expect_success \
118 "message from stdin" \
119 "echo 'silly new contents' >file && \
120 echo commit message from stdin | git commit -F - -a"
122 test_expect_success \
123 "overriding author from command line" \
124 "echo 'gak' >file && \
125 git commit -m 'author' --author 'Rubber Duck <rduck@convoy.org>' -a >output 2>&1"
127 test_expect_success \
128 "commit --author output mentions author" \
129 "grep Rubber.Duck output"
131 test_expect_success PERL \
133 "echo 7 | git commit --interactive | grep 'What now'"
135 test_expect_success \
136 "showing committed revisions" \
137 "git rev-list HEAD >current"
141 sed -e "s/good/bad/g" < "$1" > "$1-"
147 A good commit message.
150 test_expect_success \
151 'editor not invoked if -F is given' '
153 EDITOR=./editor git commit -a -F msg &&
154 git show -s --pretty=format:"%s" | grep -q good &&
155 echo "quack" >file &&
156 echo "Another good message." | EDITOR=./editor git commit -a -F - &&
157 git show -s --pretty=format:"%s" | grep -q good
159 # We could just check the head sha1, but checking each commit makes it
160 # easier to isolate bugs.
163 72c0dc9855b0c9dadcbfd5a31cab072e0cb774ca
164 9b88fc14ce6b32e3d9ee021531a54f18a5cf38a2
165 3536bbb352c3a1ef9a420f5b4242d48578b92aa7
166 d381ac431806e53f3dd7ac2f1ae0534f36d738b9
167 4fd44095ad6334f3ef72e4c5ec8ddf108174b54a
168 402702b49136e7587daa9280e91e4bb7cb2179f7
171 test_expect_success \
172 'validate git rev-list output.' \
173 'test_cmp expected current'
175 test_expect_success
'partial commit that involves removal (1)' '
177 git rm --cached file &&
180 git commit -m "Partial: add elif" elif &&
181 git diff-tree --name-status HEAD^ HEAD >current &&
182 echo "A elif" >expected &&
183 test_cmp expected current
187 test_expect_success
'partial commit that involves removal (2)' '
189 git commit -m "Partial: remove file" file &&
190 git diff-tree --name-status HEAD^ HEAD >current &&
191 echo "D file" >expected &&
192 test_cmp expected current
196 test_expect_success
'partial commit that involves removal (3)' '
198 git rm --cached elif &&
200 git commit -m "Partial: modify elif" elif &&
201 git diff-tree --name-status HEAD^ HEAD >current &&
202 echo "M elif" >expected &&
203 test_cmp expected current
207 author
="The Real Author <someguy@his.email.org>"
208 test_expect_success
'amend commit to fix author' '
210 oldtick=$GIT_AUTHOR_DATE &&
213 git cat-file -p HEAD |
214 sed -e "s/author.*/author $author $oldtick/" \
215 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
217 git commit --amend --author="$author" &&
218 git cat-file -p HEAD > current &&
219 test_cmp expected current
223 test_expect_success
'amend commit to fix date' '
226 newtick=$GIT_AUTHOR_DATE &&
228 git cat-file -p HEAD |
229 sed -e "s/author.*/author $author $newtick/" \
230 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
232 git commit --amend --date="$newtick" &&
233 git cat-file -p HEAD > current &&
234 test_cmp expected current
238 test_expect_success
'commit complains about bogus date' '
239 test_must_fail git commit --amend --date=10.11.2010
242 test_expect_success
'sign off (1)' '
246 git commit -s -m "thank you" &&
247 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
251 git var GIT_COMMITTER_IDENT |
252 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
254 test_cmp expected actual
258 test_expect_success
'sign off (2)' '
262 existing="Signed-off-by: Watch This <watchthis@example.com>" &&
263 git commit -s -m "thank you
266 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
271 git var GIT_COMMITTER_IDENT |
272 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
274 test_cmp expected actual
278 test_expect_success
'signoff gap' '
282 alt="Alt-RFC-822-Header: Value" &&
283 git commit -s -m "welcome
286 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
291 git var GIT_COMMITTER_IDENT |
292 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
294 test_cmp expected actual
297 test_expect_success
'signoff gap 2' '
302 git commit -s -m "welcome
306 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
313 git var GIT_COMMITTER_IDENT |
314 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
316 test_cmp expected actual
319 test_expect_success
'multiple -m' '
323 git commit -m "one" -m "two" -m "three" &&
324 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
332 test_cmp expected actual
336 author
="The Real Author <someguy@his.email.org>"
337 test_expect_success
'amend commit to fix author' '
339 oldtick=$GIT_AUTHOR_DATE &&
342 git cat-file -p HEAD |
343 sed -e "s/author.*/author $author $oldtick/" \
344 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
346 git commit --amend --author="$author" &&
347 git cat-file -p HEAD > current &&
348 test_cmp expected current
352 test_expect_success
'git commit <file> with dirty index' '
353 echo tacocat > elif &&
354 echo tehlulz > chz &&
356 git commit elif -m "tacocat is a palindrome" &&
357 git show --stat | grep elif &&
358 git diff --cached | grep chz
361 test_expect_success
'same tree (single parent)' '
365 if git commit -m empty
367 echo oops -- should have complained
375 test_expect_success
'same tree (single parent) --allow-empty' '
377 git commit --allow-empty -m "forced empty" &&
378 git cat-file commit HEAD | grep forced
382 test_expect_success
'same tree (merge and amend merge)' '
384 git checkout -b side HEAD^ &&
387 git commit -m "add zero" &&
388 git checkout master &&
390 git merge -s ours side -m "empty ok" &&
391 git diff HEAD^ HEAD >actual &&
393 test_cmp expected actual &&
395 git commit --amend -m "empty really ok" &&
396 git diff HEAD^ HEAD >actual &&
398 test_cmp expected actual
402 test_expect_success
'amend using the message from another commit' '
406 git commit --allow-empty -m "old commit" &&
407 old=$(git rev-parse --verify HEAD) &&
409 git commit --allow-empty -m "new commit" &&
410 new=$(git rev-parse --verify HEAD) &&
412 git commit --allow-empty --amend -C "$old" &&
413 git show --pretty="format:%ad %s" "$old" >expected &&
414 git show --pretty="format:%ad %s" HEAD >actual &&
415 test_cmp expected actual
419 test_expect_success
'amend using the message from a commit named with tag' '
423 git commit --allow-empty -m "old commit" &&
424 old=$(git rev-parse --verify HEAD) &&
425 git tag -a -m "tag on old" tagged-old HEAD &&
427 git commit --allow-empty -m "new commit" &&
428 new=$(git rev-parse --verify HEAD) &&
430 git commit --allow-empty --amend -C tagged-old &&
431 git show --pretty="format:%ad %s" "$old" >expected &&
432 git show --pretty="format:%ad %s" HEAD >actual &&
433 test_cmp expected actual
437 test_expect_success
'amend can copy notes' '
439 git config notes.rewrite.amend true &&
440 git config notes.rewriteRef "refs/notes/*" &&
442 git notes add -m"a note" &&
444 git commit --amend -m"new foo" &&
445 test "$(git notes show)" = "a note"