Document all help keys in "git add -i" patch mode.
[git/dscho.git] / t / t7501-commit.sh
blobce83af3a02427af8c6a5fbea921a46ed5522b8b3
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, hooks
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_failure \
21 "fail initial amend" \
22 "git-commit --amend"
24 test_expect_success \
25 "initial commit" \
26 "git-commit -m initial"
28 test_expect_failure \
29 "invalid options 1" \
30 "git-commit -m foo -m bar -F file"
32 test_expect_failure \
33 "invalid options 2" \
34 "git-commit -C HEAD -m illegal"
36 test_expect_failure \
37 "using paths with -a" \
38 "echo King of the bongo >file &&
39 git-commit -m foo -a file"
41 test_expect_failure \
42 "using paths with --interactive" \
43 "echo bong-o-bong >file &&
44 echo 7 | git-commit -m foo --interactive file"
46 test_expect_failure \
47 "using invalid commit with -C" \
48 "git-commit -C bogus"
50 test_expect_failure \
51 "testing nothing to commit" \
52 "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_failure \
60 "commit message from non-existing file" \
61 "echo 'more bongo: bongo bongo bongo bongo' >file && \
62 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_failure \
72 "empty commit message" \
73 "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 -i -e "s/a file/an amend commit/g" $1
83 EOF
84 chmod 755 editor
86 test_expect_success \
87 "amend commit" \
88 "VISUAL=./editor git-commit --amend"
90 test_expect_failure \
91 "passing -m and -F" \
92 "echo 'enough with the bongos' >file && \
93 git-commit -F msg -m amending ."
95 test_expect_success \
96 "using message from other commit" \
97 "git-commit -C HEAD^ ."
99 cat >editor <<\EOF
100 #!/bin/sh
101 sed -i -e "s/amend/older/g" $1
103 chmod 755 editor
105 test_expect_success \
106 "editing message from other commit" \
107 "echo 'hula hula' >file && \
108 VISUAL=./editor git-commit -c HEAD^ -a"
110 test_expect_success \
111 "message from stdin" \
112 "echo 'silly new contents' >file && \
113 echo commit message from stdin | git-commit -F - -a"
115 test_expect_success \
116 "overriding author from command line" \
117 "echo 'gak' >file && \
118 git-commit -m 'author' --author 'Rubber Duck <rduck@convoy.org>' -a"
120 test_expect_success \
121 "interactive add" \
122 "echo 7 | git-commit --interactive | grep 'What now'"
124 test_expect_success \
125 "showing committed revisions" \
126 "git-rev-list HEAD >current"
128 # We could just check the head sha1, but checking each commit makes it
129 # easier to isolate bugs.
131 cat >expected <<\EOF
132 72c0dc9855b0c9dadcbfd5a31cab072e0cb774ca
133 9b88fc14ce6b32e3d9ee021531a54f18a5cf38a2
134 3536bbb352c3a1ef9a420f5b4242d48578b92aa7
135 d381ac431806e53f3dd7ac2f1ae0534f36d738b9
136 4fd44095ad6334f3ef72e4c5ec8ddf108174b54a
137 402702b49136e7587daa9280e91e4bb7cb2179f7
140 test_expect_success \
141 'validate git-rev-list output.' \
142 'diff current expected'
144 test_expect_success 'partial commit that involves removal (1)' '
146 git rm --cached file &&
147 mv file elif &&
148 git add elif &&
149 git commit -m "Partial: add elif" elif &&
150 git diff-tree --name-status HEAD^ HEAD >current &&
151 echo "A elif" >expected &&
152 diff expected current
156 test_expect_success 'partial commit that involves removal (2)' '
158 git commit -m "Partial: remove file" file &&
159 git diff-tree --name-status HEAD^ HEAD >current &&
160 echo "D file" >expected &&
161 diff expected current
165 test_expect_success 'partial commit that involves removal (3)' '
167 git rm --cached elif &&
168 echo elif >elif &&
169 git commit -m "Partial: modify elif" elif &&
170 git diff-tree --name-status HEAD^ HEAD >current &&
171 echo "M elif" >expected &&
172 diff expected current
176 author="The Real Author <someguy@his.email.org>"
177 test_expect_success 'amend commit to fix author' '
179 oldtick=$GIT_AUTHOR_DATE &&
180 test_tick &&
181 git reset --hard &&
182 git cat-file -p HEAD |
183 sed -e "s/author.*/author $author $oldtick/" \
184 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
185 expected &&
186 git commit --amend --author="$author" &&
187 git cat-file -p HEAD > current &&
188 diff expected current
192 test_expect_success 'sign off (1)' '
194 echo 1 >positive &&
195 git add positive &&
196 git commit -s -m "thank you" &&
197 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
199 echo thank you
200 echo
201 git var GIT_COMMITTER_IDENT |
202 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
203 ) >expected &&
204 diff -u expected actual
208 test_expect_success 'sign off (2)' '
210 echo 2 >positive &&
211 git add positive &&
212 existing="Signed-off-by: Watch This <watchthis@example.com>" &&
213 git commit -s -m "thank you
215 $existing" &&
216 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
218 echo thank you
219 echo
220 echo $existing
221 git var GIT_COMMITTER_IDENT |
222 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
223 ) >expected &&
224 diff -u expected actual
228 test_expect_success 'multiple -m' '
230 >negative &&
231 git add negative &&
232 git commit -m "one" -m "two" -m "three" &&
233 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
235 echo one
236 echo
237 echo two
238 echo
239 echo three
240 ) >expected &&
241 diff -u expected actual
245 author="The Real Author <someguy@his.email.org>"
246 test_expect_success 'amend commit to fix author' '
248 oldtick=$GIT_AUTHOR_DATE &&
249 test_tick &&
250 git reset --hard &&
251 git cat-file -p HEAD |
252 sed -e "s/author.*/author $author $oldtick/" \
253 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
254 expected &&
255 git commit --amend --author="$author" &&
256 git cat-file -p HEAD > current &&
257 diff expected current
261 test_expect_success 'git commit <file> with dirty index' '
262 echo tacocat > elif &&
263 echo tehlulz > chz &&
264 git add chz &&
265 git commit elif -m "tacocat is a palindrome" &&
266 git show --stat | grep elif &&
267 git diff --cached | grep chz
270 test_done