3 test_description
='git commit porcelain-ish'
7 # Arguments: [<prefix] [<commit message>] [<commit options>]
8 check_summary_oneline
() {
10 git commit
${3+"$3"} -m "$2" |
head -1 > act
&&
13 SUMMARY_PREFIX
="$(git name-rev --name-only HEAD)" &&
15 # append the "special" prefix, like "root-commit", "detached HEAD"
18 SUMMARY_PREFIX
="$SUMMARY_PREFIX ($1)"
22 SUMMARY_POSTFIX
="$(git log -1 --pretty='format:%h')"
23 echo "[$SUMMARY_PREFIX $SUMMARY_POSTFIX] $2" >exp
&&
28 test_expect_success
'output summary format' '
32 check_summary_oneline "root-commit" "initial" &&
34 echo change >>file1 &&
36 check_summary_oneline "" "a change"
39 test_expect_success
'output summary format for commit with an empty diff' '
41 check_summary_oneline "" "empty" "--allow-empty"
44 test_expect_success
'output summary format for merges' '
46 git checkout -b recursive-base &&
47 test_commit base file1 &&
49 git checkout -b recursive-a recursive-base &&
50 test_commit commit-a file1 &&
52 git checkout -b recursive-b recursive-base &&
53 test_commit commit-b file1 &&
56 git checkout recursive-a &&
57 test_must_fail git merge recursive-b &&
58 # resolve the conflict
59 echo commit-a > file1 &&
61 check_summary_oneline "" "Merge"
64 output_tests_cleanup
() {
65 # this is needed for "do not fire editor in the presence of conflicts"
66 git checkout master
&&
68 # this is needed for the "partial removal" test to pass
70 git commit
-m "cleanup"
73 test_expect_success
'the basics' '
75 output_tests_cleanup &&
77 echo doing partial >"commit is" &&
79 echo very much encouraged but we should >not/forbid &&
80 git add "commit is" not &&
81 echo update added "commit is" file >"commit is" &&
82 echo also update another >not/forbid &&
84 git commit -a -m "initial with -a" &&
86 git cat-file blob HEAD:"commit is" >current.1 &&
87 git cat-file blob HEAD:not/forbid >current.2 &&
89 cmp current.1 "commit is" &&
90 cmp current.2 not/forbid
94 test_expect_success
'partial' '
96 echo another >"commit is" &&
97 echo another >not/forbid &&
99 git commit -m "partial commit to handle a file" "commit is" &&
101 changed=$(git diff-tree --name-only HEAD^ HEAD) &&
102 test "$changed" = "commit is"
106 test_expect_success
'partial modification in a subdirectory' '
109 git commit -m "partial commit to subdirectory" not &&
111 changed=$(git diff-tree -r --name-only HEAD^ HEAD) &&
112 test "$changed" = "not/forbid"
116 test_expect_success
'partial removal' '
119 git commit -m "partial commit to remove not/forbid" not &&
121 changed=$(git diff-tree -r --name-only HEAD^ HEAD) &&
122 test "$changed" = "not/forbid" &&
123 remain=$(git ls-tree -r --name-only HEAD) &&
124 test "$remain" = "commit is"
128 test_expect_success
'sign off' '
132 git commit -s -m "thank you" &&
133 actual=$(git cat-file commit HEAD | sed -ne "s/Signed-off-by: //p") &&
134 expected=$(git var GIT_COMMITTER_IDENT | sed -e "s/>.*/>/") &&
135 test "z$actual" = "z$expected"
139 test_expect_success
'multiple -m' '
143 git commit -m "one" -m "two" -m "three" &&
144 actual=$(git cat-file commit HEAD | sed -e "1,/^\$/d") &&
145 expected=$(echo one; echo; echo two; echo; echo three) &&
146 test "z$actual" = "z$expected"
150 test_expect_success
'verbose' '
152 echo minus >negative &&
154 git status -v | sed -ne "/^diff --git /p" >actual &&
155 echo "diff --git a/negative b/negative" >expect &&
156 test_cmp expect actual
160 test_expect_success
'verbose respects diff config' '
162 git config color.diff always &&
163 git status -v >actual &&
164 grep "\[1mdiff --git" actual &&
165 git config --unset color.diff
168 test_expect_success
'cleanup commit messages (verbatim,-t)' '
171 { echo;echo "# text";echo; } >expect &&
172 git commit --cleanup=verbatim -t expect -a &&
173 git cat-file -p HEAD |sed -e "1,/^\$/d" |head -n 3 >actual &&
174 test_cmp expect actual
178 test_expect_success
'cleanup commit messages (verbatim,-F)' '
181 git commit --cleanup=verbatim -F expect -a &&
182 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
183 test_cmp expect actual
187 test_expect_success
'cleanup commit messages (verbatim,-m)' '
190 git commit --cleanup=verbatim -m "$(cat expect)" -a &&
191 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
192 test_cmp expect actual
196 test_expect_success
'cleanup commit messages (whitespace,-F)' '
199 { echo;echo "# text";echo; } >text &&
200 echo "# text" >expect &&
201 git commit --cleanup=whitespace -F text -a &&
202 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
203 test_cmp expect actual
207 test_expect_success
'cleanup commit messages (strip,-F)' '
210 { echo;echo "# text";echo sample;echo; } >text &&
211 echo sample >expect &&
212 git commit --cleanup=strip -F text -a &&
213 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
214 test_cmp expect actual
220 # Please enter the commit message for your changes. Lines starting
221 # with '#' will be ignored, and an empty message aborts the commit." >expect
223 test_expect_success
'cleanup commit messages (strip,-F,-e)' '
226 { echo;echo sample;echo; } >text &&
227 git commit -e -F text -a &&
228 head -n 4 .git/COMMIT_EDITMSG >actual &&
229 test_cmp expect actual
234 # Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
237 test_expect_success
'author different from committer' '
240 git commit -e -m "sample"
241 head -n 7 .git/COMMIT_EDITMSG >actual &&
242 test_cmp expect actual
246 sed '$d' < expect.tmp
> expect
251 test_expect_success
'committer is automatic' '
255 sane_unset GIT_COMMITTER_EMAIL &&
256 sane_unset GIT_COMMITTER_NAME &&
257 # must fail because there is no change
258 test_must_fail git commit -e -m "sample"
260 head -n 8 .git/COMMIT_EDITMSG | \
261 sed "s/^# Committer: .*/# Committer:/" >actual &&
262 test_cmp expect actual
266 cat >> .git
/FAKE_EDITOR
<< EOF
268 echo editor started > "$pwd/.git/result"
271 chmod +x .git
/FAKE_EDITOR
273 test_expect_success
'do not fire editor in the presence of conflicts' '
278 git commit -m "add g" &&
283 git commit -m "modify g and add h" &&
284 git checkout second &&
287 git commit -m second &&
288 # Must fail due to conflict
289 test_must_fail git cherry-pick -n master &&
290 echo "editor not started" >.git/result &&
292 GIT_EDITOR="$(pwd)/.git/FAKE_EDITOR" &&
294 test_must_fail git commit
296 test "$(cat .git/result)" = "editor not started"
300 cat >.git
/FAKE_EDITOR
<<EOF
302 # kill -TERM command added below.
305 test_expect_success EXECKEEPSPID
'a SIGTERM should break locks' '
307 ! "$SHELL_PATH" -c '\''
308 echo kill -TERM $$ >> .git/FAKE_EDITOR
309 GIT_EDITOR=.git/FAKE_EDITOR
311 exec git commit -a'\'' &&
312 test ! -f .git/index.lock
315 rm -f .git
/MERGE_MSG .git
/COMMIT_EDITMSG
318 test_expect_success
'Hand committing of a redundant merge removes dups' '
320 git rev-parse second master >expect &&
321 test_must_fail git merge second master &&
322 git checkout master g &&
323 EDITOR=: git commit -a &&
324 git cat-file commit HEAD | sed -n -e "s/^parent //p" -e "/^$/q" >actual &&
325 test_cmp expect actual
329 test_expect_success
'A single-liner subject with a token plus colon is not a footer' '
332 git commit -s -m "hello: kitty" --allow-empty &&
333 git cat-file commit HEAD | sed -e "1,/^$/d" >actual &&
334 test $(wc -l <actual) = 3
338 cat >.git
/FAKE_EDITOR
<<EOF
347 echo '## Custom template' >template
351 git config
--unset-all "$1"
362 GIT_EDITOR
=.git
/FAKE_EDITOR git commit
-a $
* $use_template &&
363 case "$use_template" in
365 ! grep "^## Custom template" .git
/COMMIT_EDITMSG
;;
367 grep "^## Custom template" .git
/COMMIT_EDITMSG
;;
371 try_commit_status_combo
() {
373 test_expect_success
'commit' '
374 clear_config commit.status &&
376 grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
379 test_expect_success
'commit' '
380 clear_config commit.status &&
382 grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
385 test_expect_success
'commit --status' '
386 clear_config commit.status &&
387 try_commit --status &&
388 grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
391 test_expect_success
'commit --no-status' '
392 clear_config commit.status &&
393 try_commit --no-status &&
394 ! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
397 test_expect_success
'commit with commit.status = yes' '
398 clear_config commit.status &&
399 git config commit.status yes &&
401 grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
404 test_expect_success
'commit with commit.status = no' '
405 clear_config commit.status &&
406 git config commit.status no &&
408 ! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
411 test_expect_success
'commit --status with commit.status = yes' '
412 clear_config commit.status &&
413 git config commit.status yes &&
414 try_commit --status &&
415 grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
418 test_expect_success
'commit --no-status with commit.status = yes' '
419 clear_config commit.status &&
420 git config commit.status yes &&
421 try_commit --no-status &&
422 ! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
425 test_expect_success
'commit --status with commit.status = no' '
426 clear_config commit.status &&
427 git config commit.status no &&
428 try_commit --status &&
429 grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
432 test_expect_success
'commit --no-status with commit.status = no' '
433 clear_config commit.status &&
434 git config commit.status no &&
435 try_commit --no-status &&
436 ! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
441 try_commit_status_combo
443 use_template
="-t template"
445 try_commit_status_combo