test: add missing "&&" after echo command
[git/jrn.git] / t / t7501-commit.sh
blobda75abc1bf9adc8a9528d514ce9813f20303d01f
1 #!/bin/sh
3 # Copyright (c) 2007 Kristian Høgsberg <krh@redhat.com>
6 # FIXME: Test the various index usages, -i and -o, test reflog,
7 # signoff
9 test_description='git commit'
10 . ./test-lib.sh
12 test_tick
14 test_expect_success \
15 "initial status" \
16 "echo 'bongo bongo' >file &&
17 git add file"
19 test_expect_success "Constructing initial commit" '
20 git status >actual &&
21 test_i18ngrep "Initial commit" actual
24 test_expect_success \
25 "fail initial amend" \
26 "test_must_fail git commit --amend"
28 test_expect_success \
29 "initial commit" \
30 "git commit -m initial"
32 test_expect_success \
33 "invalid options 1" \
34 "test_must_fail git commit -m foo -m bar -F file"
36 test_expect_success \
37 "invalid options 2" \
38 "test_must_fail git commit -C HEAD -m illegal"
40 test_expect_success \
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 'can use paths with --interactive' '
46 echo bong-o-bong >file &&
47 # 2: update, 1:st path, that is all, 7: quit
48 ( echo 2; echo 1; echo; echo 7 ) |
49 git commit -m foo --interactive file &&
50 git reset --hard HEAD^
53 test_expect_success \
54 "using invalid commit with -C" \
55 "test_must_fail git commit -C bogus"
57 test_expect_success \
58 "testing nothing to commit" \
59 "test_must_fail git commit -m initial"
61 test_expect_success \
62 "next commit" \
63 "echo 'bongo bongo bongo' >file && \
64 git commit -m next -a"
66 test_expect_success \
67 "commit message from non-existing file" \
68 "echo 'more bongo: bongo bongo bongo bongo' >file && \
69 test_must_fail git commit -F gah -a"
71 # Empty except stray tabs and spaces on a few lines.
72 sed -e 's/@$//' >msg <<EOF
76 Signed-off-by: hula
77 EOF
78 test_expect_success \
79 "empty commit message" \
80 "test_must_fail git commit -F msg -a"
82 test_expect_success \
83 "commit message from file" \
84 "echo 'this is the commit message, coming from a file' >msg && \
85 git commit -F msg -a"
87 cat >editor <<\EOF
88 #!/bin/sh
89 sed -e "s/a file/an amend commit/g" < "$1" > "$1-"
90 mv "$1-" "$1"
91 EOF
92 chmod 755 editor
94 test_expect_success \
95 "amend commit" \
96 "EDITOR=./editor git commit --amend"
98 test_expect_success \
99 "passing -m and -F" \
100 "echo 'enough with the bongos' >file && \
101 test_must_fail git commit -F msg -m amending ."
103 test_expect_success \
104 "using message from other commit" \
105 "git commit -C HEAD^ ."
107 cat >editor <<\EOF
108 #!/bin/sh
109 sed -e "s/amend/older/g" < "$1" > "$1-"
110 mv "$1-" "$1"
112 chmod 755 editor
114 test_expect_success \
115 "editing message from other commit" \
116 "echo 'hula hula' >file && \
117 EDITOR=./editor git commit -c HEAD^ -a"
119 test_expect_success \
120 "message from stdin" \
121 "echo 'silly new contents' >file && \
122 echo commit message from stdin | git commit -F - -a"
124 test_expect_success \
125 "overriding author from command line" \
126 "echo 'gak' >file && \
127 git commit -m 'author' --author 'Rubber Duck <rduck@convoy.org>' -a >output 2>&1"
129 test_expect_success \
130 "commit --author output mentions author" \
131 "grep Rubber.Duck output"
133 test_expect_success PERL \
134 "interactive add" \
135 "echo 7 | git commit --interactive | grep 'What now'"
137 test_expect_success PERL \
138 "commit --interactive doesn't change index if editor aborts" \
139 "echo zoo >file &&
140 test_must_fail git diff --exit-code >diff1 &&
141 (echo u ; echo '*' ; echo q) |
142 (EDITOR=: && export EDITOR &&
143 test_must_fail git commit --interactive) &&
144 git diff >diff2 &&
145 test_cmp diff1 diff2"
147 test_expect_success \
148 "showing committed revisions" \
149 "git rev-list HEAD >current"
151 cat >editor <<\EOF
152 #!/bin/sh
153 sed -e "s/good/bad/g" < "$1" > "$1-"
154 mv "$1-" "$1"
156 chmod 755 editor
158 cat >msg <<EOF
159 A good commit message.
162 test_expect_success \
163 'editor not invoked if -F is given' '
164 echo "moo" >file &&
165 EDITOR=./editor git commit -a -F msg &&
166 git show -s --pretty=format:"%s" | grep -q good &&
167 echo "quack" >file &&
168 echo "Another good message." | EDITOR=./editor git commit -a -F - &&
169 git show -s --pretty=format:"%s" | grep -q good
171 # We could just check the head sha1, but checking each commit makes it
172 # easier to isolate bugs.
174 cat >expected <<\EOF
175 285fcf7ec0d61b14249dfdb4c1e1fe03eaf15ee0
176 0b8148b9afce917b87d71199b900466dc8ea8b6e
177 43fb8826314939ce79a856face7953557fdca3d1
178 eaa04bc3ae0f0b003f7f1d86bf869ec5d73eaf3e
179 ee1963b250ee0f02a3fe37be0e4a02bb5af6a1ad
180 b49f306003c627361a0304d151a6b4c8b26af6a1
181 402702b49136e7587daa9280e91e4bb7cb2179f7
184 test_expect_success \
185 'validate git rev-list output.' \
186 'test_cmp expected current'
188 test_expect_success 'partial commit that involves removal (1)' '
190 git rm --cached file &&
191 mv file elif &&
192 git add elif &&
193 git commit -m "Partial: add elif" elif &&
194 git diff-tree --name-status HEAD^ HEAD >current &&
195 echo "A elif" >expected &&
196 test_cmp expected current
200 test_expect_success 'partial commit that involves removal (2)' '
202 git commit -m "Partial: remove file" file &&
203 git diff-tree --name-status HEAD^ HEAD >current &&
204 echo "D file" >expected &&
205 test_cmp expected current
209 test_expect_success 'partial commit that involves removal (3)' '
211 git rm --cached elif &&
212 echo elif >elif &&
213 git commit -m "Partial: modify elif" elif &&
214 git diff-tree --name-status HEAD^ HEAD >current &&
215 echo "M elif" >expected &&
216 test_cmp expected current
220 author="The Real Author <someguy@his.email.org>"
221 test_expect_success 'amend commit to fix author' '
223 oldtick=$GIT_AUTHOR_DATE &&
224 test_tick &&
225 git reset --hard &&
226 git cat-file -p HEAD |
227 sed -e "s/author.*/author $author $oldtick/" \
228 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
229 expected &&
230 git commit --amend --author="$author" &&
231 git cat-file -p HEAD > current &&
232 test_cmp expected current
236 test_expect_success 'amend commit to fix date' '
238 test_tick &&
239 newtick=$GIT_AUTHOR_DATE &&
240 git reset --hard &&
241 git cat-file -p HEAD |
242 sed -e "s/author.*/author $author $newtick/" \
243 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
244 expected &&
245 git commit --amend --date="$newtick" &&
246 git cat-file -p HEAD > current &&
247 test_cmp expected current
251 test_expect_success 'commit complains about bogus date' '
252 test_must_fail git commit --amend --date=10.11.2010
255 test_expect_success 'sign off (1)' '
257 echo 1 >positive &&
258 git add positive &&
259 git commit -s -m "thank you" &&
260 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
262 echo thank you
263 echo
264 git var GIT_COMMITTER_IDENT |
265 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
266 ) >expected &&
267 test_cmp expected actual
271 test_expect_success 'sign off (2)' '
273 echo 2 >positive &&
274 git add positive &&
275 existing="Signed-off-by: Watch This <watchthis@example.com>" &&
276 git commit -s -m "thank you
278 $existing" &&
279 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
281 echo thank you
282 echo
283 echo $existing
284 git var GIT_COMMITTER_IDENT |
285 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
286 ) >expected &&
287 test_cmp expected actual
291 test_expect_success 'signoff gap' '
293 echo 3 >positive &&
294 git add positive &&
295 alt="Alt-RFC-822-Header: Value" &&
296 git commit -s -m "welcome
298 $alt" &&
299 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
301 echo welcome
302 echo
303 echo $alt
304 git var GIT_COMMITTER_IDENT |
305 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
306 ) >expected &&
307 test_cmp expected actual
310 test_expect_success 'signoff gap 2' '
312 echo 4 >positive &&
313 git add positive &&
314 alt="fixed: 34" &&
315 git commit -s -m "welcome
317 We have now
318 $alt" &&
319 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
321 echo welcome
322 echo
323 echo We have now
324 echo $alt
325 echo
326 git var GIT_COMMITTER_IDENT |
327 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
328 ) >expected &&
329 test_cmp expected actual
332 test_expect_success 'multiple -m' '
334 >negative &&
335 git add negative &&
336 git commit -m "one" -m "two" -m "three" &&
337 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
339 echo one
340 echo
341 echo two
342 echo
343 echo three
344 ) >expected &&
345 test_cmp expected actual
349 author="The Real Author <someguy@his.email.org>"
350 test_expect_success 'amend commit to fix author' '
352 oldtick=$GIT_AUTHOR_DATE &&
353 test_tick &&
354 git reset --hard &&
355 git cat-file -p HEAD |
356 sed -e "s/author.*/author $author $oldtick/" \
357 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
358 expected &&
359 git commit --amend --author="$author" &&
360 git cat-file -p HEAD > current &&
361 test_cmp expected current
365 test_expect_success 'git commit <file> with dirty index' '
366 echo tacocat > elif &&
367 echo tehlulz > chz &&
368 git add chz &&
369 git commit elif -m "tacocat is a palindrome" &&
370 git show --stat | grep elif &&
371 git diff --cached | grep chz
374 test_expect_success 'same tree (single parent)' '
376 git reset --hard
378 if git commit -m empty
379 then
380 echo oops -- should have complained
381 false
382 else
383 : happy
388 test_expect_success 'same tree (single parent) --allow-empty' '
390 git commit --allow-empty -m "forced empty" &&
391 git cat-file commit HEAD | grep forced
395 test_expect_success 'same tree (merge and amend merge)' '
397 git checkout -b side HEAD^ &&
398 echo zero >zero &&
399 git add zero &&
400 git commit -m "add zero" &&
401 git checkout master &&
403 git merge -s ours side -m "empty ok" &&
404 git diff HEAD^ HEAD >actual &&
405 : >expected &&
406 test_cmp expected actual &&
408 git commit --amend -m "empty really ok" &&
409 git diff HEAD^ HEAD >actual &&
410 : >expected &&
411 test_cmp expected actual
415 test_expect_success 'amend using the message from another commit' '
417 git reset --hard &&
418 test_tick &&
419 git commit --allow-empty -m "old commit" &&
420 old=$(git rev-parse --verify HEAD) &&
421 test_tick &&
422 git commit --allow-empty -m "new commit" &&
423 new=$(git rev-parse --verify HEAD) &&
424 test_tick &&
425 git commit --allow-empty --amend -C "$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 using the message from a commit named with tag' '
434 git reset --hard &&
435 test_tick &&
436 git commit --allow-empty -m "old commit" &&
437 old=$(git rev-parse --verify HEAD) &&
438 git tag -a -m "tag on old" tagged-old HEAD &&
439 test_tick &&
440 git commit --allow-empty -m "new commit" &&
441 new=$(git rev-parse --verify HEAD) &&
442 test_tick &&
443 git commit --allow-empty --amend -C tagged-old &&
444 git show --pretty="format:%ad %s" "$old" >expected &&
445 git show --pretty="format:%ad %s" HEAD >actual &&
446 test_cmp expected actual
450 test_expect_success 'amend can copy notes' '
452 git config notes.rewrite.amend true &&
453 git config notes.rewriteRef "refs/notes/*" &&
454 test_commit foo &&
455 git notes add -m"a note" &&
456 test_tick &&
457 git commit --amend -m"new foo" &&
458 test "$(git notes show)" = "a note"
462 test_done