Merge commit 'v1.6.3.2' into devel
[4msysgit-hv.git] / t / t7501-commit.sh
blobb7beb8b9ab8cec6a77ed1a2da3f04b210041617f
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 "VISUAL=./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 VISUAL=./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 echo "SKIP because msysgit does not support Git.pm" ||
123 test_expect_success PERL \
124 "interactive add" \
125 "echo 7 | git commit --interactive | grep 'What now'"
127 test_expect_success \
128 "showing committed revisions" \
129 "git rev-list HEAD >current"
131 cat >editor <<\EOF
132 #!/bin/sh
133 sed -e "s/good/bad/g" < "$1" > "$1-"
134 mv "$1-" "$1"
136 chmod 755 editor
138 cat >msg <<EOF
139 A good commit message.
142 test_expect_success \
143 'editor not invoked if -F is given' '
144 echo "moo" >file &&
145 VISUAL=./editor git commit -a -F msg &&
146 git show -s --pretty=format:"%s" | grep -q good &&
147 echo "quack" >file &&
148 echo "Another good message." | VISUAL=./editor git commit -a -F - &&
149 git show -s --pretty=format:"%s" | grep -q good
151 # We could just check the head sha1, but checking each commit makes it
152 # easier to isolate bugs.
154 cat >expected <<\EOF
155 72c0dc9855b0c9dadcbfd5a31cab072e0cb774ca
156 9b88fc14ce6b32e3d9ee021531a54f18a5cf38a2
157 3536bbb352c3a1ef9a420f5b4242d48578b92aa7
158 d381ac431806e53f3dd7ac2f1ae0534f36d738b9
159 4fd44095ad6334f3ef72e4c5ec8ddf108174b54a
160 402702b49136e7587daa9280e91e4bb7cb2179f7
163 test_expect_success \
164 'validate git rev-list output.' \
165 'test_cmp expected current'
167 test_expect_success 'partial commit that involves removal (1)' '
169 git rm --cached file &&
170 mv file elif &&
171 git add elif &&
172 git commit -m "Partial: add elif" elif &&
173 git diff-tree --name-status HEAD^ HEAD >current &&
174 echo "A elif" >expected &&
175 test_cmp expected current
179 test_expect_success 'partial commit that involves removal (2)' '
181 git commit -m "Partial: remove file" file &&
182 git diff-tree --name-status HEAD^ HEAD >current &&
183 echo "D file" >expected &&
184 test_cmp expected current
188 test_expect_success 'partial commit that involves removal (3)' '
190 git rm --cached elif &&
191 echo elif >elif &&
192 git commit -m "Partial: modify elif" elif &&
193 git diff-tree --name-status HEAD^ HEAD >current &&
194 echo "M elif" >expected &&
195 test_cmp expected current
199 author="The Real Author <someguy@his.email.org>"
200 test_expect_success 'amend commit to fix author' '
202 oldtick=$GIT_AUTHOR_DATE &&
203 test_tick &&
204 git reset --hard &&
205 git cat-file -p HEAD |
206 sed -e "s/author.*/author $author $oldtick/" \
207 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
208 expected &&
209 git commit --amend --author="$author" &&
210 git cat-file -p HEAD > current &&
211 test_cmp expected current
215 test_expect_success 'sign off (1)' '
217 echo 1 >positive &&
218 git add positive &&
219 git commit -s -m "thank you" &&
220 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
222 echo thank you
223 echo
224 git var GIT_COMMITTER_IDENT |
225 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
226 ) >expected &&
227 test_cmp expected actual
231 test_expect_success 'sign off (2)' '
233 echo 2 >positive &&
234 git add positive &&
235 existing="Signed-off-by: Watch This <watchthis@example.com>" &&
236 git commit -s -m "thank you
238 $existing" &&
239 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
241 echo thank you
242 echo
243 echo $existing
244 git var GIT_COMMITTER_IDENT |
245 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
246 ) >expected &&
247 test_cmp expected actual
251 test_expect_success 'multiple -m' '
253 >negative &&
254 git add negative &&
255 git commit -m "one" -m "two" -m "three" &&
256 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
258 echo one
259 echo
260 echo two
261 echo
262 echo three
263 ) >expected &&
264 test_cmp expected actual
268 author="The Real Author <someguy@his.email.org>"
269 test_expect_success 'amend commit to fix author' '
271 oldtick=$GIT_AUTHOR_DATE &&
272 test_tick &&
273 git reset --hard &&
274 git cat-file -p HEAD |
275 sed -e "s/author.*/author $author $oldtick/" \
276 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
277 expected &&
278 git commit --amend --author="$author" &&
279 git cat-file -p HEAD > current &&
280 test_cmp expected current
284 test_expect_success 'git commit <file> with dirty index' '
285 echo tacocat > elif &&
286 echo tehlulz > chz &&
287 git add chz &&
288 git commit elif -m "tacocat is a palindrome" &&
289 git show --stat | grep elif &&
290 git diff --cached | grep chz
293 test_expect_success 'same tree (single parent)' '
295 git reset --hard
297 if git commit -m empty
298 then
299 echo oops -- should have complained
300 false
301 else
302 : happy
307 test_expect_success 'same tree (single parent) --allow-empty' '
309 git commit --allow-empty -m "forced empty" &&
310 git cat-file commit HEAD | grep forced
314 test_expect_success 'same tree (merge and amend merge)' '
316 git checkout -b side HEAD^ &&
317 echo zero >zero &&
318 git add zero &&
319 git commit -m "add zero" &&
320 git checkout master &&
322 git merge -s ours side -m "empty ok" &&
323 git diff HEAD^ HEAD >actual &&
324 : >expected &&
325 test_cmp expected actual &&
327 git commit --amend -m "empty really ok" &&
328 git diff HEAD^ HEAD >actual &&
329 : >expected &&
330 test_cmp expected actual
334 test_expect_success 'amend using the message from another commit' '
336 git reset --hard &&
337 test_tick &&
338 git commit --allow-empty -m "old commit" &&
339 old=$(git rev-parse --verify HEAD) &&
340 test_tick &&
341 git commit --allow-empty -m "new commit" &&
342 new=$(git rev-parse --verify HEAD) &&
343 test_tick &&
344 git commit --allow-empty --amend -C "$old" &&
345 git show --pretty="format:%ad %s" "$old" >expected &&
346 git show --pretty="format:%ad %s" HEAD >actual &&
347 test_cmp expected actual
351 test_expect_success 'amend using the message from a commit named with tag' '
353 git reset --hard &&
354 test_tick &&
355 git commit --allow-empty -m "old commit" &&
356 old=$(git rev-parse --verify HEAD) &&
357 git tag -a -m "tag on old" tagged-old HEAD &&
358 test_tick &&
359 git commit --allow-empty -m "new commit" &&
360 new=$(git rev-parse --verify HEAD) &&
361 test_tick &&
362 git commit --allow-empty --amend -C tagged-old &&
363 git show --pretty="format:%ad %s" "$old" >expected &&
364 git show --pretty="format:%ad %s" HEAD >actual &&
365 test_cmp expected actual
369 test_done