]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7501-commit.sh
Do not use VISUAL editor on dumb terminals
[thirdparty/git.git] / t / t7501-commit.sh
CommitLineData
12ace0b2
KH
1#!/bin/sh
2#
3# Copyright (c) 2007 Kristian Høgsberg <krh@redhat.com>
4#
5
6# FIXME: Test the various index usages, -i and -o, test reflog,
264474f2 7# signoff
12ace0b2 8
47a528ad 9test_description='git commit'
12ace0b2
KH
10. ./test-lib.sh
11
12test_tick
13
14test_expect_success \
15 "initial status" \
16 "echo 'bongo bongo' >file &&
47a528ad
NS
17 git add file && \
18 git status | grep 'Initial commit'"
12ace0b2 19
41ac414e 20test_expect_success \
12ace0b2 21 "fail initial amend" \
47a528ad 22 "test_must_fail git commit --amend"
12ace0b2
KH
23
24test_expect_success \
25 "initial commit" \
47a528ad 26 "git commit -m initial"
12ace0b2 27
41ac414e 28test_expect_success \
12ace0b2 29 "invalid options 1" \
47a528ad 30 "test_must_fail git commit -m foo -m bar -F file"
12ace0b2 31
41ac414e 32test_expect_success \
12ace0b2 33 "invalid options 2" \
47a528ad 34 "test_must_fail git commit -C HEAD -m illegal"
12ace0b2 35
41ac414e 36test_expect_success \
9d87442f
BS
37 "using paths with -a" \
38 "echo King of the bongo >file &&
47a528ad 39 test_must_fail git commit -m foo -a file"
9d87442f 40
1b19ccd2 41test_expect_success PERL \
9d87442f
BS
42 "using paths with --interactive" \
43 "echo bong-o-bong >file &&
47a528ad 44 ! (echo 7 | git commit -m foo --interactive file)"
9d87442f 45
41ac414e 46test_expect_success \
12ace0b2 47 "using invalid commit with -C" \
47a528ad 48 "test_must_fail git commit -C bogus"
12ace0b2 49
41ac414e 50test_expect_success \
12ace0b2 51 "testing nothing to commit" \
47a528ad 52 "test_must_fail git commit -m initial"
12ace0b2
KH
53
54test_expect_success \
55 "next commit" \
56 "echo 'bongo bongo bongo' >file \
47a528ad 57 git commit -m next -a"
12ace0b2 58
41ac414e 59test_expect_success \
12ace0b2
KH
60 "commit message from non-existing file" \
61 "echo 'more bongo: bongo bongo bongo bongo' >file && \
47a528ad 62 test_must_fail git commit -F gah -a"
12ace0b2
KH
63
64# Empty except stray tabs and spaces on a few lines.
65sed -e 's/@$//' >msg <<EOF
66 @
67
68 @
69Signed-off-by: hula
70EOF
41ac414e 71test_expect_success \
12ace0b2 72 "empty commit message" \
47a528ad 73 "test_must_fail git commit -F msg -a"
12ace0b2
KH
74
75test_expect_success \
76 "commit message from file" \
77 "echo 'this is the commit message, coming from a file' >msg && \
47a528ad 78 git commit -F msg -a"
12ace0b2
KH
79
80cat >editor <<\EOF
81#!/bin/sh
f69e836f
BD
82sed -e "s/a file/an amend commit/g" < "$1" > "$1-"
83mv "$1-" "$1"
12ace0b2
KH
84EOF
85chmod 755 editor
86
87test_expect_success \
88 "amend commit" \
d33738d7 89 "EDITOR=./editor git commit --amend"
12ace0b2 90
41ac414e 91test_expect_success \
6d4bbebd 92 "passing -m and -F" \
12ace0b2 93 "echo 'enough with the bongos' >file && \
47a528ad 94 test_must_fail git commit -F msg -m amending ."
12ace0b2
KH
95
96test_expect_success \
97 "using message from other commit" \
47a528ad 98 "git commit -C HEAD^ ."
12ace0b2
KH
99
100cat >editor <<\EOF
101#!/bin/sh
f69e836f
BD
102sed -e "s/amend/older/g" < "$1" > "$1-"
103mv "$1-" "$1"
12ace0b2
KH
104EOF
105chmod 755 editor
106
107test_expect_success \
108 "editing message from other commit" \
109 "echo 'hula hula' >file && \
d33738d7 110 EDITOR=./editor git commit -c HEAD^ -a"
12ace0b2
KH
111
112test_expect_success \
113 "message from stdin" \
114 "echo 'silly new contents' >file && \
47a528ad 115 echo commit message from stdin | git commit -F - -a"
12ace0b2
KH
116
117test_expect_success \
118 "overriding author from command line" \
119 "echo 'gak' >file && \
47a528ad 120 git commit -m 'author' --author 'Rubber Duck <rduck@convoy.org>' -a"
12ace0b2 121
1b19ccd2 122test_expect_success PERL \
12ace0b2 123 "interactive add" \
47a528ad 124 "echo 7 | git commit --interactive | grep 'What now'"
12ace0b2
KH
125
126test_expect_success \
127 "showing committed revisions" \
47a528ad 128 "git rev-list HEAD >current"
12ace0b2 129
7eb5bbdb
AS
130cat >editor <<\EOF
131#!/bin/sh
132sed -e "s/good/bad/g" < "$1" > "$1-"
133mv "$1-" "$1"
134EOF
135chmod 755 editor
136
137cat >msg <<EOF
138A good commit message.
139EOF
140
141test_expect_success \
142 'editor not invoked if -F is given' '
143 echo "moo" >file &&
d33738d7 144 EDITOR=./editor git commit -a -F msg &&
7eb5bbdb
AS
145 git show -s --pretty=format:"%s" | grep -q good &&
146 echo "quack" >file &&
d33738d7 147 echo "Another good message." | EDITOR=./editor git commit -a -F - &&
7eb5bbdb
AS
148 git show -s --pretty=format:"%s" | grep -q good
149 '
12ace0b2
KH
150# We could just check the head sha1, but checking each commit makes it
151# easier to isolate bugs.
152
153cat >expected <<\EOF
15472c0dc9855b0c9dadcbfd5a31cab072e0cb774ca
1559b88fc14ce6b32e3d9ee021531a54f18a5cf38a2
1563536bbb352c3a1ef9a420f5b4242d48578b92aa7
157d381ac431806e53f3dd7ac2f1ae0534f36d738b9
1584fd44095ad6334f3ef72e4c5ec8ddf108174b54a
159402702b49136e7587daa9280e91e4bb7cb2179f7
160EOF
161
162test_expect_success \
47a528ad 163 'validate git rev-list output.' \
1e368681 164 'test_cmp expected current'
12ace0b2 165
db33af0a 166test_expect_success 'partial commit that involves removal (1)' '
80bffaf7
JH
167
168 git rm --cached file &&
169 mv file elif &&
170 git add elif &&
171 git commit -m "Partial: add elif" elif &&
172 git diff-tree --name-status HEAD^ HEAD >current &&
173 echo "A elif" >expected &&
1e368681 174 test_cmp expected current
80bffaf7
JH
175
176'
177
db33af0a 178test_expect_success 'partial commit that involves removal (2)' '
80bffaf7
JH
179
180 git commit -m "Partial: remove file" file &&
181 git diff-tree --name-status HEAD^ HEAD >current &&
182 echo "D file" >expected &&
1e368681 183 test_cmp expected current
80bffaf7
JH
184
185'
186
db33af0a
JH
187test_expect_success 'partial commit that involves removal (3)' '
188
189 git rm --cached elif &&
190 echo elif >elif &&
191 git commit -m "Partial: modify elif" elif &&
192 git diff-tree --name-status HEAD^ HEAD >current &&
193 echo "M elif" >expected &&
1e368681 194 test_cmp expected current
db33af0a
JH
195
196'
197
5aa5cd46
JH
198author="The Real Author <someguy@his.email.org>"
199test_expect_success 'amend commit to fix author' '
200
201 oldtick=$GIT_AUTHOR_DATE &&
202 test_tick &&
203 git reset --hard &&
204 git cat-file -p HEAD |
205 sed -e "s/author.*/author $author $oldtick/" \
206 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
207 expected &&
208 git commit --amend --author="$author" &&
209 git cat-file -p HEAD > current &&
1e368681 210 test_cmp expected current
5aa5cd46
JH
211
212'
213
214test_expect_success 'sign off (1)' '
215
216 echo 1 >positive &&
217 git add positive &&
218 git commit -s -m "thank you" &&
219 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
220 (
221 echo thank you
222 echo
223 git var GIT_COMMITTER_IDENT |
224 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
225 ) >expected &&
82ebb0b6 226 test_cmp expected actual
5aa5cd46
JH
227
228'
229
230test_expect_success 'sign off (2)' '
231
232 echo 2 >positive &&
233 git add positive &&
234 existing="Signed-off-by: Watch This <watchthis@example.com>" &&
235 git commit -s -m "thank you
236
237$existing" &&
238 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
239 (
240 echo thank you
241 echo
242 echo $existing
243 git var GIT_COMMITTER_IDENT |
244 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
245 ) >expected &&
82ebb0b6 246 test_cmp expected actual
5aa5cd46
JH
247
248'
249
c1e01b0c
DB
250test_expect_success 'signoff gap' '
251
252 echo 3 >positive &&
253 git add positive &&
254 alt="Alt-RFC-822-Header: Value" &&
255 git commit -s -m "welcome
256
257$alt" &&
258 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
259 (
260 echo welcome
261 echo
262 echo $alt
263 git var GIT_COMMITTER_IDENT |
264 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
265 ) >expected &&
266 test_cmp expected actual
267'
268
269test_expect_success 'signoff gap 2' '
270
271 echo 4 >positive &&
272 git add positive &&
273 alt="fixed: 34" &&
274 git commit -s -m "welcome
275
276We have now
277$alt" &&
278 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
279 (
280 echo welcome
281 echo
282 echo We have now
283 echo $alt
284 echo
285 git var GIT_COMMITTER_IDENT |
286 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
287 ) >expected &&
288 test_cmp expected actual
289'
290
5aa5cd46
JH
291test_expect_success 'multiple -m' '
292
293 >negative &&
294 git add negative &&
295 git commit -m "one" -m "two" -m "three" &&
296 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
297 (
298 echo one
299 echo
300 echo two
301 echo
302 echo three
303 ) >expected &&
82ebb0b6 304 test_cmp expected actual
5aa5cd46
JH
305
306'
307
d63c2fd1
KH
308author="The Real Author <someguy@his.email.org>"
309test_expect_success 'amend commit to fix author' '
310
311 oldtick=$GIT_AUTHOR_DATE &&
312 test_tick &&
313 git reset --hard &&
314 git cat-file -p HEAD |
315 sed -e "s/author.*/author $author $oldtick/" \
316 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
317 expected &&
318 git commit --amend --author="$author" &&
319 git cat-file -p HEAD > current &&
1e368681 320 test_cmp expected current
d63c2fd1
KH
321
322'
1200993a
KH
323
324test_expect_success 'git commit <file> with dirty index' '
325 echo tacocat > elif &&
326 echo tehlulz > chz &&
327 git add chz &&
328 git commit elif -m "tacocat is a palindrome" &&
329 git show --stat | grep elif &&
330 git diff --cached | grep chz
331'
332
13aba1e5
JS
333test_expect_success 'same tree (single parent)' '
334
31cbb5d9
JH
335 git reset --hard
336
13aba1e5
JS
337 if git commit -m empty
338 then
339 echo oops -- should have complained
340 false
341 else
342 : happy
343 fi
344
345'
346
36863af1
JH
347test_expect_success 'same tree (single parent) --allow-empty' '
348
349 git commit --allow-empty -m "forced empty" &&
350 git cat-file commit HEAD | grep forced
351
352'
353
13aba1e5
JS
354test_expect_success 'same tree (merge and amend merge)' '
355
356 git checkout -b side HEAD^ &&
357 echo zero >zero &&
358 git add zero &&
359 git commit -m "add zero" &&
360 git checkout master &&
361
362 git merge -s ours side -m "empty ok" &&
363 git diff HEAD^ HEAD >actual &&
364 : >expected &&
82ebb0b6 365 test_cmp expected actual &&
13aba1e5
JS
366
367 git commit --amend -m "empty really ok" &&
368 git diff HEAD^ HEAD >actual &&
369 : >expected &&
82ebb0b6 370 test_cmp expected actual
13aba1e5
JS
371
372'
373
1eb1e9ee
JH
374test_expect_success 'amend using the message from another commit' '
375
376 git reset --hard &&
377 test_tick &&
378 git commit --allow-empty -m "old commit" &&
379 old=$(git rev-parse --verify HEAD) &&
380 test_tick &&
381 git commit --allow-empty -m "new commit" &&
382 new=$(git rev-parse --verify HEAD) &&
383 test_tick &&
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 &&
82ebb0b6 387 test_cmp expected actual
1eb1e9ee
JH
388
389'
390
8a2f8733
JH
391test_expect_success 'amend using the message from a commit named with tag' '
392
393 git reset --hard &&
394 test_tick &&
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 &&
398 test_tick &&
399 git commit --allow-empty -m "new commit" &&
400 new=$(git rev-parse --verify HEAD) &&
401 test_tick &&
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 &&
82ebb0b6 405 test_cmp expected actual
8a2f8733
JH
406
407'
408
12ace0b2 409test_done