Merge branch 'bs/maint-commit-options'
[git/git.git] / t / t7501-commit.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Kristian Høgsberg <krh@redhat.com>
4 #
5
6 # FIXME: Test the various index usages, -i and -o, test reflog,
7 # signoff, hooks
8
9 test_description='git-commit'
10 . ./test-lib.sh
11
12 test_tick
13
14 test_expect_success \
15 "initial status" \
16 "echo 'bongo bongo' >file &&
17 git-add file && \
18 git-status | grep 'Initial commit'"
19
20 test_expect_failure \
21 "fail initial amend" \
22 "git-commit --amend"
23
24 test_expect_success \
25 "initial commit" \
26 "git-commit -m initial"
27
28 test_expect_failure \
29 "invalid options 1" \
30 "git-commit -m foo -m bar -F file"
31
32 test_expect_failure \
33 "invalid options 2" \
34 "git-commit -C HEAD -m illegal"
35
36 test_expect_failure \
37 "using paths with -a" \
38 "echo King of the bongo >file &&
39 git-commit -m foo -a file"
40
41 test_expect_failure \
42 "using paths with --interactive" \
43 "echo bong-o-bong >file &&
44 echo 7 | git-commit -m foo --interactive file"
45
46 test_expect_failure \
47 "using invalid commit with -C" \
48 "git-commit -C bogus"
49
50 test_expect_failure \
51 "testing nothing to commit" \
52 "git-commit -m initial"
53
54 test_expect_success \
55 "next commit" \
56 "echo 'bongo bongo bongo' >file \
57 git-commit -m next -a"
58
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"
63
64 # Empty except stray tabs and spaces on a few lines.
65 sed -e 's/@$//' >msg <<EOF
66 @
67
68 @
69 Signed-off-by: hula
70 EOF
71 test_expect_failure \
72 "empty commit message" \
73 "git-commit -F msg -a"
74
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"
79
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
85
86 test_expect_success \
87 "amend commit" \
88 "VISUAL=./editor git-commit --amend"
89
90 test_expect_failure \
91 "passing -m and -F" \
92 "echo 'enough with the bongos' >file && \
93 git-commit -F msg -m amending ."
94
95 test_expect_success \
96 "using message from other commit" \
97 "git-commit -C HEAD^ ."
98
99 cat >editor <<\EOF
100 #!/bin/sh
101 sed -i -e "s/amend/older/g" $1
102 EOF
103 chmod 755 editor
104
105 test_expect_success \
106 "editing message from other commit" \
107 "echo 'hula hula' >file && \
108 VISUAL=./editor git-commit -c HEAD^ -a"
109
110 test_expect_success \
111 "message from stdin" \
112 "echo 'silly new contents' >file && \
113 echo commit message from stdin | git-commit -F - -a"
114
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"
119
120 test_expect_success \
121 "interactive add" \
122 "echo 7 | git-commit --interactive | grep 'What now'"
123
124 test_expect_success \
125 "showing committed revisions" \
126 "git-rev-list HEAD >current"
127
128 # We could just check the head sha1, but checking each commit makes it
129 # easier to isolate bugs.
130
131 cat >expected <<\EOF
132 72c0dc9855b0c9dadcbfd5a31cab072e0cb774ca
133 9b88fc14ce6b32e3d9ee021531a54f18a5cf38a2
134 3536bbb352c3a1ef9a420f5b4242d48578b92aa7
135 d381ac431806e53f3dd7ac2f1ae0534f36d738b9
136 4fd44095ad6334f3ef72e4c5ec8ddf108174b54a
137 402702b49136e7587daa9280e91e4bb7cb2179f7
138 EOF
139
140 test_expect_success \
141 'validate git-rev-list output.' \
142 'diff current expected'
143
144 test_expect_success 'partial commit that involves removal (1)' '
145
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
153
154 '
155
156 test_expect_success 'partial commit that involves removal (2)' '
157
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
162
163 '
164
165 test_expect_success 'partial commit that involves removal (3)' '
166
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
173
174 '
175
176 author="The Real Author <someguy@his.email.org>"
177 test_expect_success 'amend commit to fix author' '
178
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
189
190 '
191
192 test_expect_success 'sign off (1)' '
193
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 &&
198 (
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
205
206 '
207
208 test_expect_success 'sign off (2)' '
209
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
214
215 $existing" &&
216 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
217 (
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
225
226 '
227
228 test_expect_success 'multiple -m' '
229
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 &&
234 (
235 echo one
236 echo
237 echo two
238 echo
239 echo three
240 ) >expected &&
241 diff -u expected actual
242
243 '
244
245 test_done