2007-07-23 06:17:42 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2007 Steven Grimm
|
|
|
|
#
|
|
|
|
|
2008-09-03 10:59:33 +02:00
|
|
|
test_description='git commit
|
2007-07-23 06:17:42 +02:00
|
|
|
|
|
|
|
Tests for selected commit options.'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
commit_msg_is () {
|
|
|
|
test "`git log --pretty=format:%s%b -1`" = "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
# A sanity check to see if commit is working at all.
|
|
|
|
test_expect_success 'a basic commit in an empty tree should succeed' '
|
|
|
|
echo content > foo &&
|
|
|
|
git add foo &&
|
|
|
|
git commit -m "initial commit"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'nonexistent template file should return error' '
|
|
|
|
echo changes >> foo &&
|
|
|
|
git add foo &&
|
2008-07-12 17:47:52 +02:00
|
|
|
test_must_fail git commit --template "$PWD"/notexist
|
2007-07-23 06:17:42 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'nonexistent template file in config should return error' '
|
|
|
|
git config commit.template "$PWD"/notexist &&
|
2008-07-12 17:47:52 +02:00
|
|
|
test_must_fail git commit &&
|
2007-07-23 06:17:42 +02:00
|
|
|
git config --unset commit.template
|
|
|
|
'
|
|
|
|
|
|
|
|
# From now on we'll use a template file that exists.
|
|
|
|
TEMPLATE="$PWD"/template
|
|
|
|
|
|
|
|
test_expect_success 'unedited template should not commit' '
|
|
|
|
echo "template line" > "$TEMPLATE" &&
|
2008-07-12 17:47:52 +02:00
|
|
|
test_must_fail git commit --template "$TEMPLATE"
|
2007-07-23 06:17:42 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'unedited template with comments should not commit' '
|
|
|
|
echo "# comment in template" >> "$TEMPLATE" &&
|
2008-07-12 17:47:52 +02:00
|
|
|
test_must_fail git commit --template "$TEMPLATE"
|
2007-07-23 06:17:42 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'a Signed-off-by line by itself should not commit' '
|
2008-08-08 11:26:28 +02:00
|
|
|
(
|
|
|
|
test_set_editor "$TEST_DIRECTORY"/t7500/add-signed-off &&
|
|
|
|
test_must_fail git commit --template "$TEMPLATE"
|
|
|
|
)
|
2007-07-23 06:17:42 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'adding comments to a template should not commit' '
|
2008-08-08 11:26:28 +02:00
|
|
|
(
|
|
|
|
test_set_editor "$TEST_DIRECTORY"/t7500/add-comments &&
|
|
|
|
test_must_fail git commit --template "$TEMPLATE"
|
|
|
|
)
|
2007-07-23 06:17:42 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'adding real content to a template should commit' '
|
2008-08-08 11:26:28 +02:00
|
|
|
(
|
|
|
|
test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
|
|
|
|
git commit --template "$TEMPLATE"
|
|
|
|
) &&
|
2007-07-23 06:17:42 +02:00
|
|
|
commit_msg_is "template linecommit message"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '-t option should be short for --template' '
|
|
|
|
echo "short template" > "$TEMPLATE" &&
|
|
|
|
echo "new content" >> foo &&
|
|
|
|
git add foo &&
|
2008-08-08 11:26:28 +02:00
|
|
|
(
|
|
|
|
test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
|
|
|
|
git commit -t "$TEMPLATE"
|
|
|
|
) &&
|
2007-07-23 06:17:42 +02:00
|
|
|
commit_msg_is "short templatecommit message"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'config-specified template should commit' '
|
|
|
|
echo "new template" > "$TEMPLATE" &&
|
|
|
|
git config commit.template "$TEMPLATE" &&
|
|
|
|
echo "more content" >> foo &&
|
|
|
|
git add foo &&
|
2008-08-08 11:26:28 +02:00
|
|
|
(
|
|
|
|
test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
|
|
|
|
git commit
|
|
|
|
) &&
|
2007-07-23 06:17:42 +02:00
|
|
|
git config --unset commit.template &&
|
|
|
|
commit_msg_is "new templatecommit message"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'explicit commit message should override template' '
|
|
|
|
echo "still more content" >> foo &&
|
|
|
|
git add foo &&
|
2008-08-08 11:26:28 +02:00
|
|
|
GIT_EDITOR="$TEST_DIRECTORY"/t7500/add-content git commit --template "$TEMPLATE" \
|
2007-07-23 06:17:42 +02:00
|
|
|
-m "command line msg" &&
|
2007-09-25 16:38:46 +02:00
|
|
|
commit_msg_is "command line msg"
|
2007-07-23 06:17:42 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'commit message from file should override template' '
|
|
|
|
echo "content galore" >> foo &&
|
|
|
|
git add foo &&
|
|
|
|
echo "standard input msg" |
|
2008-08-08 11:26:28 +02:00
|
|
|
(
|
|
|
|
test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
|
|
|
|
git commit --template "$TEMPLATE" --file -
|
|
|
|
) &&
|
2007-09-25 16:38:46 +02:00
|
|
|
commit_msg_is "standard input msg"
|
2007-07-23 06:17:42 +02:00
|
|
|
'
|
|
|
|
|
2007-11-11 13:28:08 +01:00
|
|
|
test_expect_success 'using alternate GIT_INDEX_FILE (1)' '
|
|
|
|
|
|
|
|
cp .git/index saved-index &&
|
|
|
|
(
|
|
|
|
echo some new content >file &&
|
|
|
|
GIT_INDEX_FILE=.git/another_index &&
|
|
|
|
export GIT_INDEX_FILE &&
|
|
|
|
git add file &&
|
|
|
|
git commit -m "commit using another index" &&
|
|
|
|
git diff-index --exit-code HEAD &&
|
|
|
|
git diff-files --exit-code
|
|
|
|
) &&
|
|
|
|
cmp .git/index saved-index >/dev/null
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'using alternate GIT_INDEX_FILE (2)' '
|
|
|
|
|
|
|
|
cp .git/index saved-index &&
|
|
|
|
(
|
|
|
|
rm -f .git/no-such-index &&
|
|
|
|
GIT_INDEX_FILE=.git/no-such-index &&
|
|
|
|
export GIT_INDEX_FILE &&
|
|
|
|
git commit -m "commit using nonexistent index" &&
|
|
|
|
test -z "$(git ls-files)" &&
|
|
|
|
test -z "$(git ls-tree HEAD)"
|
|
|
|
|
|
|
|
) &&
|
|
|
|
cmp .git/index saved-index >/dev/null
|
2007-11-11 18:35:58 +01:00
|
|
|
'
|
2007-11-11 13:28:08 +01:00
|
|
|
|
2007-11-11 18:35:58 +01:00
|
|
|
cat > expect << EOF
|
|
|
|
zort
|
2007-11-11 18:36:27 +01:00
|
|
|
|
2007-11-11 18:35:58 +01:00
|
|
|
Signed-off-by: C O Mitter <committer@example.com>
|
|
|
|
EOF
|
|
|
|
|
|
|
|
test_expect_success '--signoff' '
|
|
|
|
echo "yet another content *narf*" >> foo &&
|
2009-01-09 18:30:05 +01:00
|
|
|
echo "zort" | git commit -s -F - foo &&
|
2007-11-11 18:35:58 +01:00
|
|
|
git cat-file commit HEAD | sed "1,/^$/d" > output &&
|
2008-08-08 11:26:28 +02:00
|
|
|
test_cmp expect output
|
2007-11-11 13:28:08 +01:00
|
|
|
'
|
|
|
|
|
2008-08-06 20:43:47 +02:00
|
|
|
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"
|
|
|
|
'
|
|
|
|
|
2007-07-23 06:17:42 +02:00
|
|
|
test_done
|