3 # Copyright (c) 2007 Kristian Høgsberg <krh@redhat.com>
6 # FIXME: Test the various index usages, -i and -o, test reflog,
9 test_description
='git commit'
16 "echo 'bongo bongo' >file &&
18 git status | grep 'Initial commit'"
21 "fail initial amend" \
22 "test_must_fail git commit --amend"
26 "git commit -m initial"
30 "test_must_fail git commit -m foo -m bar -F file"
34 "test_must_fail git commit -C HEAD -m illegal"
37 "using paths with -a" \
38 "echo King of the bongo >file &&
39 test_must_fail git commit -m foo -a file"
42 "using paths with --interactive" \
43 "echo bong-o-bong >file &&
44 ! (echo 7 | git commit -m foo --interactive file)"
47 "using invalid commit with -C" \
48 "test_must_fail git commit -C bogus"
51 "testing nothing to commit" \
52 "test_must_fail git commit -m initial"
56 "echo 'bongo bongo bongo' >file \
57 git commit -m next -a"
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
72 "empty commit message" \
73 "test_must_fail git commit -F msg -a"
76 "commit message from file" \
77 "echo 'this is the commit message, coming from a file' >msg && \
82 sed -e "s/a file/an amend commit/g" < "$1" > "$1-"
89 "VISUAL=./editor git commit --amend"
93 "echo 'enough with the bongos' >file && \
94 test_must_fail git commit -F msg -m amending ."
97 "using message from other commit" \
98 "git commit -C HEAD^ ."
102 sed -e "s/amend/older/g" < "$1" > "$1-"
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 \
125 "echo 7 | git commit --interactive | grep 'What now'"
127 test_expect_success \
128 "showing committed revisions" \
129 "git rev-list HEAD >current"
131 # We could just check the head sha1, but checking each commit makes it
132 # easier to isolate bugs.
135 72c0dc9855b0c9dadcbfd5a31cab072e0cb774ca
136 9b88fc14ce6b32e3d9ee021531a54f18a5cf38a2
137 3536bbb352c3a1ef9a420f5b4242d48578b92aa7
138 d381ac431806e53f3dd7ac2f1ae0534f36d738b9
139 4fd44095ad6334f3ef72e4c5ec8ddf108174b54a
140 402702b49136e7587daa9280e91e4bb7cb2179f7
143 test_expect_success \
144 'validate git rev-list output.' \
145 'test_cmp expected current'
147 test_expect_success
'partial commit that involves removal (1)' '
149 git rm --cached file &&
152 git commit -m "Partial: add elif" elif &&
153 git diff-tree --name-status HEAD^ HEAD >current &&
154 echo "A elif" >expected &&
155 test_cmp expected current
159 test_expect_success
'partial commit that involves removal (2)' '
161 git commit -m "Partial: remove file" file &&
162 git diff-tree --name-status HEAD^ HEAD >current &&
163 echo "D file" >expected &&
164 test_cmp expected current
168 test_expect_success
'partial commit that involves removal (3)' '
170 git rm --cached elif &&
172 git commit -m "Partial: modify elif" elif &&
173 git diff-tree --name-status HEAD^ HEAD >current &&
174 echo "M elif" >expected &&
175 test_cmp expected current
179 author
="The Real Author <someguy@his.email.org>"
180 test_expect_success
'amend commit to fix author' '
182 oldtick=$GIT_AUTHOR_DATE &&
185 git cat-file -p HEAD |
186 sed -e "s/author.*/author $author $oldtick/" \
187 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
189 git commit --amend --author="$author" &&
190 git cat-file -p HEAD > current &&
191 test_cmp expected current
195 test_expect_success
'sign off (1)' '
199 git commit -s -m "thank you" &&
200 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
204 git var GIT_COMMITTER_IDENT |
205 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
207 test_cmp expected actual
211 test_expect_success
'sign off (2)' '
215 existing="Signed-off-by: Watch This <watchthis@example.com>" &&
216 git commit -s -m "thank you
219 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
224 git var GIT_COMMITTER_IDENT |
225 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
227 test_cmp expected actual
231 test_expect_success
'multiple -m' '
235 git commit -m "one" -m "two" -m "three" &&
236 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
244 test_cmp expected actual
248 author
="The Real Author <someguy@his.email.org>"
249 test_expect_success
'amend commit to fix author' '
251 oldtick=$GIT_AUTHOR_DATE &&
254 git cat-file -p HEAD |
255 sed -e "s/author.*/author $author $oldtick/" \
256 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
258 git commit --amend --author="$author" &&
259 git cat-file -p HEAD > current &&
260 test_cmp expected current
264 test_expect_success
'git commit <file> with dirty index' '
265 echo tacocat > elif &&
266 echo tehlulz > chz &&
268 git commit elif -m "tacocat is a palindrome" &&
269 git show --stat | grep elif &&
270 git diff --cached | grep chz
273 test_expect_success
'same tree (single parent)' '
277 if git commit -m empty
279 echo oops -- should have complained
287 test_expect_success
'same tree (single parent) --allow-empty' '
289 git commit --allow-empty -m "forced empty" &&
290 git cat-file commit HEAD | grep forced
294 test_expect_success
'same tree (merge and amend merge)' '
296 git checkout -b side HEAD^ &&
299 git commit -m "add zero" &&
300 git checkout master &&
302 git merge -s ours side -m "empty ok" &&
303 git diff HEAD^ HEAD >actual &&
305 test_cmp expected actual &&
307 git commit --amend -m "empty really ok" &&
308 git diff HEAD^ HEAD >actual &&
310 test_cmp expected actual
314 test_expect_success
'amend using the message from another commit' '
318 git commit --allow-empty -m "old commit" &&
319 old=$(git rev-parse --verify HEAD) &&
321 git commit --allow-empty -m "new commit" &&
322 new=$(git rev-parse --verify HEAD) &&
324 git commit --allow-empty --amend -C "$old" &&
325 git show --pretty="format:%ad %s" "$old" >expected &&
326 git show --pretty="format:%ad %s" HEAD >actual &&
327 test_cmp expected actual
331 test_expect_success
'amend using the message from a commit named with tag' '
335 git commit --allow-empty -m "old commit" &&
336 old=$(git rev-parse --verify HEAD) &&
337 git tag -a -m "tag on old" tagged-old HEAD &&
339 git commit --allow-empty -m "new commit" &&
340 new=$(git rev-parse --verify HEAD) &&
342 git commit --allow-empty --amend -C tagged-old &&
343 git show --pretty="format:%ad %s" "$old" >expected &&
344 git show --pretty="format:%ad %s" HEAD >actual &&
345 test_cmp expected actual