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 &&
18 git status | grep 'Initial commit'"
21 "fail initial amend" \
22 "test_must_fail git commit --amend"
26 "git commit -m initial"
30 "test_must_fail git commit -m foo -m bar -F file"
34 "test_must_fail git commit -C HEAD -m illegal"
37 "using paths with -a" \
38 "echo King of the bongo >file &&
39 test_must_fail git commit -m foo -a file"
41 test_expect_success PERL \
42 "using paths with --interactive" \
43 "echo bong-o-bong >file &&
44 ! (echo 7 | git commit -m foo --interactive file)"
47 "using invalid commit with -C" \
48 "test_must_fail git commit -C bogus"
51 "testing nothing to commit" \
52 "test_must_fail git commit -m initial"
56 "echo 'bongo bongo bongo' >file \
57 git commit -m next -a"
60 "commit message from non-existing file" \
61 "echo 'more bongo: bongo bongo bongo bongo' >file && \
62 test_must_fail git commit -F gah -a"
64 # Empty except stray tabs and spaces on a few lines.
65 sed -e 's/@$//' >msg <<EOF
72 "empty commit message" \
73 "test_must_fail git commit -F msg -a"
76 "commit message from file" \
77 "echo 'this is the commit message, coming from a file' >msg && \
82 sed -e "s/a file/an amend commit/g" < "$1" > "$1-"
89 "EDITOR=./editor git commit --amend"
93 "echo 'enough with the bongos' >file && \
94 test_must_fail git commit -F msg -m amending ."
97 "using message from other commit" \
98 "git commit -C HEAD^ ."
102 sed -e "s/amend/older/g" < "$1" > "$1-"
107 test_expect_success \
108 "editing message from other commit" \
109 "echo 'hula hula' >file && \
110 EDITOR=./editor git commit -c HEAD^ -a"
112 test_expect_success \
113 "message from stdin" \
114 "echo 'silly new contents' >file && \
115 echo commit message from stdin | git commit -F - -a"
117 test_expect_success \
118 "overriding author from command line" \
119 "echo 'gak' >file && \
120 git commit -m 'author' --author 'Rubber Duck <rduck@convoy.org>' -a >output 2>&1"
122 test_expect_success \
123 "commit --author output mentions author" \
124 "grep Rubber.Duck output"
126 test_expect_success PERL \
128 "echo 7 | git commit --interactive | grep 'What now'"
130 test_expect_success \
131 "showing committed revisions" \
132 "git rev-list HEAD >current"
136 sed -e "s/good/bad/g" < "$1" > "$1-"
142 A good commit message.
145 test_expect_success \
146 'editor not invoked if -F is given' '
148 EDITOR=./editor git commit -a -F msg &&
149 git show -s --pretty=format:"%s" | grep -q good &&
150 echo "quack" >file &&
151 echo "Another good message." | EDITOR=./editor git commit -a -F - &&
152 git show -s --pretty=format:"%s" | grep -q good
154 # We could just check the head sha1, but checking each commit makes it
155 # easier to isolate bugs.
158 72c0dc9855b0c9dadcbfd5a31cab072e0cb774ca
159 9b88fc14ce6b32e3d9ee021531a54f18a5cf38a2
160 3536bbb352c3a1ef9a420f5b4242d48578b92aa7
161 d381ac431806e53f3dd7ac2f1ae0534f36d738b9
162 4fd44095ad6334f3ef72e4c5ec8ddf108174b54a
163 402702b49136e7587daa9280e91e4bb7cb2179f7
166 test_expect_success \
167 'validate git rev-list output.' \
168 'test_cmp expected current'
170 test_expect_success 'partial commit that involves removal (1)' '
172 git rm --cached file &&
175 git commit -m "Partial: add elif" elif &&
176 git diff-tree --name-status HEAD^ HEAD >current &&
177 echo "A elif" >expected &&
178 test_cmp expected current
182 test_expect_success 'partial commit that involves removal (2)' '
184 git commit -m "Partial: remove file" file &&
185 git diff-tree --name-status HEAD^ HEAD >current &&
186 echo "D file" >expected &&
187 test_cmp expected current
191 test_expect_success 'partial commit that involves removal (3)' '
193 git rm --cached elif &&
195 git commit -m "Partial: modify elif" elif &&
196 git diff-tree --name-status HEAD^ HEAD >current &&
197 echo "M elif" >expected &&
198 test_cmp expected current
202 author="The Real Author <someguy@his.email.org>"
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 author="The Real Author <someguy@his.email.org>"
332 test_expect_success 'amend commit to fix author' '
334 oldtick=$GIT_AUTHOR_DATE &&
337 git cat-file -p HEAD |
338 sed -e "s/author.*/author $author $oldtick/" \
339 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
341 git commit --amend --author="$author" &&
342 git cat-file -p HEAD > current &&
343 test_cmp expected current
347 test_expect_success 'git commit <file> with dirty index' '
348 echo tacocat > elif &&
349 echo tehlulz > chz &&
351 git commit elif -m "tacocat is a palindrome" &&
352 git show --stat | grep elif &&
353 git diff --cached | grep chz
356 test_expect_success 'same tree (single parent)' '
360 if git commit -m empty
362 echo oops -- should have complained
370 test_expect_success 'same tree (single parent) --allow-empty' '
372 git commit --allow-empty -m "forced empty" &&
373 git cat-file commit HEAD | grep forced
377 test_expect_success 'same tree (merge and amend merge)' '
379 git checkout -b side HEAD^ &&
382 git commit -m "add zero" &&
383 git checkout master &&
385 git merge -s ours side -m "empty ok" &&
386 git diff HEAD^ HEAD >actual &&
388 test_cmp expected actual &&
390 git commit --amend -m "empty really ok" &&
391 git diff HEAD^ HEAD >actual &&
393 test_cmp expected actual
397 test_expect_success 'amend using the message from another commit' '
401 git commit --allow-empty -m "old commit" &&
402 old=$(git rev-parse --verify HEAD) &&
404 git commit --allow-empty -m "new commit" &&
405 new=$(git rev-parse --verify HEAD) &&
407 git commit --allow-empty --amend -C "$old" &&
408 git show --pretty="format:%ad %s" "$old" >expected &&
409 git show --pretty="format:%ad %s" HEAD >actual &&
410 test_cmp expected actual
414 test_expect_success 'amend using the message from a commit named with tag' '
418 git commit --allow-empty -m "old commit" &&
419 old=$(git rev-parse --verify HEAD) &&
420 git tag -a -m "tag on old" tagged-old HEAD &&
422 git commit --allow-empty -m "new commit" &&
423 new=$(git rev-parse --verify HEAD) &&
425 git commit --allow-empty --amend -C tagged-old &&
426 git show --pretty="format:%ad %s" "$old" >expected &&
427 git show --pretty="format:%ad %s" HEAD >actual &&
428 test_cmp expected actual
432 test_expect_success 'amend can copy notes' '
434 git config notes.rewrite.amend true &&
435 git config notes.rewriteRef "refs/notes/*" &&
437 git notes add -m"a note" &&
439 git commit --amend -m"new foo" &&
440 test "$(git notes show)" = "a note"