diff.c: omit hidden entries from namelen calculation with --stat
[git/dscho.git] / t / t7501-commit.sh
blob7f7f7c7b95475b3b0673de00b68914a08098aead
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 \
46 "using paths with --interactive" \
47 "echo bong-o-bong >file &&
48 ! (echo 7 | git commit -m foo --interactive file)"
50 test_expect_success \
51 "using invalid commit with -C" \
52 "test_must_fail git commit -C bogus"
54 test_expect_success \
55 "testing nothing to commit" \
56 "test_must_fail git commit -m initial"
58 test_expect_success \
59 "next commit" \
60 "echo 'bongo bongo bongo' >file \
61 git commit -m next -a"
63 test_expect_success \
64 "commit message from non-existing file" \
65 "echo 'more bongo: bongo bongo bongo bongo' >file && \
66 test_must_fail git commit -F gah -a"
68 # Empty except stray tabs and spaces on a few lines.
69 sed -e 's/@$//' >msg <<EOF
73 Signed-off-by: hula
74 EOF
75 test_expect_success \
76 "empty commit message" \
77 "test_must_fail git commit -F msg -a"
79 test_expect_success \
80 "commit message from file" \
81 "echo 'this is the commit message, coming from a file' >msg && \
82 git commit -F msg -a"
84 cat >editor <<\EOF
85 #!/bin/sh
86 sed -e "s/a file/an amend commit/g" < "$1" > "$1-"
87 mv "$1-" "$1"
88 EOF
89 chmod 755 editor
91 test_expect_success \
92 "amend commit" \
93 "EDITOR=./editor git commit --amend"
95 test_expect_success \
96 "passing -m and -F" \
97 "echo 'enough with the bongos' >file && \
98 test_must_fail git commit -F msg -m amending ."
100 test_expect_success \
101 "using message from other commit" \
102 "git commit -C HEAD^ ."
104 cat >editor <<\EOF
105 #!/bin/sh
106 sed -e "s/amend/older/g" < "$1" > "$1-"
107 mv "$1-" "$1"
109 chmod 755 editor
111 test_expect_success \
112 "editing message from other commit" \
113 "echo 'hula hula' >file && \
114 EDITOR=./editor git commit -c HEAD^ -a"
116 test_expect_success \
117 "message from stdin" \
118 "echo 'silly new contents' >file && \
119 echo commit message from stdin | git commit -F - -a"
121 test_expect_success \
122 "overriding author from command line" \
123 "echo 'gak' >file && \
124 git commit -m 'author' --author 'Rubber Duck <rduck@convoy.org>' -a >output 2>&1"
126 test_expect_success \
127 "commit --author output mentions author" \
128 "grep Rubber.Duck output"
130 test_expect_success PERL \
131 "interactive add" \
132 "echo 7 | git commit --interactive | grep 'What now'"
134 test_expect_success \
135 "showing committed revisions" \
136 "git rev-list HEAD >current"
138 cat >editor <<\EOF
139 #!/bin/sh
140 sed -e "s/good/bad/g" < "$1" > "$1-"
141 mv "$1-" "$1"
143 chmod 755 editor
145 cat >msg <<EOF
146 A good commit message.
149 test_expect_success \
150 'editor not invoked if -F is given' '
151 echo "moo" >file &&
152 EDITOR=./editor git commit -a -F msg &&
153 git show -s --pretty=format:"%s" | grep -q good &&
154 echo "quack" >file &&
155 echo "Another good message." | EDITOR=./editor git commit -a -F - &&
156 git show -s --pretty=format:"%s" | grep -q good
158 # We could just check the head sha1, but checking each commit makes it
159 # easier to isolate bugs.
161 cat >expected <<\EOF
162 72c0dc9855b0c9dadcbfd5a31cab072e0cb774ca
163 9b88fc14ce6b32e3d9ee021531a54f18a5cf38a2
164 3536bbb352c3a1ef9a420f5b4242d48578b92aa7
165 d381ac431806e53f3dd7ac2f1ae0534f36d738b9
166 4fd44095ad6334f3ef72e4c5ec8ddf108174b54a
167 402702b49136e7587daa9280e91e4bb7cb2179f7
170 test_expect_success \
171 'validate git rev-list output.' \
172 'test_cmp expected current'
174 test_expect_success 'partial commit that involves removal (1)' '
176 git rm --cached file &&
177 mv file elif &&
178 git add elif &&
179 git commit -m "Partial: add elif" elif &&
180 git diff-tree --name-status HEAD^ HEAD >current &&
181 echo "A elif" >expected &&
182 test_cmp expected current
186 test_expect_success 'partial commit that involves removal (2)' '
188 git commit -m "Partial: remove file" file &&
189 git diff-tree --name-status HEAD^ HEAD >current &&
190 echo "D file" >expected &&
191 test_cmp expected current
195 test_expect_success 'partial commit that involves removal (3)' '
197 git rm --cached elif &&
198 echo elif >elif &&
199 git commit -m "Partial: modify elif" elif &&
200 git diff-tree --name-status HEAD^ HEAD >current &&
201 echo "M elif" >expected &&
202 test_cmp expected current
206 author="The Real Author <someguy@his.email.org>"
207 test_expect_success 'amend commit to fix author' '
209 oldtick=$GIT_AUTHOR_DATE &&
210 test_tick &&
211 git reset --hard &&
212 git cat-file -p HEAD |
213 sed -e "s/author.*/author $author $oldtick/" \
214 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
215 expected &&
216 git commit --amend --author="$author" &&
217 git cat-file -p HEAD > current &&
218 test_cmp expected current
222 test_expect_success 'amend commit to fix date' '
224 test_tick &&
225 newtick=$GIT_AUTHOR_DATE &&
226 git reset --hard &&
227 git cat-file -p HEAD |
228 sed -e "s/author.*/author $author $newtick/" \
229 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
230 expected &&
231 git commit --amend --date="$newtick" &&
232 git cat-file -p HEAD > current &&
233 test_cmp expected current
237 test_expect_success 'commit complains about bogus date' '
238 test_must_fail git commit --amend --date=10.11.2010
241 test_expect_success 'sign off (1)' '
243 echo 1 >positive &&
244 git add positive &&
245 git commit -s -m "thank you" &&
246 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
248 echo thank you
249 echo
250 git var GIT_COMMITTER_IDENT |
251 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
252 ) >expected &&
253 test_cmp expected actual
257 test_expect_success 'sign off (2)' '
259 echo 2 >positive &&
260 git add positive &&
261 existing="Signed-off-by: Watch This <watchthis@example.com>" &&
262 git commit -s -m "thank you
264 $existing" &&
265 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
267 echo thank you
268 echo
269 echo $existing
270 git var GIT_COMMITTER_IDENT |
271 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
272 ) >expected &&
273 test_cmp expected actual
277 test_expect_success 'signoff gap' '
279 echo 3 >positive &&
280 git add positive &&
281 alt="Alt-RFC-822-Header: Value" &&
282 git commit -s -m "welcome
284 $alt" &&
285 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
287 echo welcome
288 echo
289 echo $alt
290 git var GIT_COMMITTER_IDENT |
291 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
292 ) >expected &&
293 test_cmp expected actual
296 test_expect_success 'signoff gap 2' '
298 echo 4 >positive &&
299 git add positive &&
300 alt="fixed: 34" &&
301 git commit -s -m "welcome
303 We have now
304 $alt" &&
305 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
307 echo welcome
308 echo
309 echo We have now
310 echo $alt
311 echo
312 git var GIT_COMMITTER_IDENT |
313 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
314 ) >expected &&
315 test_cmp expected actual
318 test_expect_success 'multiple -m' '
320 >negative &&
321 git add negative &&
322 git commit -m "one" -m "two" -m "three" &&
323 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
325 echo one
326 echo
327 echo two
328 echo
329 echo three
330 ) >expected &&
331 test_cmp expected actual
335 author="The Real Author <someguy@his.email.org>"
336 test_expect_success 'amend commit to fix author' '
338 oldtick=$GIT_AUTHOR_DATE &&
339 test_tick &&
340 git reset --hard &&
341 git cat-file -p HEAD |
342 sed -e "s/author.*/author $author $oldtick/" \
343 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
344 expected &&
345 git commit --amend --author="$author" &&
346 git cat-file -p HEAD > current &&
347 test_cmp expected current
351 test_expect_success 'git commit <file> with dirty index' '
352 echo tacocat > elif &&
353 echo tehlulz > chz &&
354 git add chz &&
355 git commit elif -m "tacocat is a palindrome" &&
356 git show --stat | grep elif &&
357 git diff --cached | grep chz
360 test_expect_success 'same tree (single parent)' '
362 git reset --hard
364 if git commit -m empty
365 then
366 echo oops -- should have complained
367 false
368 else
369 : happy
374 test_expect_success 'same tree (single parent) --allow-empty' '
376 git commit --allow-empty -m "forced empty" &&
377 git cat-file commit HEAD | grep forced
381 test_expect_success 'same tree (merge and amend merge)' '
383 git checkout -b side HEAD^ &&
384 echo zero >zero &&
385 git add zero &&
386 git commit -m "add zero" &&
387 git checkout master &&
389 git merge -s ours side -m "empty ok" &&
390 git diff HEAD^ HEAD >actual &&
391 : >expected &&
392 test_cmp expected actual &&
394 git commit --amend -m "empty really ok" &&
395 git diff HEAD^ HEAD >actual &&
396 : >expected &&
397 test_cmp expected actual
401 test_expect_success 'amend using the message from another commit' '
403 git reset --hard &&
404 test_tick &&
405 git commit --allow-empty -m "old commit" &&
406 old=$(git rev-parse --verify HEAD) &&
407 test_tick &&
408 git commit --allow-empty -m "new commit" &&
409 new=$(git rev-parse --verify HEAD) &&
410 test_tick &&
411 git commit --allow-empty --amend -C "$old" &&
412 git show --pretty="format:%ad %s" "$old" >expected &&
413 git show --pretty="format:%ad %s" HEAD >actual &&
414 test_cmp expected actual
418 test_expect_success 'amend using the message from a commit named with tag' '
420 git reset --hard &&
421 test_tick &&
422 git commit --allow-empty -m "old commit" &&
423 old=$(git rev-parse --verify HEAD) &&
424 git tag -a -m "tag on old" tagged-old HEAD &&
425 test_tick &&
426 git commit --allow-empty -m "new commit" &&
427 new=$(git rev-parse --verify HEAD) &&
428 test_tick &&
429 git commit --allow-empty --amend -C tagged-old &&
430 git show --pretty="format:%ad %s" "$old" >expected &&
431 git show --pretty="format:%ad %s" HEAD >actual &&
432 test_cmp expected actual
436 test_expect_success 'amend can copy notes' '
438 git config notes.rewrite.amend true &&
439 git config notes.rewriteRef "refs/notes/*" &&
440 test_commit foo &&
441 git notes add -m"a note" &&
442 test_tick &&
443 git commit --amend -m"new foo" &&
444 test "$(git notes show)" = "a note"
448 test_done