3 # Copyright (c) 2007 Steven Grimm
6 test_description='git-commit
8 Tests for selected commit options.'
13 test "`git log --pretty=format:%s%b -1`" = "$1"
16 # A sanity check to see if commit is working at all.
17 test_expect_success 'a basic commit in an empty tree should succeed' '
20 git commit -m "initial commit"
23 test_expect_success 'nonexistent template file should return error' '
24 echo changes >> foo &&
26 test_must_fail git commit --template "$PWD"/notexist
29 test_expect_success 'nonexistent template file in config should return error' '
30 git config commit.template "$PWD"/notexist &&
31 test_must_fail git commit &&
32 git config --unset commit.template
35 # From now on we'll use a template file that exists.
36 TEMPLATE="$PWD"/template
38 test_expect_success 'unedited template should not commit' '
39 echo "template line" > "$TEMPLATE" &&
40 test_must_fail git commit --template "$TEMPLATE"
43 test_expect_success 'unedited template with comments should not commit' '
44 echo "# comment in template" >> "$TEMPLATE" &&
45 test_must_fail git commit --template "$TEMPLATE"
48 test_expect_success 'a Signed-off-by line by itself should not commit' '
50 test_set_editor "$TEST_DIRECTORY"/t7500/add-signed-off &&
51 test_must_fail git commit --template "$TEMPLATE"
55 test_expect_success 'adding comments to a template should not commit' '
57 test_set_editor "$TEST_DIRECTORY"/t7500/add-comments &&
58 test_must_fail git commit --template "$TEMPLATE"
62 test_expect_success 'adding real content to a template should commit' '
64 test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
65 git commit --template "$TEMPLATE"
67 commit_msg_is "template linecommit message"
70 test_expect_success '-t option should be short for --template' '
71 echo "short template" > "$TEMPLATE" &&
72 echo "new content" >> foo &&
75 test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
76 git commit -t "$TEMPLATE"
78 commit_msg_is "short templatecommit message"
81 test_expect_success 'config-specified template should commit' '
82 echo "new template" > "$TEMPLATE" &&
83 git config commit.template "$TEMPLATE" &&
84 echo "more content" >> foo &&
87 test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
90 git config --unset commit.template &&
91 commit_msg_is "new templatecommit message"
94 test_expect_success 'explicit commit message should override template' '
95 echo "still more content" >> foo &&
97 GIT_EDITOR="$TEST_DIRECTORY"/t7500/add-content git commit --template "$TEMPLATE" \
98 -m "command line msg" &&
99 commit_msg_is "command line msg"
102 test_expect_success 'commit message from file should override template' '
103 echo "content galore" >> foo &&
105 echo "standard input msg" |
107 test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
108 git commit --template "$TEMPLATE" --file -
110 commit_msg_is "standard input msg"
113 test_expect_success 'using alternate GIT_INDEX_FILE (1)' '
115 cp .git/index saved-index &&
117 echo some new content >file &&
118 GIT_INDEX_FILE=.git/another_index &&
119 export GIT_INDEX_FILE &&
121 git commit -m "commit using another index" &&
122 git diff-index --exit-code HEAD &&
123 git diff-files --exit-code
125 cmp .git/index saved-index >/dev/null
129 test_expect_success 'using alternate GIT_INDEX_FILE (2)' '
131 cp .git/index saved-index &&
133 rm -f .git/no-such-index &&
134 GIT_INDEX_FILE=.git/no-such-index &&
135 export GIT_INDEX_FILE &&
136 git commit -m "commit using nonexistent index" &&
137 test -z "$(git ls-files)" &&
138 test -z "$(git ls-tree HEAD)"
141 cmp .git/index saved-index >/dev/null
147 Signed-off-by: C O Mitter <committer@example.com>
150 test_expect_success '--signoff' '
151 echo "yet another content *narf*" >> foo &&
153 test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
154 git commit -s -F - foo
156 git cat-file commit HEAD | sed "1,/^$/d" > output &&
157 test_cmp expect output
160 test_expect_success 'commit message from file (1)' '
162 echo "Log in top directory" >log &&
163 echo "Log in sub directory" >subdir/log &&
166 git commit --allow-empty -F log
168 commit_msg_is "Log in sub directory"
171 test_expect_success 'commit message from file (2)' '
173 echo "Log in sub directory" >subdir/log &&
176 git commit --allow-empty -F log
178 commit_msg_is "Log in sub directory"
181 test_expect_success 'commit message from stdin' '
184 echo "Log with foo word" | git commit --allow-empty -F -
186 commit_msg_is "Log with foo word"