Allow git commit --interactive with paths
[git/jnareb-git.git] / t / t7501-commit.sh
blobc2fd116d633351eeaa75cc4040f6e4a73670975b
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 C_LOCALE_OUTPUT \
20 "Constructing initial commit" \
21 "git status | grep 'Initial commit'"
23 test_expect_success \
24 "fail initial amend" \
25 "test_must_fail git commit --amend"
27 test_expect_success \
28 "initial commit" \
29 "git commit -m initial"
31 test_expect_success \
32 "invalid options 1" \
33 "test_must_fail git commit -m foo -m bar -F file"
35 test_expect_success \
36 "invalid options 2" \
37 "test_must_fail git commit -C HEAD -m illegal"
39 test_expect_success \
40 "using paths with -a" \
41 "echo King of the bongo >file &&
42 test_must_fail git commit -m foo -a file"
44 test_expect_success PERL 'can use paths with --interactive' '
45 echo bong-o-bong >file &&
46 # 2: update, 1:st path, that is all, 7: quit
47 ( echo 2; echo 1; echo; echo 7 ) |
48 git commit -m foo --interactive file &&
49 git reset --hard HEAD^
52 test_expect_success \
53 "using invalid commit with -C" \
54 "test_must_fail git commit -C bogus"
56 test_expect_success \
57 "testing nothing to commit" \
58 "test_must_fail git commit -m initial"
60 test_expect_success \
61 "next commit" \
62 "echo 'bongo bongo bongo' >file \
63 git commit -m next -a"
65 test_expect_success \
66 "commit message from non-existing file" \
67 "echo 'more bongo: bongo bongo bongo bongo' >file && \
68 test_must_fail git commit -F gah -a"
70 # Empty except stray tabs and spaces on a few lines.
71 sed -e 's/@$//' >msg <<EOF
75 Signed-off-by: hula
76 EOF
77 test_expect_success \
78 "empty commit message" \
79 "test_must_fail git commit -F msg -a"
81 test_expect_success \
82 "commit message from file" \
83 "echo 'this is the commit message, coming from a file' >msg && \
84 git commit -F msg -a"
86 cat >editor <<\EOF
87 #!/bin/sh
88 sed -e "s/a file/an amend commit/g" < "$1" > "$1-"
89 mv "$1-" "$1"
90 EOF
91 chmod 755 editor
93 test_expect_success \
94 "amend commit" \
95 "EDITOR=./editor git commit --amend"
97 test_expect_success \
98 "passing -m and -F" \
99 "echo 'enough with the bongos' >file && \
100 test_must_fail git commit -F msg -m amending ."
102 test_expect_success \
103 "using message from other commit" \
104 "git commit -C HEAD^ ."
106 cat >editor <<\EOF
107 #!/bin/sh
108 sed -e "s/amend/older/g" < "$1" > "$1-"
109 mv "$1-" "$1"
111 chmod 755 editor
113 test_expect_success \
114 "editing message from other commit" \
115 "echo 'hula hula' >file && \
116 EDITOR=./editor git commit -c HEAD^ -a"
118 test_expect_success \
119 "message from stdin" \
120 "echo 'silly new contents' >file && \
121 echo commit message from stdin | git commit -F - -a"
123 test_expect_success \
124 "overriding author from command line" \
125 "echo 'gak' >file && \
126 git commit -m 'author' --author 'Rubber Duck <rduck@convoy.org>' -a >output 2>&1"
128 test_expect_success \
129 "commit --author output mentions author" \
130 "grep Rubber.Duck output"
132 test_expect_success PERL \
133 "interactive add" \
134 "echo 7 | git commit --interactive | grep 'What now'"
136 test_expect_success \
137 "showing committed revisions" \
138 "git rev-list HEAD >current"
140 cat >editor <<\EOF
141 #!/bin/sh
142 sed -e "s/good/bad/g" < "$1" > "$1-"
143 mv "$1-" "$1"
145 chmod 755 editor
147 cat >msg <<EOF
148 A good commit message.
151 test_expect_success \
152 'editor not invoked if -F is given' '
153 echo "moo" >file &&
154 EDITOR=./editor git commit -a -F msg &&
155 git show -s --pretty=format:"%s" | grep -q good &&
156 echo "quack" >file &&
157 echo "Another good message." | EDITOR=./editor git commit -a -F - &&
158 git show -s --pretty=format:"%s" | grep -q good
160 # We could just check the head sha1, but checking each commit makes it
161 # easier to isolate bugs.
163 cat >expected <<\EOF
164 72c0dc9855b0c9dadcbfd5a31cab072e0cb774ca
165 9b88fc14ce6b32e3d9ee021531a54f18a5cf38a2
166 3536bbb352c3a1ef9a420f5b4242d48578b92aa7
167 d381ac431806e53f3dd7ac2f1ae0534f36d738b9
168 4fd44095ad6334f3ef72e4c5ec8ddf108174b54a
169 402702b49136e7587daa9280e91e4bb7cb2179f7
172 test_expect_success \
173 'validate git rev-list output.' \
174 'test_cmp expected current'
176 test_expect_success 'partial commit that involves removal (1)' '
178 git rm --cached file &&
179 mv file elif &&
180 git add elif &&
181 git commit -m "Partial: add elif" elif &&
182 git diff-tree --name-status HEAD^ HEAD >current &&
183 echo "A elif" >expected &&
184 test_cmp expected current
188 test_expect_success 'partial commit that involves removal (2)' '
190 git commit -m "Partial: remove file" file &&
191 git diff-tree --name-status HEAD^ HEAD >current &&
192 echo "D file" >expected &&
193 test_cmp expected current
197 test_expect_success 'partial commit that involves removal (3)' '
199 git rm --cached elif &&
200 echo elif >elif &&
201 git commit -m "Partial: modify elif" elif &&
202 git diff-tree --name-status HEAD^ HEAD >current &&
203 echo "M elif" >expected &&
204 test_cmp expected current
208 author="The Real Author <someguy@his.email.org>"
209 test_expect_success 'amend commit to fix author' '
211 oldtick=$GIT_AUTHOR_DATE &&
212 test_tick &&
213 git reset --hard &&
214 git cat-file -p HEAD |
215 sed -e "s/author.*/author $author $oldtick/" \
216 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
217 expected &&
218 git commit --amend --author="$author" &&
219 git cat-file -p HEAD > current &&
220 test_cmp expected current
224 test_expect_success 'amend commit to fix date' '
226 test_tick &&
227 newtick=$GIT_AUTHOR_DATE &&
228 git reset --hard &&
229 git cat-file -p HEAD |
230 sed -e "s/author.*/author $author $newtick/" \
231 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
232 expected &&
233 git commit --amend --date="$newtick" &&
234 git cat-file -p HEAD > current &&
235 test_cmp expected current
239 test_expect_success 'commit complains about bogus date' '
240 test_must_fail git commit --amend --date=10.11.2010
243 test_expect_success 'sign off (1)' '
245 echo 1 >positive &&
246 git add positive &&
247 git commit -s -m "thank you" &&
248 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
250 echo thank you
251 echo
252 git var GIT_COMMITTER_IDENT |
253 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
254 ) >expected &&
255 test_cmp expected actual
259 test_expect_success 'sign off (2)' '
261 echo 2 >positive &&
262 git add positive &&
263 existing="Signed-off-by: Watch This <watchthis@example.com>" &&
264 git commit -s -m "thank you
266 $existing" &&
267 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
269 echo thank you
270 echo
271 echo $existing
272 git var GIT_COMMITTER_IDENT |
273 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
274 ) >expected &&
275 test_cmp expected actual
279 test_expect_success 'signoff gap' '
281 echo 3 >positive &&
282 git add positive &&
283 alt="Alt-RFC-822-Header: Value" &&
284 git commit -s -m "welcome
286 $alt" &&
287 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
289 echo welcome
290 echo
291 echo $alt
292 git var GIT_COMMITTER_IDENT |
293 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
294 ) >expected &&
295 test_cmp expected actual
298 test_expect_success 'signoff gap 2' '
300 echo 4 >positive &&
301 git add positive &&
302 alt="fixed: 34" &&
303 git commit -s -m "welcome
305 We have now
306 $alt" &&
307 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
309 echo welcome
310 echo
311 echo We have now
312 echo $alt
313 echo
314 git var GIT_COMMITTER_IDENT |
315 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
316 ) >expected &&
317 test_cmp expected actual
320 test_expect_success 'multiple -m' '
322 >negative &&
323 git add negative &&
324 git commit -m "one" -m "two" -m "three" &&
325 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
327 echo one
328 echo
329 echo two
330 echo
331 echo three
332 ) >expected &&
333 test_cmp expected actual
337 author="The Real Author <someguy@his.email.org>"
338 test_expect_success 'amend commit to fix author' '
340 oldtick=$GIT_AUTHOR_DATE &&
341 test_tick &&
342 git reset --hard &&
343 git cat-file -p HEAD |
344 sed -e "s/author.*/author $author $oldtick/" \
345 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
346 expected &&
347 git commit --amend --author="$author" &&
348 git cat-file -p HEAD > current &&
349 test_cmp expected current
353 test_expect_success 'git commit <file> with dirty index' '
354 echo tacocat > elif &&
355 echo tehlulz > chz &&
356 git add chz &&
357 git commit elif -m "tacocat is a palindrome" &&
358 git show --stat | grep elif &&
359 git diff --cached | grep chz
362 test_expect_success 'same tree (single parent)' '
364 git reset --hard
366 if git commit -m empty
367 then
368 echo oops -- should have complained
369 false
370 else
371 : happy
376 test_expect_success 'same tree (single parent) --allow-empty' '
378 git commit --allow-empty -m "forced empty" &&
379 git cat-file commit HEAD | grep forced
383 test_expect_success 'same tree (merge and amend merge)' '
385 git checkout -b side HEAD^ &&
386 echo zero >zero &&
387 git add zero &&
388 git commit -m "add zero" &&
389 git checkout master &&
391 git merge -s ours side -m "empty ok" &&
392 git diff HEAD^ HEAD >actual &&
393 : >expected &&
394 test_cmp expected actual &&
396 git commit --amend -m "empty really ok" &&
397 git diff HEAD^ HEAD >actual &&
398 : >expected &&
399 test_cmp expected actual
403 test_expect_success 'amend using the message from another commit' '
405 git reset --hard &&
406 test_tick &&
407 git commit --allow-empty -m "old commit" &&
408 old=$(git rev-parse --verify HEAD) &&
409 test_tick &&
410 git commit --allow-empty -m "new commit" &&
411 new=$(git rev-parse --verify HEAD) &&
412 test_tick &&
413 git commit --allow-empty --amend -C "$old" &&
414 git show --pretty="format:%ad %s" "$old" >expected &&
415 git show --pretty="format:%ad %s" HEAD >actual &&
416 test_cmp expected actual
420 test_expect_success 'amend using the message from a commit named with tag' '
422 git reset --hard &&
423 test_tick &&
424 git commit --allow-empty -m "old commit" &&
425 old=$(git rev-parse --verify HEAD) &&
426 git tag -a -m "tag on old" tagged-old HEAD &&
427 test_tick &&
428 git commit --allow-empty -m "new commit" &&
429 new=$(git rev-parse --verify HEAD) &&
430 test_tick &&
431 git commit --allow-empty --amend -C tagged-old &&
432 git show --pretty="format:%ad %s" "$old" >expected &&
433 git show --pretty="format:%ad %s" HEAD >actual &&
434 test_cmp expected actual
438 test_expect_success 'amend can copy notes' '
440 git config notes.rewrite.amend true &&
441 git config notes.rewriteRef "refs/notes/*" &&
442 test_commit foo &&
443 git notes add -m"a note" &&
444 test_tick &&
445 git commit --amend -m"new foo" &&
446 test "$(git notes show)" = "a note"
450 test_done