3 test_description
='git commit porcelain-ish'
7 test_expect_success
'the basics' '
9 echo doing partial >"commit is" &&
11 echo very much encouraged but we should >not/forbid &&
12 git add "commit is" not &&
13 echo update added "commit is" file >"commit is" &&
14 echo also update another >not/forbid &&
16 git commit -a -m "initial with -a" &&
18 git cat-file blob HEAD:"commit is" >current.1 &&
19 git cat-file blob HEAD:not/forbid >current.2 &&
21 cmp current.1 "commit is" &&
22 cmp current.2 not/forbid
26 test_expect_success
'partial' '
28 echo another >"commit is" &&
29 echo another >not/forbid &&
31 git commit -m "partial commit to handle a file" "commit is" &&
33 changed=$(git diff-tree --name-only HEAD^ HEAD) &&
34 test "$changed" = "commit is"
38 test_expect_success
'partial modification in a subdirecotry' '
41 git commit -m "partial commit to subdirectory" not &&
43 changed=$(git diff-tree -r --name-only HEAD^ HEAD) &&
44 test "$changed" = "not/forbid"
48 test_expect_success
'partial removal' '
51 git commit -m "partial commit to remove not/forbid" not &&
53 changed=$(git diff-tree -r --name-only HEAD^ HEAD) &&
54 test "$changed" = "not/forbid" &&
55 remain=$(git ls-tree -r --name-only HEAD) &&
56 test "$remain" = "commit is"
60 test_expect_success
'sign off' '
64 git commit -s -m "thank you" &&
65 actual=$(git cat-file commit HEAD | sed -ne "s/Signed-off-by: //p") &&
66 expected=$(git var GIT_COMMITTER_IDENT | sed -e "s/>.*/>/") &&
67 test "z$actual" = "z$expected"
71 test_expect_success
'multiple -m' '
75 git commit -m "one" -m "two" -m "three" &&
76 actual=$(git cat-file commit HEAD | sed -e "1,/^\$/d") &&
77 expected=$(echo one; echo; echo two; echo; echo three) &&
78 test "z$actual" = "z$expected"
82 test_expect_success
'verbose' '
84 echo minus >negative &&
86 git status -v | sed -ne "/^diff --git /p" >actual &&
87 echo "diff --git a/negative b/negative" >expect &&
88 test_cmp expect actual
92 test_expect_success
'verbose respects diff config' '
94 git config color.diff always &&
95 git status -v >actual &&
96 grep "\[1mdiff --git" actual &&
97 git config --unset color.diff
100 test_expect_success
'cleanup commit messages (verbatim,-t)' '
103 { echo;echo "# text";echo; } >expect &&
104 git commit --cleanup=verbatim -t expect -a &&
105 git cat-file -p HEAD |sed -e "1,/^\$/d" |head -n 3 >actual &&
106 test_cmp expect actual
110 test_expect_success
'cleanup commit messages (verbatim,-F)' '
113 git commit --cleanup=verbatim -F expect -a &&
114 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
115 test_cmp expect actual
119 test_expect_success
'cleanup commit messages (verbatim,-m)' '
122 git commit --cleanup=verbatim -m "$(cat expect)" -a &&
123 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
124 test_cmp expect actual
128 test_expect_success
'cleanup commit messages (whitespace,-F)' '
131 { echo;echo "# text";echo; } >text &&
132 echo "# text" >expect &&
133 git commit --cleanup=whitespace -F text -a &&
134 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
135 test_cmp expect actual
139 test_expect_success
'cleanup commit messages (strip,-F)' '
142 { echo;echo "# text";echo sample;echo; } >text &&
143 echo sample >expect &&
144 git commit --cleanup=strip -F text -a &&
145 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
146 test_cmp expect actual
152 # Please enter the commit message for your changes. Lines starting
153 # with '#' will be ignored, and an empty message aborts the commit." >expect
155 test_expect_success
'cleanup commit messages (strip,-F,-e)' '
158 { echo;echo sample;echo; } >text &&
159 git commit -e -F text -a &&
160 head -n 4 .git/COMMIT_EDITMSG >actual &&
161 test_cmp expect actual
166 # Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
169 test_expect_success
'author different from committer' '
172 git commit -e -m "sample"
173 head -n 7 .git/COMMIT_EDITMSG >actual &&
174 test_cmp expect actual
178 sed '$d' < expect.tmp
> expect
183 test_expect_success
'committer is automatic' '
187 unset GIT_COMMITTER_EMAIL
188 unset GIT_COMMITTER_NAME
189 # must fail because there is no change
190 test_must_fail git commit -e -m "sample"
192 head -n 8 .git/COMMIT_EDITMSG | \
193 sed "s/^# Committer: .*/# Committer:/" >actual &&
194 test_cmp expect actual
198 cat >> .git
/FAKE_EDITOR
<< EOF
200 echo editor started > "$pwd/.git/result"
203 chmod +x .git
/FAKE_EDITOR
205 test_expect_success
'do not fire editor in the presence of conflicts' '
210 git commit -m "add g" &&
215 git commit -m "modify g and add h" &&
216 git checkout second &&
219 git commit -m second &&
220 # Must fail due to conflict
221 test_must_fail git cherry-pick -n master &&
222 echo "editor not started" >.git/result &&
224 GIT_EDITOR="$(pwd)/.git/FAKE_EDITOR" &&
226 test_must_fail git commit
228 test "$(cat .git/result)" = "editor not started"
232 cat >.git
/FAKE_EDITOR
<<EOF
234 # kill -TERM command added below.
237 test_expect_success EXECKEEPSPID
'a SIGTERM should break locks' '
239 ! "$SHELL_PATH" -c '\''
240 echo kill -TERM $$ >> .git/FAKE_EDITOR
241 GIT_EDITOR=.git/FAKE_EDITOR
243 exec git commit -a'\'' &&
244 test ! -f .git/index.lock
247 rm -f .git
/MERGE_MSG .git
/COMMIT_EDITMSG
250 test_expect_success
'Hand committing of a redundant merge removes dups' '
252 git rev-parse second master >expect &&
253 test_must_fail git merge second master &&
254 git checkout master g &&
255 EDITOR=: git commit -a &&
256 git cat-file commit HEAD | sed -n -e "s/^parent //p" -e "/^$/q" >actual &&
257 test_cmp expect actual
261 test_expect_success
'A single-liner subject with a token plus colon is not a footer' '
264 git commit -s -m "hello: kitty" --allow-empty &&
265 git cat-file commit HEAD | sed -e "1,/^$/d" >actual &&
266 test $(wc -l <actual) = 3