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
&&
25 if test_have_prereq C_LOCALE_OUTPUT
31 test_expect_success
'output summary format' '
35 check_summary_oneline "root-commit" "initial" &&
37 echo change >>file1 &&
41 test_expect_success
'output summary format: root-commit' '
42 check_summary_oneline "" "a change"
45 test_expect_success
'output summary format for commit with an empty diff' '
47 check_summary_oneline "" "empty" "--allow-empty"
50 test_expect_success
'output summary format for merges' '
52 git checkout -b recursive-base &&
53 test_commit base file1 &&
55 git checkout -b recursive-a recursive-base &&
56 test_commit commit-a file1 &&
58 git checkout -b recursive-b recursive-base &&
59 test_commit commit-b file1 &&
62 git checkout recursive-a &&
63 test_must_fail git merge recursive-b &&
64 # resolve the conflict
65 echo commit-a > file1 &&
67 check_summary_oneline "" "Merge"
70 output_tests_cleanup
() {
71 # this is needed for "do not fire editor in the presence of conflicts"
72 git checkout master
&&
74 # this is needed for the "partial removal" test to pass
76 git commit
-m "cleanup"
79 test_expect_success
'the basics' '
81 output_tests_cleanup &&
83 echo doing partial >"commit is" &&
85 echo very much encouraged but we should >not/forbid &&
86 git add "commit is" not &&
87 echo update added "commit is" file >"commit is" &&
88 echo also update another >not/forbid &&
90 git commit -a -m "initial with -a" &&
92 git cat-file blob HEAD:"commit is" >current.1 &&
93 git cat-file blob HEAD:not/forbid >current.2 &&
95 cmp current.1 "commit is" &&
96 cmp current.2 not/forbid
100 test_expect_success
'partial' '
102 echo another >"commit is" &&
103 echo another >not/forbid &&
105 git commit -m "partial commit to handle a file" "commit is" &&
107 changed=$(git diff-tree --name-only HEAD^ HEAD) &&
108 test "$changed" = "commit is"
112 test_expect_success
'partial modification in a subdirectory' '
115 git commit -m "partial commit to subdirectory" not &&
117 changed=$(git diff-tree -r --name-only HEAD^ HEAD) &&
118 test "$changed" = "not/forbid"
122 test_expect_success
'partial removal' '
125 git commit -m "partial commit to remove not/forbid" not &&
127 changed=$(git diff-tree -r --name-only HEAD^ HEAD) &&
128 test "$changed" = "not/forbid" &&
129 remain=$(git ls-tree -r --name-only HEAD) &&
130 test "$remain" = "commit is"
134 test_expect_success
'sign off' '
138 git commit -s -m "thank you" &&
139 actual=$(git cat-file commit HEAD | sed -ne "s/Signed-off-by: //p") &&
140 expected=$(git var GIT_COMMITTER_IDENT | sed -e "s/>.*/>/") &&
141 test "z$actual" = "z$expected"
145 test_expect_success
'multiple -m' '
149 git commit -m "one" -m "two" -m "three" &&
150 actual=$(git cat-file commit HEAD | sed -e "1,/^\$/d") &&
151 expected=$(echo one; echo; echo two; echo; echo three) &&
152 test "z$actual" = "z$expected"
156 test_expect_success
'verbose' '
158 echo minus >negative &&
160 git status -v | sed -ne "/^diff --git /p" >actual &&
161 echo "diff --git a/negative b/negative" >expect &&
162 test_cmp expect actual
166 test_expect_success
'verbose respects diff config' '
168 git config color.diff always &&
169 git status -v >actual &&
170 grep "\[1mdiff --git" actual &&
171 git config --unset color.diff
174 test_expect_success
'cleanup commit messages (verbatim,-t)' '
177 { echo;echo "# text";echo; } >expect &&
178 git commit --cleanup=verbatim -t expect -a &&
179 git cat-file -p HEAD |sed -e "1,/^\$/d" |head -n 3 >actual &&
180 test_cmp expect actual
184 test_expect_success
'cleanup commit messages (verbatim,-F)' '
187 git commit --cleanup=verbatim -F expect -a &&
188 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
189 test_cmp expect actual
193 test_expect_success
'cleanup commit messages (verbatim,-m)' '
196 git commit --cleanup=verbatim -m "$(cat expect)" -a &&
197 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
198 test_cmp expect actual
202 test_expect_success
'cleanup commit messages (whitespace,-F)' '
205 { echo;echo "# text";echo; } >text &&
206 echo "# text" >expect &&
207 git commit --cleanup=whitespace -F text -a &&
208 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
209 test_cmp expect actual
213 test_expect_success
'cleanup commit messages (strip,-F)' '
216 { echo;echo "# text";echo sample;echo; } >text &&
217 echo sample >expect &&
218 git commit --cleanup=strip -F text -a &&
219 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
220 test_cmp expect actual
224 test_expect_success
'cleanup commit messages (strip,-F,-e)' '
227 { echo;echo sample;echo; } >text &&
228 git commit -e -F text -a &&
229 head -n 4 .git/COMMIT_EDITMSG >actual
234 # Please enter the commit message for your changes. Lines starting
235 # with '#' will be ignored, and an empty message aborts the commit." >expect
237 test_expect_success C_LOCALE_OUTPUT
'cleanup commit messages (strip,-F,-e): output' '
238 test_cmp expect actual
242 # Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
245 test_expect_success C_LOCALE_OUTPUT
'author different from committer' '
248 git commit -e -m "sample"
249 head -n 7 .git/COMMIT_EDITMSG >actual
252 test_expect_success C_LOCALE_OUTPUT
'author different from committer: output' '
253 test_cmp expect actual
257 sed '$d' < expect.tmp
> expect
262 test_expect_success C_LOCALE_OUTPUT
'committer is automatic' '
266 sane_unset GIT_COMMITTER_EMAIL &&
267 sane_unset GIT_COMMITTER_NAME &&
268 # must fail because there is no change
269 test_must_fail git commit -e -m "sample"
271 head -n 8 .git/COMMIT_EDITMSG | \
272 sed "s/^# Committer: .*/# Committer:/" >actual
275 test_expect_success C_LOCALE_OUTPUT
'committer is automatic: output' '
276 test_cmp expect actual
280 cat >> .git
/FAKE_EDITOR
<< EOF
282 echo editor started > "$pwd/.git/result"
285 chmod +x .git
/FAKE_EDITOR
287 test_expect_success
'do not fire editor in the presence of conflicts' '
292 git commit -m "add g" &&
297 git commit -m "modify g and add h" &&
298 git checkout second &&
301 git commit -m second &&
302 # Must fail due to conflict
303 test_must_fail git cherry-pick -n master &&
304 echo "editor not started" >.git/result &&
306 GIT_EDITOR="$(pwd)/.git/FAKE_EDITOR" &&
308 test_must_fail git commit
310 test "$(cat .git/result)" = "editor not started"
314 cat >.git
/FAKE_EDITOR
<<EOF
316 # kill -TERM command added below.
319 test_expect_success EXECKEEPSPID
'a SIGTERM should break locks' '
321 ! "$SHELL_PATH" -c '\''
322 echo kill -TERM $$ >> .git/FAKE_EDITOR
323 GIT_EDITOR=.git/FAKE_EDITOR
325 exec git commit -a'\'' &&
326 test ! -f .git/index.lock
329 rm -f .git
/MERGE_MSG .git
/COMMIT_EDITMSG
332 test_expect_success
'Hand committing of a redundant merge removes dups' '
334 git rev-parse second master >expect &&
335 test_must_fail git merge second master &&
336 git checkout master g &&
337 EDITOR=: git commit -a &&
338 git cat-file commit HEAD | sed -n -e "s/^parent //p" -e "/^$/q" >actual &&
339 test_cmp expect actual
343 test_expect_success
'A single-liner subject with a token plus colon is not a footer' '
346 git commit -s -m "hello: kitty" --allow-empty &&
347 git cat-file commit HEAD | sed -e "1,/^$/d" >actual &&
348 test $(wc -l <actual) = 3
352 cat >.git
/FAKE_EDITOR
<<EOF
361 echo '## Custom template' >template
365 git config
--unset-all "$1"
376 GIT_EDITOR
=.git
/FAKE_EDITOR git commit
-a $
* $use_template &&
377 case "$use_template" in
379 ! grep "^## Custom template" .git
/COMMIT_EDITMSG
;;
381 grep "^## Custom template" .git
/COMMIT_EDITMSG
;;
385 try_commit_status_combo
() {
387 test_expect_success C_LOCALE_OUTPUT
'commit' '
388 clear_config commit.status &&
390 grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
393 test_expect_success C_LOCALE_OUTPUT
'commit' '
394 clear_config commit.status &&
396 grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
399 test_expect_success C_LOCALE_OUTPUT
'commit --status' '
400 clear_config commit.status &&
401 try_commit --status &&
402 grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
405 test_expect_success C_LOCALE_OUTPUT
'commit --no-status' '
406 clear_config commit.status &&
407 try_commit --no-status &&
408 ! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
411 test_expect_success C_LOCALE_OUTPUT
'commit with commit.status = yes' '
412 clear_config commit.status &&
413 git config commit.status yes &&
415 grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
418 test_expect_success C_LOCALE_OUTPUT
'commit with commit.status = no' '
419 clear_config commit.status &&
420 git config commit.status no &&
422 ! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
425 test_expect_success C_LOCALE_OUTPUT
'commit --status with commit.status = yes' '
426 clear_config commit.status &&
427 git config commit.status yes &&
428 try_commit --status &&
429 grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
432 test_expect_success C_LOCALE_OUTPUT
'commit --no-status with commit.status = yes' '
433 clear_config commit.status &&
434 git config commit.status yes &&
435 try_commit --no-status &&
436 ! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
439 test_expect_success C_LOCALE_OUTPUT
'commit --status with commit.status = no' '
440 clear_config commit.status &&
441 git config commit.status no &&
442 try_commit --status &&
443 grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
446 test_expect_success C_LOCALE_OUTPUT
'commit --no-status with commit.status = no' '
447 clear_config commit.status &&
448 git config commit.status no &&
449 try_commit --no-status &&
450 ! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
455 try_commit_status_combo
457 use_template
="-t template"
459 try_commit_status_combo