test prerequisites: eradicate NOT_FOO
[gitweb.git] / t / t7502-commit.sh
index b0ae7059367fdb50dfc04fe87ae69e03abbb03bd..051489ea334c9693c2d19823ad23947703f66d90 100755 (executable)
@@ -176,12 +176,20 @@ test_expect_success 'verbose respects diff config' '
        grep "\[1mdiff --git" actual
 '
 
+mesg_with_comment_and_newlines='
+# text
+
+'
+
+test_expect_success 'prepare file with comment line and trailing newlines'  '
+       printf "%s" "$mesg_with_comment_and_newlines" >expect
+'
+
 test_expect_success 'cleanup commit messages (verbatim option,-t)' '
 
        echo >>negative &&
-       { echo;echo "# text";echo; } >expect &&
-       git commit --cleanup=verbatim -t expect -a &&
-       git cat-file -p HEAD |sed -e "1,/^\$/d" |head -n 3 >actual &&
+       git commit --cleanup=verbatim --no-status -t expect -a &&
+       git cat-file -p HEAD |sed -e "1,/^\$/d" >actual &&
        test_cmp expect actual
 
 '
@@ -198,7 +206,7 @@ test_expect_success 'cleanup commit messages (verbatim option,-F)' '
 test_expect_success 'cleanup commit messages (verbatim option,-m)' '
 
        echo >>negative &&
-       git commit --cleanup=verbatim -m "$(cat expect)" -a &&
+       git commit --cleanup=verbatim -m "$mesg_with_comment_and_newlines" -a &&
        git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
        test_cmp expect actual
 
@@ -215,6 +223,22 @@ test_expect_success 'cleanup commit messages (whitespace option,-F)' '
 
 '
 
+test_expect_success 'cleanup commit messages (scissors option,-F,-e)' '
+
+       echo >>negative &&
+       cat >text <<EOF &&
+
+# to be kept
+# ------------------------ >8 ------------------------
+to be removed
+EOF
+       echo "# to be kept" >expect &&
+       git commit --cleanup=scissors -e -F text -a &&
+       git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
+       test_cmp expect actual
+
+'
+
 test_expect_success 'cleanup commit messages (strip option,-F)' '
 
        echo >>negative &&
@@ -254,32 +278,40 @@ test_expect_success 'cleanup commit message (fail on invalid cleanup mode config
 test_expect_success 'cleanup commit message (no config and no option uses default)' '
        echo content >>file &&
        git add file &&
-       test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
-       git commit --no-status &&
+       (
+         test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
+         git commit --no-status
+       ) &&
        commit_msg_is "commit message"
 '
 
 test_expect_success 'cleanup commit message (option overrides default)' '
        echo content >>file &&
        git add file &&
-       test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
-       git commit --cleanup=whitespace --no-status &&
+       (
+         test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
+         git commit --cleanup=whitespace --no-status
+       ) &&
        commit_msg_is "commit message # comment"
 '
 
 test_expect_success 'cleanup commit message (config overrides default)' '
        echo content >>file &&
        git add file &&
-       test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
-       git -c commit.cleanup=whitespace commit --no-status &&
+       (
+         test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
+         git -c commit.cleanup=whitespace commit --no-status
+       ) &&
        commit_msg_is "commit message # comment"
 '
 
 test_expect_success 'cleanup commit message (option overrides config)' '
        echo content >>file &&
        git add file &&
-       test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
-       git -c commit.cleanup=whitespace commit --cleanup=default &&
+       (
+         test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
+         git -c commit.cleanup=whitespace commit --cleanup=default
+       ) &&
        commit_msg_is "commit message"
 '
 
@@ -312,6 +344,13 @@ test_expect_success 'message shows author when it is not equal to committer' '
          .git/COMMIT_EDITMSG
 '
 
+test_expect_success 'message shows date when it is explicitly set' '
+       git commit --allow-empty -e -m foo --date="2010-01-02T03:04:05" &&
+       test_i18ngrep \
+         "^# Date: *Sat Jan 2 03:04:05 2010 +0000" \
+         .git/COMMIT_EDITMSG
+'
+
 test_expect_success AUTOIDENT 'message shows committer when it is automatic' '
 
        echo >>negative &&
@@ -345,6 +384,23 @@ test_expect_success !AUTOIDENT 'do not fire editor when committer is bogus' '
        test_cmp expect .git/result
 '
 
+test_expect_success 'do not fire editor if -m <msg> was given' '
+       echo tick >file &&
+       git add file &&
+       echo "editor not started" >.git/result &&
+       (GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" git commit -m tick) &&
+       test "$(cat .git/result)" = "editor not started"
+'
+
+test_expect_success 'do not fire editor if -m "" was given' '
+       echo tock >file &&
+       git add file &&
+       echo "editor not started" >.git/result &&
+       (GIT_EDITOR="\"$(pwd)/.git/FAKE_EDITOR\"" \
+        git commit -m "" --allow-empty-message) &&
+       test "$(cat .git/result)" = "editor not started"
+'
+
 test_expect_success 'do not fire editor in the presence of conflicts' '
 
        git clean -f &&
@@ -408,6 +464,18 @@ test_expect_success 'A single-liner subject with a token plus colon is not a foo
 
 '
 
+test_expect_success 'commit -s places sob on third line after two empty lines' '
+       git commit -s --allow-empty --allow-empty-message &&
+       cat <<-EOF >expect &&
+
+
+       Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
+
+       EOF
+       sed -e "/^#/d" -e "s/^:.*//" .git/COMMIT_EDITMSG >actual &&
+       test_cmp expect actual
+'
+
 write_script .git/FAKE_EDITOR <<\EOF
 mv "$1" "$1.orig"
 (
@@ -502,4 +570,30 @@ test_expect_success 'commit --status with custom comment character' '
        test_i18ngrep "^; Changes to be committed:" .git/COMMIT_EDITMSG
 '
 
+test_expect_success 'switch core.commentchar' '
+       test_commit "#foo" foo &&
+       GIT_EDITOR=.git/FAKE_EDITOR git -c core.commentChar=auto commit --amend &&
+       test_i18ngrep "^; Changes to be committed:" .git/COMMIT_EDITMSG
+'
+
+test_expect_success 'switch core.commentchar but out of options' '
+       cat >text <<\EOF &&
+# 1
+; 2
+@ 3
+! 4
+$ 5
+% 6
+^ 7
+& 8
+| 9
+: 10
+EOF
+       git commit --amend -F text &&
+       (
+               test_set_editor .git/FAKE_EDITOR &&
+               test_must_fail git -c core.commentChar=auto commit --amend
+       )
+'
+
 test_done