]>
Commit | Line | Data |
---|---|---|
b468f0ce JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='git commit porcelain-ish' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
cee9f2b3 | 7 | # Arguments: [<prefix] [<commit message>] [<commit options>] |
fc6fa0d0 TRC |
8 | check_summary_oneline() { |
9 | test_tick && | |
cee9f2b3 | 10 | git commit ${3+"$3"} -m "$2" | head -1 > act && |
fc6fa0d0 TRC |
11 | |
12 | # branch name | |
13 | SUMMARY_PREFIX="$(git name-rev --name-only HEAD)" && | |
14 | ||
15 | # append the "special" prefix, like "root-commit", "detached HEAD" | |
16 | if test -n "$1" | |
17 | then | |
18 | SUMMARY_PREFIX="$SUMMARY_PREFIX ($1)" | |
19 | fi | |
20 | ||
21 | # abbrev SHA-1 | |
22 | SUMMARY_POSTFIX="$(git log -1 --pretty='format:%h')" | |
23 | echo "[$SUMMARY_PREFIX $SUMMARY_POSTFIX] $2" >exp && | |
24 | ||
f79ce8db | 25 | test_i18ncmp exp act |
fc6fa0d0 TRC |
26 | } |
27 | ||
28 | test_expect_success 'output summary format' ' | |
29 | ||
30 | echo new >file1 && | |
31 | git add file1 && | |
32 | check_summary_oneline "root-commit" "initial" && | |
33 | ||
34 | echo change >>file1 && | |
7f5673d7 ÆAB |
35 | git add file1 |
36 | ' | |
37 | ||
38 | test_expect_success 'output summary format: root-commit' ' | |
fc6fa0d0 TRC |
39 | check_summary_oneline "" "a change" |
40 | ' | |
41 | ||
a45e1a87 | 42 | test_expect_success 'output summary format for commit with an empty diff' ' |
cee9f2b3 TRC |
43 | |
44 | check_summary_oneline "" "empty" "--allow-empty" | |
45 | ' | |
46 | ||
a45e1a87 | 47 | test_expect_success 'output summary format for merges' ' |
cee9f2b3 TRC |
48 | |
49 | git checkout -b recursive-base && | |
50 | test_commit base file1 && | |
51 | ||
52 | git checkout -b recursive-a recursive-base && | |
53 | test_commit commit-a file1 && | |
54 | ||
55 | git checkout -b recursive-b recursive-base && | |
56 | test_commit commit-b file1 && | |
57 | ||
58 | # conflict | |
59 | git checkout recursive-a && | |
60 | test_must_fail git merge recursive-b && | |
61 | # resolve the conflict | |
62 | echo commit-a > file1 && | |
63 | git add file1 && | |
64 | check_summary_oneline "" "Merge" | |
65 | ' | |
66 | ||
fc6fa0d0 TRC |
67 | output_tests_cleanup() { |
68 | # this is needed for "do not fire editor in the presence of conflicts" | |
69 | git checkout master && | |
70 | ||
71 | # this is needed for the "partial removal" test to pass | |
72 | git rm file1 && | |
73 | git commit -m "cleanup" | |
74 | } | |
75 | ||
b468f0ce JH |
76 | test_expect_success 'the basics' ' |
77 | ||
fc6fa0d0 TRC |
78 | output_tests_cleanup && |
79 | ||
b468f0ce JH |
80 | echo doing partial >"commit is" && |
81 | mkdir not && | |
82 | echo very much encouraged but we should >not/forbid && | |
83 | git add "commit is" not && | |
84 | echo update added "commit is" file >"commit is" && | |
85 | echo also update another >not/forbid && | |
86 | test_tick && | |
87 | git commit -a -m "initial with -a" && | |
88 | ||
89 | git cat-file blob HEAD:"commit is" >current.1 && | |
90 | git cat-file blob HEAD:not/forbid >current.2 && | |
91 | ||
92 | cmp current.1 "commit is" && | |
93 | cmp current.2 not/forbid | |
94 | ||
95 | ' | |
96 | ||
97 | test_expect_success 'partial' ' | |
98 | ||
99 | echo another >"commit is" && | |
100 | echo another >not/forbid && | |
101 | test_tick && | |
102 | git commit -m "partial commit to handle a file" "commit is" && | |
103 | ||
104 | changed=$(git diff-tree --name-only HEAD^ HEAD) && | |
105 | test "$changed" = "commit is" | |
106 | ||
107 | ' | |
108 | ||
e8f30160 | 109 | test_expect_success 'partial modification in a subdirectory' ' |
b468f0ce JH |
110 | |
111 | test_tick && | |
112 | git commit -m "partial commit to subdirectory" not && | |
113 | ||
114 | changed=$(git diff-tree -r --name-only HEAD^ HEAD) && | |
115 | test "$changed" = "not/forbid" | |
116 | ||
117 | ' | |
118 | ||
119 | test_expect_success 'partial removal' ' | |
120 | ||
121 | git rm not/forbid && | |
122 | git commit -m "partial commit to remove not/forbid" not && | |
123 | ||
124 | changed=$(git diff-tree -r --name-only HEAD^ HEAD) && | |
125 | test "$changed" = "not/forbid" && | |
126 | remain=$(git ls-tree -r --name-only HEAD) && | |
127 | test "$remain" = "commit is" | |
128 | ||
129 | ' | |
130 | ||
131 | test_expect_success 'sign off' ' | |
132 | ||
133 | >positive && | |
134 | git add positive && | |
135 | git commit -s -m "thank you" && | |
136 | actual=$(git cat-file commit HEAD | sed -ne "s/Signed-off-by: //p") && | |
137 | expected=$(git var GIT_COMMITTER_IDENT | sed -e "s/>.*/>/") && | |
138 | test "z$actual" = "z$expected" | |
139 | ||
140 | ' | |
141 | ||
142 | test_expect_success 'multiple -m' ' | |
143 | ||
144 | >negative && | |
145 | git add negative && | |
146 | git commit -m "one" -m "two" -m "three" && | |
147 | actual=$(git cat-file commit HEAD | sed -e "1,/^\$/d") && | |
148 | expected=$(echo one; echo; echo two; echo; echo three) && | |
149 | test "z$actual" = "z$expected" | |
150 | ||
151 | ' | |
152 | ||
153 | test_expect_success 'verbose' ' | |
154 | ||
155 | echo minus >negative && | |
156 | git add negative && | |
157 | git status -v | sed -ne "/^diff --git /p" >actual && | |
158 | echo "diff --git a/negative b/negative" >expect && | |
82ebb0b6 | 159 | test_cmp expect actual |
b468f0ce JH |
160 | |
161 | ' | |
162 | ||
4f672ad6 JK |
163 | test_expect_success 'verbose respects diff config' ' |
164 | ||
165 | git config color.diff always && | |
166 | git status -v >actual && | |
167 | grep "\[1mdiff --git" actual && | |
168 | git config --unset color.diff | |
169 | ' | |
170 | ||
5f065737 AR |
171 | test_expect_success 'cleanup commit messages (verbatim,-t)' ' |
172 | ||
173 | echo >>negative && | |
174 | { echo;echo "# text";echo; } >expect && | |
175 | git commit --cleanup=verbatim -t expect -a && | |
176 | git cat-file -p HEAD |sed -e "1,/^\$/d" |head -n 3 >actual && | |
82ebb0b6 | 177 | test_cmp expect actual |
5f065737 AR |
178 | |
179 | ' | |
180 | ||
181 | test_expect_success 'cleanup commit messages (verbatim,-F)' ' | |
182 | ||
183 | echo >>negative && | |
184 | git commit --cleanup=verbatim -F expect -a && | |
185 | git cat-file -p HEAD |sed -e "1,/^\$/d">actual && | |
82ebb0b6 | 186 | test_cmp expect actual |
5f065737 AR |
187 | |
188 | ' | |
189 | ||
190 | test_expect_success 'cleanup commit messages (verbatim,-m)' ' | |
191 | ||
192 | echo >>negative && | |
193 | git commit --cleanup=verbatim -m "$(cat expect)" -a && | |
194 | git cat-file -p HEAD |sed -e "1,/^\$/d">actual && | |
82ebb0b6 | 195 | test_cmp expect actual |
5f065737 AR |
196 | |
197 | ' | |
198 | ||
199 | test_expect_success 'cleanup commit messages (whitespace,-F)' ' | |
200 | ||
201 | echo >>negative && | |
202 | { echo;echo "# text";echo; } >text && | |
203 | echo "# text" >expect && | |
204 | git commit --cleanup=whitespace -F text -a && | |
205 | git cat-file -p HEAD |sed -e "1,/^\$/d">actual && | |
82ebb0b6 | 206 | test_cmp expect actual |
5f065737 AR |
207 | |
208 | ' | |
209 | ||
210 | test_expect_success 'cleanup commit messages (strip,-F)' ' | |
211 | ||
212 | echo >>negative && | |
213 | { echo;echo "# text";echo sample;echo; } >text && | |
214 | echo sample >expect && | |
215 | git commit --cleanup=strip -F text -a && | |
216 | git cat-file -p HEAD |sed -e "1,/^\$/d">actual && | |
82ebb0b6 | 217 | test_cmp expect actual |
5f065737 AR |
218 | |
219 | ' | |
220 | ||
5f065737 AR |
221 | test_expect_success 'cleanup commit messages (strip,-F,-e)' ' |
222 | ||
223 | echo >>negative && | |
224 | { echo;echo sample;echo; } >text && | |
225 | git commit -e -F text -a && | |
0b430a17 ÆAB |
226 | head -n 4 .git/COMMIT_EDITMSG >actual |
227 | ' | |
228 | ||
229 | echo "sample | |
5f065737 | 230 | |
0b430a17 ÆAB |
231 | # Please enter the commit message for your changes. Lines starting |
232 | # with '#' will be ignored, and an empty message aborts the commit." >expect | |
233 | ||
f79ce8db JH |
234 | test_expect_success 'cleanup commit messages (strip,-F,-e): output' ' |
235 | test_i18ncmp expect actual | |
5f065737 AR |
236 | ' |
237 | ||
e83dbe80 SB |
238 | echo "# |
239 | # Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> | |
240 | #" >> expect | |
241 | ||
f79ce8db | 242 | test_expect_success 'author different from committer' ' |
e83dbe80 | 243 | echo >>negative && |
f79ce8db JH |
244 | test_might_fail git commit -e -m "sample" && |
245 | head -n 7 .git/COMMIT_EDITMSG >actual && | |
246 | test_i18ncmp expect actual | |
e83dbe80 SB |
247 | ' |
248 | ||
d16d5cdf MK |
249 | mv expect expect.tmp |
250 | sed '$d' < expect.tmp > expect | |
251 | rm -f expect.tmp | |
bb1ae3f6 SB |
252 | echo "# Committer: |
253 | #" >> expect | |
bb1ae3f6 | 254 | |
f79ce8db | 255 | test_expect_success 'committer is automatic' ' |
bb1ae3f6 SB |
256 | |
257 | echo >>negative && | |
7845944c | 258 | ( |
00648ba0 EN |
259 | sane_unset GIT_COMMITTER_EMAIL && |
260 | sane_unset GIT_COMMITTER_NAME && | |
7845944c JH |
261 | # must fail because there is no change |
262 | test_must_fail git commit -e -m "sample" | |
263 | ) && | |
fdc7c811 | 264 | head -n 8 .git/COMMIT_EDITMSG | \ |
0b430a17 | 265 | sed "s/^# Committer: .*/# Committer:/" >actual |
f79ce8db | 266 | test_i18ncmp expect actual |
bb1ae3f6 SB |
267 | ' |
268 | ||
ec84bd00 PB |
269 | pwd=`pwd` |
270 | cat >> .git/FAKE_EDITOR << EOF | |
271 | #! /bin/sh | |
272 | echo editor started > "$pwd/.git/result" | |
273 | exit 0 | |
274 | EOF | |
275 | chmod +x .git/FAKE_EDITOR | |
276 | ||
277 | test_expect_success 'do not fire editor in the presence of conflicts' ' | |
278 | ||
a3c91e08 JH |
279 | git clean -f && |
280 | echo f >g && | |
281 | git add g && | |
282 | git commit -m "add g" && | |
283 | git branch second && | |
284 | echo master >g && | |
285 | echo g >h && | |
286 | git add g h && | |
287 | git commit -m "modify g and add h" && | |
288 | git checkout second && | |
289 | echo second >g && | |
290 | git add g && | |
291 | git commit -m second && | |
292 | # Must fail due to conflict | |
293 | test_must_fail git cherry-pick -n master && | |
294 | echo "editor not started" >.git/result && | |
e2007832 BC |
295 | ( |
296 | GIT_EDITOR="$(pwd)/.git/FAKE_EDITOR" && | |
297 | export GIT_EDITOR && | |
298 | test_must_fail git commit | |
299 | ) && | |
a3c91e08 | 300 | test "$(cat .git/result)" = "editor not started" |
ec84bd00 PB |
301 | ' |
302 | ||
ad5fa3cc | 303 | pwd=`pwd` |
de5825cc JH |
304 | cat >.git/FAKE_EDITOR <<EOF |
305 | #! $SHELL_PATH | |
ad5fa3cc PB |
306 | # kill -TERM command added below. |
307 | EOF | |
308 | ||
fb9a2bea | 309 | test_expect_success EXECKEEPSPID 'a SIGTERM should break locks' ' |
ad5fa3cc | 310 | echo >>negative && |
09b78bc1 | 311 | ! "$SHELL_PATH" -c '\'' |
ad5fa3cc | 312 | echo kill -TERM $$ >> .git/FAKE_EDITOR |
09b78bc1 BC |
313 | GIT_EDITOR=.git/FAKE_EDITOR |
314 | export GIT_EDITOR | |
315 | exec git commit -a'\'' && | |
316 | test ! -f .git/index.lock | |
ad5fa3cc PB |
317 | ' |
318 | ||
67bfc030 JH |
319 | rm -f .git/MERGE_MSG .git/COMMIT_EDITMSG |
320 | git reset -q --hard | |
321 | ||
322 | test_expect_success 'Hand committing of a redundant merge removes dups' ' | |
323 | ||
324 | git rev-parse second master >expect && | |
325 | test_must_fail git merge second master && | |
326 | git checkout master g && | |
327 | EDITOR=: git commit -a && | |
328 | git cat-file commit HEAD | sed -n -e "s/^parent //p" -e "/^$/q" >actual && | |
329 | test_cmp expect actual | |
330 | ||
331 | ' | |
332 | ||
e5138436 JH |
333 | test_expect_success 'A single-liner subject with a token plus colon is not a footer' ' |
334 | ||
335 | git reset --hard && | |
336 | git commit -s -m "hello: kitty" --allow-empty && | |
337 | git cat-file commit HEAD | sed -e "1,/^$/d" >actual && | |
338 | test $(wc -l <actual) = 3 | |
339 | ||
340 | ' | |
341 | ||
f9c01817 JH |
342 | cat >.git/FAKE_EDITOR <<EOF |
343 | #!$SHELL_PATH | |
344 | mv "\$1" "\$1.orig" | |
345 | ( | |
346 | echo message | |
347 | cat "\$1.orig" | |
348 | ) >"\$1" | |
349 | EOF | |
350 | ||
351 | echo '## Custom template' >template | |
352 | ||
353 | clear_config () { | |
354 | ( | |
355 | git config --unset-all "$1" | |
356 | case $? in | |
357 | 0|5) exit 0 ;; | |
358 | *) exit 1 ;; | |
359 | esac | |
360 | ) | |
361 | } | |
362 | ||
363 | try_commit () { | |
364 | git reset --hard && | |
365 | echo >>negative && | |
366 | GIT_EDITOR=.git/FAKE_EDITOR git commit -a $* $use_template && | |
367 | case "$use_template" in | |
368 | '') | |
f79ce8db | 369 | test_i18ngrep ! "^## Custom template" .git/COMMIT_EDITMSG ;; |
f9c01817 | 370 | *) |
f79ce8db | 371 | test_i18ngrep "^## Custom template" .git/COMMIT_EDITMSG ;; |
f9c01817 JH |
372 | esac |
373 | } | |
374 | ||
375 | try_commit_status_combo () { | |
376 | ||
f79ce8db | 377 | test_expect_success 'commit' ' |
f9c01817 JH |
378 | clear_config commit.status && |
379 | try_commit "" && | |
f79ce8db | 380 | test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG |
f9c01817 JH |
381 | ' |
382 | ||
f79ce8db | 383 | test_expect_success 'commit' ' |
f9c01817 JH |
384 | clear_config commit.status && |
385 | try_commit "" && | |
f79ce8db | 386 | test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG |
f9c01817 JH |
387 | ' |
388 | ||
f79ce8db | 389 | test_expect_success 'commit --status' ' |
f9c01817 JH |
390 | clear_config commit.status && |
391 | try_commit --status && | |
f79ce8db | 392 | test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG |
f9c01817 JH |
393 | ' |
394 | ||
f79ce8db | 395 | test_expect_success 'commit --no-status' ' |
f9c01817 | 396 | clear_config commit.status && |
2dec68cf | 397 | try_commit --no-status && |
f79ce8db | 398 | test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG |
f9c01817 JH |
399 | ' |
400 | ||
f79ce8db | 401 | test_expect_success 'commit with commit.status = yes' ' |
f9c01817 JH |
402 | clear_config commit.status && |
403 | git config commit.status yes && | |
404 | try_commit "" && | |
f79ce8db | 405 | test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG |
f9c01817 JH |
406 | ' |
407 | ||
f79ce8db | 408 | test_expect_success 'commit with commit.status = no' ' |
f9c01817 JH |
409 | clear_config commit.status && |
410 | git config commit.status no && | |
411 | try_commit "" && | |
f79ce8db | 412 | test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG |
f9c01817 JH |
413 | ' |
414 | ||
f79ce8db | 415 | test_expect_success 'commit --status with commit.status = yes' ' |
f9c01817 JH |
416 | clear_config commit.status && |
417 | git config commit.status yes && | |
418 | try_commit --status && | |
f79ce8db | 419 | test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG |
f9c01817 JH |
420 | ' |
421 | ||
f79ce8db | 422 | test_expect_success 'commit --no-status with commit.status = yes' ' |
f9c01817 JH |
423 | clear_config commit.status && |
424 | git config commit.status yes && | |
425 | try_commit --no-status && | |
f79ce8db | 426 | test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG |
f9c01817 JH |
427 | ' |
428 | ||
f79ce8db | 429 | test_expect_success 'commit --status with commit.status = no' ' |
f9c01817 JH |
430 | clear_config commit.status && |
431 | git config commit.status no && | |
432 | try_commit --status && | |
f79ce8db | 433 | test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG |
f9c01817 JH |
434 | ' |
435 | ||
f79ce8db | 436 | test_expect_success 'commit --no-status with commit.status = no' ' |
f9c01817 JH |
437 | clear_config commit.status && |
438 | git config commit.status no && | |
439 | try_commit --no-status && | |
f79ce8db | 440 | test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG |
f9c01817 JH |
441 | ' |
442 | ||
443 | } | |
444 | ||
445 | try_commit_status_combo | |
446 | ||
447 | use_template="-t template" | |
448 | ||
449 | try_commit_status_combo | |
450 | ||
b468f0ce | 451 | test_done |