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