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 &&
38 test_expect_success 'output summary format: root-commit' '
39 check_summary_oneline "" "a change"
42 test_expect_success 'output summary format for commit with an empty diff' '
44 check_summary_oneline "" "empty" "--allow-empty"
47 test_expect_success 'output summary format for merges' '
49 git checkout -b recursive-base &&
50 test_commit base file1 &&
52 git checkout -b recursive-a recursive-base &&
53 test_commit commit-a file1 &&
55 git checkout -b recursive-b recursive-base &&
56 test_commit commit-b file1 &&
59 git checkout recursive-a &&
60 test_must_fail git merge recursive-b &&
61 # resolve the conflict
62 echo commit-a > file1 &&
64 check_summary_oneline "" "Merge"
67 output_tests_cleanup() {
68 # this is needed for "do not fire editor in the presence of conflicts"
69 git checkout master &&
71 # this is needed for the "partial removal" test to pass
73 git commit -m "cleanup"
76 test_expect_success 'the basics' '
78 output_tests_cleanup &&
80 echo doing partial >"commit is" &&
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 &&
87 git commit -a -m "initial with -a" &&
89 git cat-file blob HEAD:"commit is" >current.1 &&
90 git cat-file blob HEAD:not/forbid >current.2 &&
92 cmp current.1 "commit is" &&
93 cmp current.2 not/forbid
97 test_expect_success 'partial' '
99 echo another >"commit is" &&
100 echo another >not/forbid &&
102 git commit -m "partial commit to handle a file" "commit is" &&
104 changed=$(git diff-tree --name-only HEAD^ HEAD) &&
105 test "$changed" = "commit is"
109 test_expect_success 'partial modification in a subdirectory' '
112 git commit -m "partial commit to subdirectory" not &&
114 changed=$(git diff-tree -r --name-only HEAD^ HEAD) &&
115 test "$changed" = "not/forbid"
119 test_expect_success 'partial removal' '
122 git commit -m "partial commit to remove not/forbid" not &&
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"
131 test_expect_success 'sign off' '
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"
142 test_expect_success 'multiple -m' '
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"
153 test_expect_success 'verbose' '
155 echo minus >negative &&
157 git status -v | sed -ne "/^diff --git /p" >actual &&
158 echo "diff --git a/negative b/negative" >expect &&
159 test_cmp expect actual
163 test_expect_success 'verbose respects diff config' '
165 git config color.diff always &&
166 git status -v >actual &&
167 grep "\[1mdiff --git" actual &&
168 git config --unset color.diff
171 test_expect_success 'cleanup commit messages (verbatim,-t)' '
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 &&
177 test_cmp expect actual
181 test_expect_success 'cleanup commit messages (verbatim,-F)' '
184 git commit --cleanup=verbatim -F expect -a &&
185 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
186 test_cmp expect actual
190 test_expect_success 'cleanup commit messages (verbatim,-m)' '
193 git commit --cleanup=verbatim -m "$(cat expect)" -a &&
194 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
195 test_cmp expect actual
199 test_expect_success 'cleanup commit messages (whitespace,-F)' '
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 &&
206 test_cmp expect actual
210 test_expect_success 'cleanup commit messages (strip,-F)' '
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 &&
217 test_cmp expect actual
221 test_expect_success 'cleanup commit messages (strip,-F,-e)' '
224 { echo;echo sample;echo; } >text &&
225 git commit -e -F text -a &&
226 head -n 4 .git/COMMIT_EDITMSG >actual
231 # Please enter the commit message for your changes. Lines starting
232 # with '#' will be ignored, and an empty message aborts the commit." >expect
234 test_expect_success 'cleanup commit messages (strip,-F,-e): output' '
235 test_i18ncmp expect actual
239 # Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
242 test_expect_success 'author different from committer' '
244 test_might_fail git commit -e -m "sample" &&
245 head -n 7 .git/COMMIT_EDITMSG >actual &&
246 test_i18ncmp expect actual
250 sed '$d' < expect.tmp > expect
255 test_expect_success 'committer is automatic' '
259 sane_unset GIT_COMMITTER_EMAIL &&
260 sane_unset GIT_COMMITTER_NAME &&
261 # must fail because there is no change
262 test_must_fail git commit -e -m "sample"
264 head -n 8 .git/COMMIT_EDITMSG | \
265 sed "s/^# Committer: .*/# Committer:/" >actual
266 test_i18ncmp expect actual
270 cat >> .git/FAKE_EDITOR << EOF
272 echo editor started > "$pwd/.git/result"
275 chmod +x .git/FAKE_EDITOR
277 test_expect_success 'do not fire editor in the presence of conflicts' '
282 git commit -m "add g" &&
287 git commit -m "modify g and add h" &&
288 git checkout second &&
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 &&
296 GIT_EDITOR="$(pwd)/.git/FAKE_EDITOR" &&
298 test_must_fail git commit
300 test "$(cat .git/result)" = "editor not started"
304 cat >.git/FAKE_EDITOR <<EOF
306 # kill -TERM command added below.
309 test_expect_success EXECKEEPSPID 'a SIGTERM should break locks' '
311 ! "$SHELL_PATH" -c '\''
312 echo kill -TERM $$ >> .git/FAKE_EDITOR
313 GIT_EDITOR=.git/FAKE_EDITOR
315 exec git commit -a'\'' &&
316 test ! -f .git/index.lock
319 rm -f .git/MERGE_MSG .git/COMMIT_EDITMSG
322 test_expect_success 'Hand committing of a redundant merge removes dups' '
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
333 test_expect_success 'A single-liner subject with a token plus colon is not a footer' '
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
342 cat >.git/FAKE_EDITOR <<EOF
351 echo '## Custom template' >template
355 git config --unset-all "$1"
366 GIT_EDITOR=.git/FAKE_EDITOR git commit -a $* $use_template &&
367 case "$use_template" in
369 test_i18ngrep ! "^## Custom template" .git/COMMIT_EDITMSG ;;
371 test_i18ngrep "^## Custom template" .git/COMMIT_EDITMSG ;;
375 try_commit_status_combo () {
377 test_expect_success 'commit' '
378 clear_config commit.status &&
380 test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG
383 test_expect_success 'commit' '
384 clear_config commit.status &&
386 test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG
389 test_expect_success 'commit --status' '
390 clear_config commit.status &&
391 try_commit --status &&
392 test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG
395 test_expect_success 'commit --no-status' '
396 clear_config commit.status &&
397 try_commit --no-status &&
398 test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG
401 test_expect_success 'commit with commit.status = yes' '
402 clear_config commit.status &&
403 git config commit.status yes &&
405 test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG
408 test_expect_success 'commit with commit.status = no' '
409 clear_config commit.status &&
410 git config commit.status no &&
412 test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG
415 test_expect_success 'commit --status with commit.status = yes' '
416 clear_config commit.status &&
417 git config commit.status yes &&
418 try_commit --status &&
419 test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG
422 test_expect_success 'commit --no-status with commit.status = yes' '
423 clear_config commit.status &&
424 git config commit.status yes &&
425 try_commit --no-status &&
426 test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG
429 test_expect_success 'commit --status with commit.status = no' '
430 clear_config commit.status &&
431 git config commit.status no &&
432 try_commit --status &&
433 test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG
436 test_expect_success 'commit --no-status with commit.status = no' '
437 clear_config commit.status &&
438 git config commit.status no &&
439 try_commit --no-status &&
440 test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG
445 try_commit_status_combo
447 use_template="-t template"
449 try_commit_status_combo