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"
122 test_expect_success PERL \
124 "echo 7 | git commit --interactive | grep 'What now'"
126 test_expect_success \
127 "showing committed revisions" \
128 "git rev-list HEAD >current"
132 sed -e "s/good/bad/g" < "$1" > "$1-"
138 A good commit message.
141 test_expect_success \
142 'editor not invoked if -F is given' '
144 EDITOR=./editor git commit -a -F msg &&
145 git show -s --pretty=format:"%s" | grep -q good &&
146 echo "quack" >file &&
147 echo "Another good message." | EDITOR=./editor git commit -a -F - &&
148 git show -s --pretty=format:"%s" | grep -q good
150 # We could just check the head sha1, but checking each commit makes it
151 # easier to isolate bugs.
154 72c0dc9855b0c9dadcbfd5a31cab072e0cb774ca
155 9b88fc14ce6b32e3d9ee021531a54f18a5cf38a2
156 3536bbb352c3a1ef9a420f5b4242d48578b92aa7
157 d381ac431806e53f3dd7ac2f1ae0534f36d738b9
158 4fd44095ad6334f3ef72e4c5ec8ddf108174b54a
159 402702b49136e7587daa9280e91e4bb7cb2179f7
162 test_expect_success \
163 'validate git rev-list output.' \
164 'test_cmp expected current'
166 test_expect_success 'partial commit that involves removal (1)' '
168 git rm --cached file &&
171 git commit -m "Partial: add elif" elif &&
172 git diff-tree --name-status HEAD^ HEAD >current &&
173 echo "A elif" >expected &&
174 test_cmp expected current
178 test_expect_success 'partial commit that involves removal (2)' '
180 git commit -m "Partial: remove file" file &&
181 git diff-tree --name-status HEAD^ HEAD >current &&
182 echo "D file" >expected &&
183 test_cmp expected current
187 test_expect_success 'partial commit that involves removal (3)' '
189 git rm --cached elif &&
191 git commit -m "Partial: modify elif" elif &&
192 git diff-tree --name-status HEAD^ HEAD >current &&
193 echo "M elif" >expected &&
194 test_cmp expected current
198 author="The Real Author <someguy@his.email.org>"
199 test_expect_success 'amend commit to fix author' '
201 oldtick=$GIT_AUTHOR_DATE &&
204 git cat-file -p HEAD |
205 sed -e "s/author.*/author $author $oldtick/" \
206 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
208 git commit --amend --author="$author" &&
209 git cat-file -p HEAD > current &&
210 test_cmp expected current
214 test_expect_success 'sign off (1)' '
218 git commit -s -m "thank you" &&
219 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
223 git var GIT_COMMITTER_IDENT |
224 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
226 test_cmp expected actual
230 test_expect_success 'sign off (2)' '
234 existing="Signed-off-by: Watch This <watchthis@example.com>" &&
235 git commit -s -m "thank you
238 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
243 git var GIT_COMMITTER_IDENT |
244 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
246 test_cmp expected actual
250 test_expect_success 'signoff gap' '
254 alt="Alt-RFC-822-Header: Value" &&
255 git commit -s -m "welcome
258 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
263 git var GIT_COMMITTER_IDENT |
264 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
266 test_cmp expected actual
269 test_expect_success 'signoff gap 2' '
274 git commit -s -m "welcome
278 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
285 git var GIT_COMMITTER_IDENT |
286 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
288 test_cmp expected actual
291 test_expect_success 'multiple -m' '
295 git commit -m "one" -m "two" -m "three" &&
296 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
304 test_cmp expected actual
308 author="The Real Author <someguy@his.email.org>"
309 test_expect_success 'amend commit to fix author' '
311 oldtick=$GIT_AUTHOR_DATE &&
314 git cat-file -p HEAD |
315 sed -e "s/author.*/author $author $oldtick/" \
316 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
318 git commit --amend --author="$author" &&
319 git cat-file -p HEAD > current &&
320 test_cmp expected current
324 test_expect_success 'git commit <file> with dirty index' '
325 echo tacocat > elif &&
326 echo tehlulz > chz &&
328 git commit elif -m "tacocat is a palindrome" &&
329 git show --stat | grep elif &&
330 git diff --cached | grep chz
333 test_expect_success 'same tree (single parent)' '
337 if git commit -m empty
339 echo oops -- should have complained
347 test_expect_success 'same tree (single parent) --allow-empty' '
349 git commit --allow-empty -m "forced empty" &&
350 git cat-file commit HEAD | grep forced
354 test_expect_success 'same tree (merge and amend merge)' '
356 git checkout -b side HEAD^ &&
359 git commit -m "add zero" &&
360 git checkout master &&
362 git merge -s ours side -m "empty ok" &&
363 git diff HEAD^ HEAD >actual &&
365 test_cmp expected actual &&
367 git commit --amend -m "empty really ok" &&
368 git diff HEAD^ HEAD >actual &&
370 test_cmp expected actual
374 test_expect_success 'amend using the message from another commit' '
378 git commit --allow-empty -m "old commit" &&
379 old=$(git rev-parse --verify HEAD) &&
381 git commit --allow-empty -m "new commit" &&
382 new=$(git rev-parse --verify HEAD) &&
384 git commit --allow-empty --amend -C "$old" &&
385 git show --pretty="format:%ad %s" "$old" >expected &&
386 git show --pretty="format:%ad %s" HEAD >actual &&
387 test_cmp expected actual
391 test_expect_success 'amend using the message from a commit named with tag' '
395 git commit --allow-empty -m "old commit" &&
396 old=$(git rev-parse --verify HEAD) &&
397 git tag -a -m "tag on old" tagged-old HEAD &&
399 git commit --allow-empty -m "new commit" &&
400 new=$(git rev-parse --verify HEAD) &&
402 git commit --allow-empty --amend -C tagged-old &&
403 git show --pretty="format:%ad %s" "$old" >expected &&
404 git show --pretty="format:%ad %s" HEAD >actual &&
405 test_cmp expected actual