]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t7500-commit.sh
tests: use $TEST_DIRECTORY to refer to the t/ directory
[thirdparty/git.git] / t / t7500-commit.sh
index 26bd8ee469ad5bad5e4e9700c490cb3e3cb73b83..7ae0bd0e31f70271a18935be2ac1a929b5cda1bf 100755 (executable)
@@ -23,12 +23,12 @@ test_expect_success 'a basic commit in an empty tree should succeed' '
 test_expect_success 'nonexistent template file should return error' '
        echo changes >> foo &&
        git add foo &&
-       ! git commit --template "$PWD"/notexist
+       test_must_fail git commit --template "$PWD"/notexist
 '
 
 test_expect_success 'nonexistent template file in config should return error' '
        git config commit.template "$PWD"/notexist &&
-       ! git commit &&
+       test_must_fail git commit &&
        git config --unset commit.template
 '
 
@@ -37,24 +37,33 @@ TEMPLATE="$PWD"/template
 
 test_expect_success 'unedited template should not commit' '
        echo "template line" > "$TEMPLATE" &&
-       ! git commit --template "$TEMPLATE"
+       test_must_fail git commit --template "$TEMPLATE"
 '
 
 test_expect_success 'unedited template with comments should not commit' '
        echo "# comment in template" >> "$TEMPLATE" &&
-       ! git commit --template "$TEMPLATE"
+       test_must_fail git commit --template "$TEMPLATE"
 '
 
 test_expect_success 'a Signed-off-by line by itself should not commit' '
-       ! GIT_EDITOR=../t7500/add-signed-off git commit --template "$TEMPLATE"
+       (
+               test_set_editor "$TEST_DIRECTORY"/t7500/add-signed-off &&
+               test_must_fail git commit --template "$TEMPLATE"
+       )
 '
 
 test_expect_success 'adding comments to a template should not commit' '
-       ! GIT_EDITOR=../t7500/add-comments git commit --template "$TEMPLATE"
+       (
+               test_set_editor "$TEST_DIRECTORY"/t7500/add-comments &&
+               test_must_fail git commit --template "$TEMPLATE"
+       )
 '
 
 test_expect_success 'adding real content to a template should commit' '
-       GIT_EDITOR=../t7500/add-content git commit --template "$TEMPLATE" &&
+       (
+               test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
+               git commit --template "$TEMPLATE"
+       ) &&
        commit_msg_is "template linecommit message"
 '
 
@@ -62,7 +71,10 @@ test_expect_success '-t option should be short for --template' '
        echo "short template" > "$TEMPLATE" &&
        echo "new content" >> foo &&
        git add foo &&
-       GIT_EDITOR=../t7500/add-content git commit -t "$TEMPLATE" &&
+       (
+               test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
+               git commit -t "$TEMPLATE"
+       ) &&
        commit_msg_is "short templatecommit message"
 '
 
@@ -71,7 +83,10 @@ test_expect_success 'config-specified template should commit' '
        git config commit.template "$TEMPLATE" &&
        echo "more content" >> foo &&
        git add foo &&
-       GIT_EDITOR=../t7500/add-content git commit &&
+       (
+               test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
+               git commit
+       ) &&
        git config --unset commit.template &&
        commit_msg_is "new templatecommit message"
 '
@@ -79,18 +94,20 @@ test_expect_success 'config-specified template should commit' '
 test_expect_success 'explicit commit message should override template' '
        echo "still more content" >> foo &&
        git add foo &&
-       GIT_EDITOR=../t7500/add-content git commit --template "$TEMPLATE" \
+       GIT_EDITOR="$TEST_DIRECTORY"/t7500/add-content git commit --template "$TEMPLATE" \
                -m "command line msg" &&
-       commit_msg_is "command line msg<unknown>"
+       commit_msg_is "command line msg"
 '
 
 test_expect_success 'commit message from file should override template' '
        echo "content galore" >> foo &&
        git add foo &&
        echo "standard input msg" |
-               GIT_EDITOR=../t7500/add-content git commit \
-                       --template "$TEMPLATE" --file - &&
-       commit_msg_is "standard input msg<unknown>"
+       (
+               test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
+               git commit --template "$TEMPLATE" --file -
+       ) &&
+       commit_msg_is "standard input msg"
 '
 
 test_expect_success 'using alternate GIT_INDEX_FILE (1)' '
@@ -122,7 +139,51 @@ test_expect_success 'using alternate GIT_INDEX_FILE (2)' '
 
        ) &&
        cmp .git/index saved-index >/dev/null
+'
+
+cat > expect << EOF
+zort
+
+Signed-off-by: C O Mitter <committer@example.com>
+EOF
 
+test_expect_success '--signoff' '
+       echo "yet another content *narf*" >> foo &&
+       echo "zort" | (
+               test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
+               git commit -s -F - foo
+       ) &&
+       git cat-file commit HEAD | sed "1,/^$/d" > output &&
+       test_cmp expect output
+'
+
+test_expect_success 'commit message from file (1)' '
+       mkdir subdir &&
+       echo "Log in top directory" >log &&
+       echo "Log in sub directory" >subdir/log &&
+       (
+               cd subdir &&
+               git commit --allow-empty -F log
+       ) &&
+       commit_msg_is "Log in sub directory"
+'
+
+test_expect_success 'commit message from file (2)' '
+       rm -f log &&
+       echo "Log in sub directory" >subdir/log &&
+       (
+               cd subdir &&
+               git commit --allow-empty -F log
+       ) &&
+       commit_msg_is "Log in sub directory"
+'
+
+test_expect_success 'commit message from stdin' '
+       (
+               cd subdir &&
+               echo "Log with foo word" | git commit --allow-empty -F -
+       ) &&
+       commit_msg_is "Log with foo word"
 '
 
 test_done