test: remove a porcelain test that hard-codes commit names
[git/jnareb-git.git] / t / t7501-commit.sh
blob9c507b082157b34aa3ee8eee18957685e9aaac39
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 'can use paths with --interactive' '
46 echo bong-o-bong >file &&
47 # 2: update, 1:st path, that is all, 7: quit
48 ( echo 2; echo 1; echo; echo 7 ) |
49 git commit -m foo --interactive file &&
50 git reset --hard HEAD^
53 test_expect_success \
54 "using invalid commit with -C" \
55 "test_must_fail git commit -C bogus"
57 test_expect_success \
58 "testing nothing to commit" \
59 "test_must_fail git commit -m initial"
61 test_expect_success \
62 "next commit" \
63 "echo 'bongo bongo bongo' >file && \
64 git commit -m next -a"
66 test_expect_success \
67 "commit message from non-existing file" \
68 "echo 'more bongo: bongo bongo bongo bongo' >file && \
69 test_must_fail git commit -F gah -a"
71 # Empty except stray tabs and spaces on a few lines.
72 sed -e 's/@$//' >msg <<EOF
76 Signed-off-by: hula
77 EOF
78 test_expect_success \
79 "empty commit message" \
80 "test_must_fail git commit -F msg -a"
82 test_expect_success \
83 "commit message from file" \
84 "echo 'this is the commit message, coming from a file' >msg && \
85 git commit -F msg -a"
87 cat >editor <<\EOF
88 #!/bin/sh
89 sed -e "s/a file/an amend commit/g" < "$1" > "$1-"
90 mv "$1-" "$1"
91 EOF
92 chmod 755 editor
94 test_expect_success \
95 "amend commit" \
96 "EDITOR=./editor git commit --amend"
98 test_expect_success \
99 "passing -m and -F" \
100 "echo 'enough with the bongos' >file && \
101 test_must_fail git commit -F msg -m amending ."
103 test_expect_success \
104 "using message from other commit" \
105 "git commit -C HEAD^ ."
107 cat >editor <<\EOF
108 #!/bin/sh
109 sed -e "s/amend/older/g" < "$1" > "$1-"
110 mv "$1-" "$1"
112 chmod 755 editor
114 test_expect_success \
115 "editing message from other commit" \
116 "echo 'hula hula' >file && \
117 EDITOR=./editor git commit -c HEAD^ -a"
119 test_expect_success \
120 "message from stdin" \
121 "echo 'silly new contents' >file && \
122 echo commit message from stdin | git commit -F - -a"
124 test_expect_success \
125 "overriding author from command line" \
126 "echo 'gak' >file && \
127 git commit -m 'author' --author 'Rubber Duck <rduck@convoy.org>' -a >output 2>&1"
129 test_expect_success \
130 "commit --author output mentions author" \
131 "grep Rubber.Duck output"
133 test_expect_success PERL \
134 "interactive add" \
135 "echo 7 | git commit --interactive | grep 'What now'"
137 test_expect_success PERL \
138 "commit --interactive doesn't change index if editor aborts" \
139 "echo zoo >file &&
140 test_must_fail git diff --exit-code >diff1 &&
141 (echo u ; echo '*' ; echo q) |
142 (EDITOR=: && export EDITOR &&
143 test_must_fail git commit --interactive) &&
144 git diff >diff2 &&
145 test_cmp diff1 diff2"
147 cat >editor <<\EOF
148 #!/bin/sh
149 sed -e "s/good/bad/g" < "$1" > "$1-"
150 mv "$1-" "$1"
152 chmod 755 editor
154 cat >msg <<EOF
155 A good commit message.
158 test_expect_success \
159 'editor not invoked if -F is given' '
160 echo "moo" >file &&
161 EDITOR=./editor git commit -a -F msg &&
162 git show -s --pretty=format:"%s" | grep -q good &&
163 echo "quack" >file &&
164 echo "Another good message." | EDITOR=./editor git commit -a -F - &&
165 git show -s --pretty=format:"%s" | grep -q good
168 test_expect_success 'partial commit that involves removal (1)' '
170 git rm --cached file &&
171 mv file elif &&
172 git add elif &&
173 git commit -m "Partial: add elif" elif &&
174 git diff-tree --name-status HEAD^ HEAD >current &&
175 echo "A elif" >expected &&
176 test_cmp expected current
180 test_expect_success 'partial commit that involves removal (2)' '
182 git commit -m "Partial: remove file" file &&
183 git diff-tree --name-status HEAD^ HEAD >current &&
184 echo "D file" >expected &&
185 test_cmp expected current
189 test_expect_success 'partial commit that involves removal (3)' '
191 git rm --cached elif &&
192 echo elif >elif &&
193 git commit -m "Partial: modify elif" elif &&
194 git diff-tree --name-status HEAD^ HEAD >current &&
195 echo "M elif" >expected &&
196 test_cmp expected current
200 author="The Real Author <someguy@his.email.org>"
201 test_expect_success 'amend commit to fix author' '
203 oldtick=$GIT_AUTHOR_DATE &&
204 test_tick &&
205 git reset --hard &&
206 git cat-file -p HEAD |
207 sed -e "s/author.*/author $author $oldtick/" \
208 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
209 expected &&
210 git commit --amend --author="$author" &&
211 git cat-file -p HEAD > current &&
212 test_cmp expected current
216 test_expect_success 'amend commit to fix date' '
218 test_tick &&
219 newtick=$GIT_AUTHOR_DATE &&
220 git reset --hard &&
221 git cat-file -p HEAD |
222 sed -e "s/author.*/author $author $newtick/" \
223 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
224 expected &&
225 git commit --amend --date="$newtick" &&
226 git cat-file -p HEAD > current &&
227 test_cmp expected current
231 test_expect_success 'commit complains about bogus date' '
232 test_must_fail git commit --amend --date=10.11.2010
235 test_expect_success 'sign off (1)' '
237 echo 1 >positive &&
238 git add positive &&
239 git commit -s -m "thank you" &&
240 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
242 echo thank you
243 echo
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 'sign off (2)' '
253 echo 2 >positive &&
254 git add positive &&
255 existing="Signed-off-by: Watch This <watchthis@example.com>" &&
256 git commit -s -m "thank you
258 $existing" &&
259 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
261 echo thank you
262 echo
263 echo $existing
264 git var GIT_COMMITTER_IDENT |
265 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
266 ) >expected &&
267 test_cmp expected actual
271 test_expect_success 'signoff gap' '
273 echo 3 >positive &&
274 git add positive &&
275 alt="Alt-RFC-822-Header: Value" &&
276 git commit -s -m "welcome
278 $alt" &&
279 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
281 echo welcome
282 echo
283 echo $alt
284 git var GIT_COMMITTER_IDENT |
285 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
286 ) >expected &&
287 test_cmp expected actual
290 test_expect_success 'signoff gap 2' '
292 echo 4 >positive &&
293 git add positive &&
294 alt="fixed: 34" &&
295 git commit -s -m "welcome
297 We have now
298 $alt" &&
299 git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
301 echo welcome
302 echo
303 echo We have now
304 echo $alt
305 echo
306 git var GIT_COMMITTER_IDENT |
307 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
308 ) >expected &&
309 test_cmp expected actual
312 test_expect_success 'multiple -m' '
314 >negative &&
315 git add negative &&
316 git commit -m "one" -m "two" -m "three" &&
317 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
319 echo one
320 echo
321 echo two
322 echo
323 echo three
324 ) >expected &&
325 test_cmp expected actual
329 author="The Real Author <someguy@his.email.org>"
330 test_expect_success 'amend commit to fix author' '
332 oldtick=$GIT_AUTHOR_DATE &&
333 test_tick &&
334 git reset --hard &&
335 git cat-file -p HEAD |
336 sed -e "s/author.*/author $author $oldtick/" \
337 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
338 expected &&
339 git commit --amend --author="$author" &&
340 git cat-file -p HEAD > current &&
341 test_cmp expected current
345 test_expect_success 'git commit <file> with dirty index' '
346 echo tacocat > elif &&
347 echo tehlulz > chz &&
348 git add chz &&
349 git commit elif -m "tacocat is a palindrome" &&
350 git show --stat | grep elif &&
351 git diff --cached | grep chz
354 test_expect_success 'same tree (single parent)' '
356 git reset --hard
358 if git commit -m empty
359 then
360 echo oops -- should have complained
361 false
362 else
363 : happy
368 test_expect_success 'same tree (single parent) --allow-empty' '
370 git commit --allow-empty -m "forced empty" &&
371 git cat-file commit HEAD | grep forced
375 test_expect_success 'same tree (merge and amend merge)' '
377 git checkout -b side HEAD^ &&
378 echo zero >zero &&
379 git add zero &&
380 git commit -m "add zero" &&
381 git checkout master &&
383 git merge -s ours side -m "empty ok" &&
384 git diff HEAD^ HEAD >actual &&
385 : >expected &&
386 test_cmp expected actual &&
388 git commit --amend -m "empty really ok" &&
389 git diff HEAD^ HEAD >actual &&
390 : >expected &&
391 test_cmp expected actual
395 test_expect_success 'amend using the message from another commit' '
397 git reset --hard &&
398 test_tick &&
399 git commit --allow-empty -m "old commit" &&
400 old=$(git rev-parse --verify HEAD) &&
401 test_tick &&
402 git commit --allow-empty -m "new commit" &&
403 new=$(git rev-parse --verify HEAD) &&
404 test_tick &&
405 git commit --allow-empty --amend -C "$old" &&
406 git show --pretty="format:%ad %s" "$old" >expected &&
407 git show --pretty="format:%ad %s" HEAD >actual &&
408 test_cmp expected actual
412 test_expect_success 'amend using the message from a commit named with tag' '
414 git reset --hard &&
415 test_tick &&
416 git commit --allow-empty -m "old commit" &&
417 old=$(git rev-parse --verify HEAD) &&
418 git tag -a -m "tag on old" tagged-old HEAD &&
419 test_tick &&
420 git commit --allow-empty -m "new commit" &&
421 new=$(git rev-parse --verify HEAD) &&
422 test_tick &&
423 git commit --allow-empty --amend -C tagged-old &&
424 git show --pretty="format:%ad %s" "$old" >expected &&
425 git show --pretty="format:%ad %s" HEAD >actual &&
426 test_cmp expected actual
430 test_expect_success 'amend can copy notes' '
432 git config notes.rewrite.amend true &&
433 git config notes.rewriteRef "refs/notes/*" &&
434 test_commit foo &&
435 git notes add -m"a note" &&
436 test_tick &&
437 git commit --amend -m"new foo" &&
438 test "$(git notes show)" = "a note"
442 test_done