read_directory_recursive(): refactor handling of a single path into a separate function
[git/gitweb.git] / t / t7501-commit.sh
bloba5297012410271f64398124da6e4c7dd8eec3154
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 && \
18 git status | grep 'Initial commit'"
20 test_expect_success \
21 "fail initial amend" \
22 "test_must_fail git commit --amend"
24 test_expect_success \
25 "initial commit" \
26 "git commit -m initial"
28 test_expect_success \
29 "invalid options 1" \
30 "test_must_fail git commit -m foo -m bar -F file"
32 test_expect_success \
33 "invalid options 2" \
34 "test_must_fail git commit -C HEAD -m illegal"
36 test_expect_success \
37 "using paths with -a" \
38 "echo King of the bongo >file &&
39 test_must_fail git commit -m foo -a file"
41 test_expect_success PERL \
42 "using paths with --interactive" \
43 "echo bong-o-bong >file &&
44 ! (echo 7 | git commit -m foo --interactive file)"
46 test_expect_success \
47 "using invalid commit with -C" \
48 "test_must_fail git commit -C bogus"
50 test_expect_success \
51 "testing nothing to commit" \
52 "test_must_fail git commit -m initial"
54 test_expect_success \
55 "next commit" \
56 "echo 'bongo bongo bongo' >file \
57 git commit -m next -a"
59 test_expect_success \
60 "commit message from non-existing file" \
61 "echo 'more bongo: bongo bongo bongo bongo' >file && \
62 test_must_fail git commit -F gah -a"
64 # Empty except stray tabs and spaces on a few lines.
65 sed -e 's/@$//' >msg <<EOF
69 Signed-off-by: hula
70 EOF
71 test_expect_success \
72 "empty commit message" \
73 "test_must_fail git commit -F msg -a"
75 test_expect_success \
76 "commit message from file" \
77 "echo 'this is the commit message, coming from a file' >msg && \
78 git commit -F msg -a"
80 cat >editor <<\EOF
81 #!/bin/sh
82 sed -e "s/a file/an amend commit/g" < "$1" > "$1-"
83 mv "$1-" "$1"
84 EOF
85 chmod 755 editor
87 test_expect_success \
88 "amend commit" \
89 "EDITOR=./editor git commit --amend"
91 test_expect_success \
92 "passing -m and -F" \
93 "echo 'enough with the bongos' >file && \
94 test_must_fail git commit -F msg -m amending ."
96 test_expect_success \
97 "using message from other commit" \
98 "git commit -C HEAD^ ."
100 cat >editor <<\EOF
101 #!/bin/sh
102 sed -e "s/amend/older/g" < "$1" > "$1-"
103 mv "$1-" "$1"
105 chmod 755 editor
107 test_expect_success \
108 "editing message from other commit" \
109 "echo 'hula hula' >file && \
110 EDITOR=./editor git commit -c HEAD^ -a"
112 test_expect_success \
113 "message from stdin" \
114 "echo 'silly new contents' >file && \
115 echo commit message from stdin | git commit -F - -a"
117 test_expect_success \
118 "overriding author from command line" \
119 "echo 'gak' >file && \
120 git commit -m 'author' --author 'Rubber Duck <rduck@convoy.org>' -a"
122 test_expect_success PERL \
123 "interactive add" \
124 "echo 7 | git commit --interactive | grep 'What now'"
126 test_expect_success \
127 "showing committed revisions" \
128 "git rev-list HEAD >current"
130 cat >editor <<\EOF
131 #!/bin/sh
132 sed -e "s/good/bad/g" < "$1" > "$1-"
133 mv "$1-" "$1"
135 chmod 755 editor
137 cat >msg <<EOF
138 A good commit message.
141 test_expect_success \
142 'editor not invoked if -F is given' '
143 echo "moo" >file &&
144 EDITOR=./editor git commit -a -F msg &&
145 git show -s --pretty=format:"%s" | grep -q good &&
146 echo "quack" >file &&
147 echo "Another good message." | EDITOR=./editor git commit -a -F - &&
148 git show -s --pretty=format:"%s" | grep -q good
150 # We could just check the head sha1, but checking each commit makes it
151 # easier to isolate bugs.
153 cat >expected <<\EOF
154 72c0dc9855b0c9dadcbfd5a31cab072e0cb774ca
155 9b88fc14ce6b32e3d9ee021531a54f18a5cf38a2
156 3536bbb352c3a1ef9a420f5b4242d48578b92aa7
157 d381ac431806e53f3dd7ac2f1ae0534f36d738b9
158 4fd44095ad6334f3ef72e4c5ec8ddf108174b54a
159 402702b49136e7587daa9280e91e4bb7cb2179f7
162 test_expect_success \
163 'validate git rev-list output.' \
164 'test_cmp expected current'
166 test_expect_success 'partial commit that involves removal (1)' '
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 &&
174 test_cmp expected current
178 test_expect_success 'partial commit that involves removal (2)' '
180 git commit -m "Partial: remove file" file &&
181 git diff-tree --name-status HEAD^ HEAD >current &&
182 echo "D file" >expected &&
183 test_cmp expected current
187 test_expect_success 'partial commit that involves removal (3)' '
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 &&
194 test_cmp expected current
198 author="The Real Author <someguy@his.email.org>"
199 test_expect_success 'amend commit to fix author' '
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 &&
210 test_cmp expected current
214 test_expect_success 'amend commit to fix date' '
216 test_tick &&
217 newtick=$GIT_AUTHOR_DATE &&
218 git reset --hard &&
219 git cat-file -p HEAD |
220 sed -e "s/author.*/author $author $newtick/" \
221 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
222 expected &&
223 git commit --amend --date="$newtick" &&
224 git cat-file -p HEAD > current &&
225 test_cmp expected current
229 test_expect_success 'sign off (1)' '
231 echo 1 >positive &&
232 git add positive &&
233 git commit -s -m "thank you" &&
234 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
236 echo thank you
237 echo
238 git var GIT_COMMITTER_IDENT |
239 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
240 ) >expected &&
241 test_cmp expected actual
245 test_expect_success 'sign off (2)' '
247 echo 2 >positive &&
248 git add positive &&
249 existing="Signed-off-by: Watch This <watchthis@example.com>" &&
250 git commit -s -m "thank you
252 $existing" &&
253 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
255 echo thank you
256 echo
257 echo $existing
258 git var GIT_COMMITTER_IDENT |
259 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
260 ) >expected &&
261 test_cmp expected actual
265 test_expect_success 'signoff gap' '
267 echo 3 >positive &&
268 git add positive &&
269 alt="Alt-RFC-822-Header: Value" &&
270 git commit -s -m "welcome
272 $alt" &&
273 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
275 echo welcome
276 echo
277 echo $alt
278 git var GIT_COMMITTER_IDENT |
279 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
280 ) >expected &&
281 test_cmp expected actual
284 test_expect_success 'signoff gap 2' '
286 echo 4 >positive &&
287 git add positive &&
288 alt="fixed: 34" &&
289 git commit -s -m "welcome
291 We have now
292 $alt" &&
293 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
295 echo welcome
296 echo
297 echo We have now
298 echo $alt
299 echo
300 git var GIT_COMMITTER_IDENT |
301 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
302 ) >expected &&
303 test_cmp expected actual
306 test_expect_success 'multiple -m' '
308 >negative &&
309 git add negative &&
310 git commit -m "one" -m "two" -m "three" &&
311 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
313 echo one
314 echo
315 echo two
316 echo
317 echo three
318 ) >expected &&
319 test_cmp expected actual
323 author="The Real Author <someguy@his.email.org>"
324 test_expect_success 'amend commit to fix author' '
326 oldtick=$GIT_AUTHOR_DATE &&
327 test_tick &&
328 git reset --hard &&
329 git cat-file -p HEAD |
330 sed -e "s/author.*/author $author $oldtick/" \
331 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
332 expected &&
333 git commit --amend --author="$author" &&
334 git cat-file -p HEAD > current &&
335 test_cmp expected current
339 test_expect_success 'git commit <file> with dirty index' '
340 echo tacocat > elif &&
341 echo tehlulz > chz &&
342 git add chz &&
343 git commit elif -m "tacocat is a palindrome" &&
344 git show --stat | grep elif &&
345 git diff --cached | grep chz
348 test_expect_success 'same tree (single parent)' '
350 git reset --hard
352 if git commit -m empty
353 then
354 echo oops -- should have complained
355 false
356 else
357 : happy
362 test_expect_success 'same tree (single parent) --allow-empty' '
364 git commit --allow-empty -m "forced empty" &&
365 git cat-file commit HEAD | grep forced
369 test_expect_success 'same tree (merge and amend merge)' '
371 git checkout -b side HEAD^ &&
372 echo zero >zero &&
373 git add zero &&
374 git commit -m "add zero" &&
375 git checkout master &&
377 git merge -s ours side -m "empty ok" &&
378 git diff HEAD^ HEAD >actual &&
379 : >expected &&
380 test_cmp expected actual &&
382 git commit --amend -m "empty really ok" &&
383 git diff HEAD^ HEAD >actual &&
384 : >expected &&
385 test_cmp expected actual
389 test_expect_success 'amend using the message from another commit' '
391 git reset --hard &&
392 test_tick &&
393 git commit --allow-empty -m "old commit" &&
394 old=$(git rev-parse --verify HEAD) &&
395 test_tick &&
396 git commit --allow-empty -m "new commit" &&
397 new=$(git rev-parse --verify HEAD) &&
398 test_tick &&
399 git commit --allow-empty --amend -C "$old" &&
400 git show --pretty="format:%ad %s" "$old" >expected &&
401 git show --pretty="format:%ad %s" HEAD >actual &&
402 test_cmp expected actual
406 test_expect_success 'amend using the message from a commit named with tag' '
408 git reset --hard &&
409 test_tick &&
410 git commit --allow-empty -m "old commit" &&
411 old=$(git rev-parse --verify HEAD) &&
412 git tag -a -m "tag on old" tagged-old HEAD &&
413 test_tick &&
414 git commit --allow-empty -m "new commit" &&
415 new=$(git rev-parse --verify HEAD) &&
416 test_tick &&
417 git commit --allow-empty --amend -C tagged-old &&
418 git show --pretty="format:%ad %s" "$old" >expected &&
419 git show --pretty="format:%ad %s" HEAD >actual &&
420 test_cmp expected actual
424 test_done