]>
Commit | Line | Data |
---|---|---|
12ace0b2 KH |
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, | |
264474f2 | 7 | # signoff |
12ace0b2 | 8 | |
47a528ad | 9 | test_description='git commit' |
12ace0b2 KH |
10 | . ./test-lib.sh |
11 | ||
12 | test_tick | |
13 | ||
14 | test_expect_success \ | |
15 | "initial status" \ | |
16 | "echo 'bongo bongo' >file && | |
47a528ad NS |
17 | git add file && \ |
18 | git status | grep 'Initial commit'" | |
12ace0b2 | 19 | |
41ac414e | 20 | test_expect_success \ |
12ace0b2 | 21 | "fail initial amend" \ |
47a528ad | 22 | "test_must_fail git commit --amend" |
12ace0b2 KH |
23 | |
24 | test_expect_success \ | |
25 | "initial commit" \ | |
47a528ad | 26 | "git commit -m initial" |
12ace0b2 | 27 | |
41ac414e | 28 | test_expect_success \ |
12ace0b2 | 29 | "invalid options 1" \ |
47a528ad | 30 | "test_must_fail git commit -m foo -m bar -F file" |
12ace0b2 | 31 | |
41ac414e | 32 | test_expect_success \ |
12ace0b2 | 33 | "invalid options 2" \ |
47a528ad | 34 | "test_must_fail git commit -C HEAD -m illegal" |
12ace0b2 | 35 | |
41ac414e | 36 | test_expect_success \ |
9d87442f BS |
37 | "using paths with -a" \ |
38 | "echo King of the bongo >file && | |
47a528ad | 39 | test_must_fail git commit -m foo -a file" |
9d87442f | 40 | |
1b19ccd2 | 41 | test_expect_success PERL \ |
9d87442f BS |
42 | "using paths with --interactive" \ |
43 | "echo bong-o-bong >file && | |
47a528ad | 44 | ! (echo 7 | git commit -m foo --interactive file)" |
9d87442f | 45 | |
41ac414e | 46 | test_expect_success \ |
12ace0b2 | 47 | "using invalid commit with -C" \ |
47a528ad | 48 | "test_must_fail git commit -C bogus" |
12ace0b2 | 49 | |
41ac414e | 50 | test_expect_success \ |
12ace0b2 | 51 | "testing nothing to commit" \ |
47a528ad | 52 | "test_must_fail git commit -m initial" |
12ace0b2 KH |
53 | |
54 | test_expect_success \ | |
55 | "next commit" \ | |
56 | "echo 'bongo bongo bongo' >file \ | |
47a528ad | 57 | git commit -m next -a" |
12ace0b2 | 58 | |
41ac414e | 59 | test_expect_success \ |
12ace0b2 KH |
60 | "commit message from non-existing file" \ |
61 | "echo 'more bongo: bongo bongo bongo bongo' >file && \ | |
47a528ad | 62 | test_must_fail git commit -F gah -a" |
12ace0b2 KH |
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 | |
41ac414e | 71 | test_expect_success \ |
12ace0b2 | 72 | "empty commit message" \ |
47a528ad | 73 | "test_must_fail git commit -F msg -a" |
12ace0b2 KH |
74 | |
75 | test_expect_success \ | |
76 | "commit message from file" \ | |
77 | "echo 'this is the commit message, coming from a file' >msg && \ | |
47a528ad | 78 | git commit -F msg -a" |
12ace0b2 KH |
79 | |
80 | cat >editor <<\EOF | |
81 | #!/bin/sh | |
f69e836f BD |
82 | sed -e "s/a file/an amend commit/g" < "$1" > "$1-" |
83 | mv "$1-" "$1" | |
12ace0b2 KH |
84 | EOF |
85 | chmod 755 editor | |
86 | ||
87 | test_expect_success \ | |
88 | "amend commit" \ | |
d33738d7 | 89 | "EDITOR=./editor git commit --amend" |
12ace0b2 | 90 | |
41ac414e | 91 | test_expect_success \ |
6d4bbebd | 92 | "passing -m and -F" \ |
12ace0b2 | 93 | "echo 'enough with the bongos' >file && \ |
47a528ad | 94 | test_must_fail git commit -F msg -m amending ." |
12ace0b2 KH |
95 | |
96 | test_expect_success \ | |
97 | "using message from other commit" \ | |
47a528ad | 98 | "git commit -C HEAD^ ." |
12ace0b2 KH |
99 | |
100 | cat >editor <<\EOF | |
101 | #!/bin/sh | |
f69e836f BD |
102 | sed -e "s/amend/older/g" < "$1" > "$1-" |
103 | mv "$1-" "$1" | |
12ace0b2 KH |
104 | EOF |
105 | chmod 755 editor | |
106 | ||
107 | test_expect_success \ | |
108 | "editing message from other commit" \ | |
109 | "echo 'hula hula' >file && \ | |
d33738d7 | 110 | EDITOR=./editor git commit -c HEAD^ -a" |
12ace0b2 KH |
111 | |
112 | test_expect_success \ | |
113 | "message from stdin" \ | |
114 | "echo 'silly new contents' >file && \ | |
47a528ad | 115 | echo commit message from stdin | git commit -F - -a" |
12ace0b2 KH |
116 | |
117 | test_expect_success \ | |
118 | "overriding author from command line" \ | |
119 | "echo 'gak' >file && \ | |
49ff9a7a JK |
120 | git commit -m 'author' --author 'Rubber Duck <rduck@convoy.org>' -a >output 2>&1" |
121 | ||
122 | test_expect_success \ | |
123 | "commit --author output mentions author" \ | |
124 | "grep Rubber.Duck output" | |
12ace0b2 | 125 | |
1b19ccd2 | 126 | test_expect_success PERL \ |
12ace0b2 | 127 | "interactive add" \ |
47a528ad | 128 | "echo 7 | git commit --interactive | grep 'What now'" |
12ace0b2 KH |
129 | |
130 | test_expect_success \ | |
131 | "showing committed revisions" \ | |
47a528ad | 132 | "git rev-list HEAD >current" |
12ace0b2 | 133 | |
7eb5bbdb AS |
134 | cat >editor <<\EOF |
135 | #!/bin/sh | |
136 | sed -e "s/good/bad/g" < "$1" > "$1-" | |
137 | mv "$1-" "$1" | |
138 | EOF | |
139 | chmod 755 editor | |
140 | ||
141 | cat >msg <<EOF | |
142 | A good commit message. | |
143 | EOF | |
144 | ||
145 | test_expect_success \ | |
146 | 'editor not invoked if -F is given' ' | |
147 | echo "moo" >file && | |
d33738d7 | 148 | EDITOR=./editor git commit -a -F msg && |
7eb5bbdb AS |
149 | git show -s --pretty=format:"%s" | grep -q good && |
150 | echo "quack" >file && | |
d33738d7 | 151 | echo "Another good message." | EDITOR=./editor git commit -a -F - && |
7eb5bbdb AS |
152 | git show -s --pretty=format:"%s" | grep -q good |
153 | ' | |
12ace0b2 KH |
154 | # We could just check the head sha1, but checking each commit makes it |
155 | # easier to isolate bugs. | |
156 | ||
157 | cat >expected <<\EOF | |
158 | 72c0dc9855b0c9dadcbfd5a31cab072e0cb774ca | |
159 | 9b88fc14ce6b32e3d9ee021531a54f18a5cf38a2 | |
160 | 3536bbb352c3a1ef9a420f5b4242d48578b92aa7 | |
161 | d381ac431806e53f3dd7ac2f1ae0534f36d738b9 | |
162 | 4fd44095ad6334f3ef72e4c5ec8ddf108174b54a | |
163 | 402702b49136e7587daa9280e91e4bb7cb2179f7 | |
164 | EOF | |
165 | ||
166 | test_expect_success \ | |
47a528ad | 167 | 'validate git rev-list output.' \ |
1e368681 | 168 | 'test_cmp expected current' |
12ace0b2 | 169 | |
db33af0a | 170 | test_expect_success 'partial commit that involves removal (1)' ' |
80bffaf7 JH |
171 | |
172 | git rm --cached file && | |
173 | mv file elif && | |
174 | git add elif && | |
175 | git commit -m "Partial: add elif" elif && | |
176 | git diff-tree --name-status HEAD^ HEAD >current && | |
177 | echo "A elif" >expected && | |
1e368681 | 178 | test_cmp expected current |
80bffaf7 JH |
179 | |
180 | ' | |
181 | ||
db33af0a | 182 | test_expect_success 'partial commit that involves removal (2)' ' |
80bffaf7 JH |
183 | |
184 | git commit -m "Partial: remove file" file && | |
185 | git diff-tree --name-status HEAD^ HEAD >current && | |
186 | echo "D file" >expected && | |
1e368681 | 187 | test_cmp expected current |
80bffaf7 JH |
188 | |
189 | ' | |
190 | ||
db33af0a JH |
191 | test_expect_success 'partial commit that involves removal (3)' ' |
192 | ||
193 | git rm --cached elif && | |
194 | echo elif >elif && | |
195 | git commit -m "Partial: modify elif" elif && | |
196 | git diff-tree --name-status HEAD^ HEAD >current && | |
197 | echo "M elif" >expected && | |
1e368681 | 198 | test_cmp expected current |
db33af0a JH |
199 | |
200 | ' | |
201 | ||
5aa5cd46 JH |
202 | author="The Real Author <someguy@his.email.org>" |
203 | test_expect_success 'amend commit to fix author' ' | |
204 | ||
205 | oldtick=$GIT_AUTHOR_DATE && | |
206 | test_tick && | |
207 | git reset --hard && | |
208 | git cat-file -p HEAD | | |
209 | sed -e "s/author.*/author $author $oldtick/" \ | |
210 | -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ | |
211 | expected && | |
212 | git commit --amend --author="$author" && | |
213 | git cat-file -p HEAD > current && | |
1e368681 | 214 | test_cmp expected current |
5aa5cd46 JH |
215 | |
216 | ' | |
217 | ||
02b47cd7 MV |
218 | test_expect_success 'amend commit to fix date' ' |
219 | ||
220 | test_tick && | |
221 | newtick=$GIT_AUTHOR_DATE && | |
222 | git reset --hard && | |
223 | git cat-file -p HEAD | | |
224 | sed -e "s/author.*/author $author $newtick/" \ | |
225 | -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ | |
226 | expected && | |
227 | git commit --amend --date="$newtick" && | |
228 | git cat-file -p HEAD > current && | |
229 | test_cmp expected current | |
230 | ||
231 | ' | |
232 | ||
4579bb41 JK |
233 | test_expect_success 'commit complains about bogus date' ' |
234 | test_must_fail git commit --amend --date=10.11.2010 | |
235 | ' | |
236 | ||
5aa5cd46 JH |
237 | test_expect_success 'sign off (1)' ' |
238 | ||
239 | echo 1 >positive && | |
240 | git add positive && | |
241 | git commit -s -m "thank you" && | |
242 | git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && | |
243 | ( | |
244 | echo thank you | |
245 | echo | |
246 | git var GIT_COMMITTER_IDENT | | |
247 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" | |
248 | ) >expected && | |
82ebb0b6 | 249 | test_cmp expected actual |
5aa5cd46 JH |
250 | |
251 | ' | |
252 | ||
253 | test_expect_success 'sign off (2)' ' | |
254 | ||
255 | echo 2 >positive && | |
256 | git add positive && | |
257 | existing="Signed-off-by: Watch This <watchthis@example.com>" && | |
258 | git commit -s -m "thank you | |
259 | ||
260 | $existing" && | |
261 | git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && | |
262 | ( | |
263 | echo thank you | |
264 | echo | |
265 | echo $existing | |
266 | git var GIT_COMMITTER_IDENT | | |
267 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" | |
268 | ) >expected && | |
82ebb0b6 | 269 | test_cmp expected actual |
5aa5cd46 JH |
270 | |
271 | ' | |
272 | ||
c1e01b0c DB |
273 | test_expect_success 'signoff gap' ' |
274 | ||
275 | echo 3 >positive && | |
276 | git add positive && | |
277 | alt="Alt-RFC-822-Header: Value" && | |
278 | git commit -s -m "welcome | |
279 | ||
280 | $alt" && | |
281 | git cat-file commit HEAD | sed -e "1,/^\$/d" > actual && | |
282 | ( | |
283 | echo welcome | |
284 | echo | |
285 | echo $alt | |
286 | git var GIT_COMMITTER_IDENT | | |
287 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" | |
288 | ) >expected && | |
289 | test_cmp expected actual | |
290 | ' | |
291 | ||
292 | test_expect_success 'signoff gap 2' ' | |
293 | ||
294 | echo 4 >positive && | |
295 | git add positive && | |
296 | alt="fixed: 34" && | |
297 | git commit -s -m "welcome | |
298 | ||
299 | We have now | |
300 | $alt" && | |
301 | git cat-file commit HEAD | sed -e "1,/^\$/d" > actual && | |
302 | ( | |
303 | echo welcome | |
304 | echo | |
305 | echo We have now | |
306 | echo $alt | |
307 | echo | |
308 | git var GIT_COMMITTER_IDENT | | |
309 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" | |
310 | ) >expected && | |
311 | test_cmp expected actual | |
312 | ' | |
313 | ||
5aa5cd46 JH |
314 | test_expect_success 'multiple -m' ' |
315 | ||
316 | >negative && | |
317 | git add negative && | |
318 | git commit -m "one" -m "two" -m "three" && | |
319 | git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && | |
320 | ( | |
321 | echo one | |
322 | echo | |
323 | echo two | |
324 | echo | |
325 | echo three | |
326 | ) >expected && | |
82ebb0b6 | 327 | test_cmp expected actual |
5aa5cd46 JH |
328 | |
329 | ' | |
330 | ||
d63c2fd1 KH |
331 | author="The Real Author <someguy@his.email.org>" |
332 | test_expect_success 'amend commit to fix author' ' | |
333 | ||
334 | oldtick=$GIT_AUTHOR_DATE && | |
335 | test_tick && | |
336 | git reset --hard && | |
337 | git cat-file -p HEAD | | |
338 | sed -e "s/author.*/author $author $oldtick/" \ | |
339 | -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ | |
340 | expected && | |
341 | git commit --amend --author="$author" && | |
342 | git cat-file -p HEAD > current && | |
1e368681 | 343 | test_cmp expected current |
d63c2fd1 KH |
344 | |
345 | ' | |
1200993a KH |
346 | |
347 | test_expect_success 'git commit <file> with dirty index' ' | |
348 | echo tacocat > elif && | |
349 | echo tehlulz > chz && | |
350 | git add chz && | |
351 | git commit elif -m "tacocat is a palindrome" && | |
352 | git show --stat | grep elif && | |
353 | git diff --cached | grep chz | |
354 | ' | |
355 | ||
13aba1e5 JS |
356 | test_expect_success 'same tree (single parent)' ' |
357 | ||
31cbb5d9 JH |
358 | git reset --hard |
359 | ||
13aba1e5 JS |
360 | if git commit -m empty |
361 | then | |
362 | echo oops -- should have complained | |
363 | false | |
364 | else | |
365 | : happy | |
366 | fi | |
367 | ||
368 | ' | |
369 | ||
36863af1 JH |
370 | test_expect_success 'same tree (single parent) --allow-empty' ' |
371 | ||
372 | git commit --allow-empty -m "forced empty" && | |
373 | git cat-file commit HEAD | grep forced | |
374 | ||
375 | ' | |
376 | ||
13aba1e5 JS |
377 | test_expect_success 'same tree (merge and amend merge)' ' |
378 | ||
379 | git checkout -b side HEAD^ && | |
380 | echo zero >zero && | |
381 | git add zero && | |
382 | git commit -m "add zero" && | |
383 | git checkout master && | |
384 | ||
385 | git merge -s ours side -m "empty ok" && | |
386 | git diff HEAD^ HEAD >actual && | |
387 | : >expected && | |
82ebb0b6 | 388 | test_cmp expected actual && |
13aba1e5 JS |
389 | |
390 | git commit --amend -m "empty really ok" && | |
391 | git diff HEAD^ HEAD >actual && | |
392 | : >expected && | |
82ebb0b6 | 393 | test_cmp expected actual |
13aba1e5 JS |
394 | |
395 | ' | |
396 | ||
1eb1e9ee JH |
397 | test_expect_success 'amend using the message from another commit' ' |
398 | ||
399 | git reset --hard && | |
400 | test_tick && | |
401 | git commit --allow-empty -m "old commit" && | |
402 | old=$(git rev-parse --verify HEAD) && | |
403 | test_tick && | |
404 | git commit --allow-empty -m "new commit" && | |
405 | new=$(git rev-parse --verify HEAD) && | |
406 | test_tick && | |
407 | git commit --allow-empty --amend -C "$old" && | |
408 | git show --pretty="format:%ad %s" "$old" >expected && | |
409 | git show --pretty="format:%ad %s" HEAD >actual && | |
82ebb0b6 | 410 | test_cmp expected actual |
1eb1e9ee JH |
411 | |
412 | ' | |
413 | ||
8a2f8733 JH |
414 | test_expect_success 'amend using the message from a commit named with tag' ' |
415 | ||
416 | git reset --hard && | |
417 | test_tick && | |
418 | git commit --allow-empty -m "old commit" && | |
419 | old=$(git rev-parse --verify HEAD) && | |
420 | git tag -a -m "tag on old" tagged-old HEAD && | |
421 | test_tick && | |
422 | git commit --allow-empty -m "new commit" && | |
423 | new=$(git rev-parse --verify HEAD) && | |
424 | test_tick && | |
425 | git commit --allow-empty --amend -C tagged-old && | |
426 | git show --pretty="format:%ad %s" "$old" >expected && | |
427 | git show --pretty="format:%ad %s" HEAD >actual && | |
82ebb0b6 | 428 | test_cmp expected actual |
8a2f8733 JH |
429 | |
430 | ' | |
431 | ||
6360d343 TR |
432 | test_expect_success 'amend can copy notes' ' |
433 | ||
434 | git config notes.rewrite.amend true && | |
435 | git config notes.rewriteRef "refs/notes/*" && | |
436 | test_commit foo && | |
437 | git notes add -m"a note" && | |
438 | test_tick && | |
439 | git commit --amend -m"new foo" && | |
440 | test "$(git notes show)" = "a note" | |
441 | ||
442 | ' | |
443 | ||
12ace0b2 | 444 | test_done |