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 "Constructing initial commit" '
21 test_i18ngrep "Initial commit" actual
25 "fail initial amend" \
26 "test_must_fail git commit --amend"
30 "git commit -m initial"
34 "test_must_fail git commit -m foo -m bar -F file"
38 "test_must_fail git commit -C HEAD -m illegal"
41 "using paths with -a" \
42 "echo King of the bongo >file &&
43 test_must_fail git commit -m foo -a file"
45 test_expect_success PERL \
46 "using paths with --interactive" \
47 "echo bong-o-bong >file &&
48 ! (echo 7 | git commit -m foo --interactive file)"
51 "using invalid commit with -C" \
52 "test_must_fail git commit -C bogus"
55 "testing nothing to commit" \
56 "test_must_fail git commit -m initial"
60 "echo 'bongo bongo bongo' >file \
61 git commit -m next -a"
64 "commit message from non-existing file" \
65 "echo 'more bongo: bongo bongo bongo bongo' >file && \
66 test_must_fail git commit -F gah -a"
68 # Empty except stray tabs and spaces on a few lines.
69 sed -e 's/@$//' >msg <<EOF
76 "empty commit message" \
77 "test_must_fail git commit -F msg -a"
80 "commit message from file" \
81 "echo 'this is the commit message, coming from a file' >msg && \
86 sed -e "s/a file/an amend commit/g" < "$1" > "$1-"
93 "EDITOR=./editor git commit --amend"
97 "echo 'enough with the bongos' >file && \
98 test_must_fail git commit -F msg -m amending ."
100 test_expect_success \
101 "using message from other commit" \
102 "git commit -C HEAD^ ."
106 sed -e "s/amend/older/g" < "$1" > "$1-"
111 test_expect_success \
112 "editing message from other commit" \
113 "echo 'hula hula' >file && \
114 EDITOR=./editor git commit -c HEAD^ -a"
116 test_expect_success \
117 "message from stdin" \
118 "echo 'silly new contents' >file && \
119 echo commit message from stdin | git commit -F - -a"
121 test_expect_success \
122 "overriding author from command line" \
123 "echo 'gak' >file && \
124 git commit -m 'author' --author 'Rubber Duck <rduck@convoy.org>' -a >output 2>&1"
126 test_expect_success \
127 "commit --author output mentions author" \
128 "grep Rubber.Duck output"
130 test_expect_success PERL \
132 "echo 7 | git commit --interactive | grep 'What now'"
134 test_expect_success \
135 "showing committed revisions" \
136 "git rev-list HEAD >current"
140 sed -e "s/good/bad/g" < "$1" > "$1-"
146 A good commit message.
149 test_expect_success \
150 'editor not invoked if -F is given' '
152 EDITOR=./editor git commit -a -F msg &&
153 git show -s --pretty=format:"%s" | grep -q good &&
154 echo "quack" >file &&
155 echo "Another good message." | EDITOR=./editor git commit -a -F - &&
156 git show -s --pretty=format:"%s" | grep -q good
158 # We could just check the head sha1, but checking each commit makes it
159 # easier to isolate bugs.
162 72c0dc9855b0c9dadcbfd5a31cab072e0cb774ca
163 9b88fc14ce6b32e3d9ee021531a54f18a5cf38a2
164 3536bbb352c3a1ef9a420f5b4242d48578b92aa7
165 d381ac431806e53f3dd7ac2f1ae0534f36d738b9
166 4fd44095ad6334f3ef72e4c5ec8ddf108174b54a
167 402702b49136e7587daa9280e91e4bb7cb2179f7
170 test_expect_success \
171 'validate git rev-list output.' \
172 'test_cmp expected current'
174 test_expect_success 'partial commit that involves removal (1)' '
176 git rm --cached file &&
179 git commit -m "Partial: add elif" elif &&
180 git diff-tree --name-status HEAD^ HEAD >current &&
181 echo "A elif" >expected &&
182 test_cmp expected current
186 test_expect_success 'partial commit that involves removal (2)' '
188 git commit -m "Partial: remove file" file &&
189 git diff-tree --name-status HEAD^ HEAD >current &&
190 echo "D file" >expected &&
191 test_cmp expected current
195 test_expect_success 'partial commit that involves removal (3)' '
197 git rm --cached elif &&
199 git commit -m "Partial: modify elif" elif &&
200 git diff-tree --name-status HEAD^ HEAD >current &&
201 echo "M elif" >expected &&
202 test_cmp expected current
206 author="The Real Author <someguy@his.email.org>"
207 test_expect_success 'amend commit to fix author' '
209 oldtick=$GIT_AUTHOR_DATE &&
212 git cat-file -p HEAD |
213 sed -e "s/author.*/author $author $oldtick/" \
214 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
216 git commit --amend --author="$author" &&
217 git cat-file -p HEAD > current &&
218 test_cmp expected current
222 test_expect_success 'amend commit to fix date' '
225 newtick=$GIT_AUTHOR_DATE &&
227 git cat-file -p HEAD |
228 sed -e "s/author.*/author $author $newtick/" \
229 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
231 git commit --amend --date="$newtick" &&
232 git cat-file -p HEAD > current &&
233 test_cmp expected current
237 test_expect_success 'commit complains about bogus date' '
238 test_must_fail git commit --amend --date=10.11.2010
241 test_expect_success 'sign off (1)' '
245 git commit -s -m "thank you" &&
246 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
250 git var GIT_COMMITTER_IDENT |
251 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
253 test_cmp expected actual
257 test_expect_success 'sign off (2)' '
261 existing="Signed-off-by: Watch This <watchthis@example.com>" &&
262 git commit -s -m "thank you
265 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
270 git var GIT_COMMITTER_IDENT |
271 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
273 test_cmp expected actual
277 test_expect_success 'signoff gap' '
281 alt="Alt-RFC-822-Header: Value" &&
282 git commit -s -m "welcome
285 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
290 git var GIT_COMMITTER_IDENT |
291 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
293 test_cmp expected actual
296 test_expect_success 'signoff gap 2' '
301 git commit -s -m "welcome
305 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
312 git var GIT_COMMITTER_IDENT |
313 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
315 test_cmp expected actual
318 test_expect_success 'multiple -m' '
322 git commit -m "one" -m "two" -m "three" &&
323 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
331 test_cmp expected actual
335 author="The Real Author <someguy@his.email.org>"
336 test_expect_success 'amend commit to fix author' '
338 oldtick=$GIT_AUTHOR_DATE &&
341 git cat-file -p HEAD |
342 sed -e "s/author.*/author $author $oldtick/" \
343 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
345 git commit --amend --author="$author" &&
346 git cat-file -p HEAD > current &&
347 test_cmp expected current
351 test_expect_success 'git commit <file> with dirty index' '
352 echo tacocat > elif &&
353 echo tehlulz > chz &&
355 git commit elif -m "tacocat is a palindrome" &&
356 git show --stat | grep elif &&
357 git diff --cached | grep chz
360 test_expect_success 'same tree (single parent)' '
364 if git commit -m empty
366 echo oops -- should have complained
374 test_expect_success 'same tree (single parent) --allow-empty' '
376 git commit --allow-empty -m "forced empty" &&
377 git cat-file commit HEAD | grep forced
381 test_expect_success 'same tree (merge and amend merge)' '
383 git checkout -b side HEAD^ &&
386 git commit -m "add zero" &&
387 git checkout master &&
389 git merge -s ours side -m "empty ok" &&
390 git diff HEAD^ HEAD >actual &&
392 test_cmp expected actual &&
394 git commit --amend -m "empty really ok" &&
395 git diff HEAD^ HEAD >actual &&
397 test_cmp expected actual
401 test_expect_success 'amend using the message from another commit' '
405 git commit --allow-empty -m "old commit" &&
406 old=$(git rev-parse --verify HEAD) &&
408 git commit --allow-empty -m "new commit" &&
409 new=$(git rev-parse --verify HEAD) &&
411 git commit --allow-empty --amend -C "$old" &&
412 git show --pretty="format:%ad %s" "$old" >expected &&
413 git show --pretty="format:%ad %s" HEAD >actual &&
414 test_cmp expected actual
418 test_expect_success 'amend using the message from a commit named with tag' '
422 git commit --allow-empty -m "old commit" &&
423 old=$(git rev-parse --verify HEAD) &&
424 git tag -a -m "tag on old" tagged-old HEAD &&
426 git commit --allow-empty -m "new commit" &&
427 new=$(git rev-parse --verify HEAD) &&
429 git commit --allow-empty --amend -C tagged-old &&
430 git show --pretty="format:%ad %s" "$old" >expected &&
431 git show --pretty="format:%ad %s" HEAD >actual &&
432 test_cmp expected actual
436 test_expect_success 'amend can copy notes' '
438 git config notes.rewrite.amend true &&
439 git config notes.rewriteRef "refs/notes/*" &&
441 git notes add -m"a note" &&
443 git commit --amend -m"new foo" &&
444 test "$(git notes show)" = "a note"