]> git.ipfire.org Git - thirdparty/git.git/blob - t/t7502-commit.sh
submodule: fix relative url parsing for scp-style origin
[thirdparty/git.git] / t / t7502-commit.sh
1 #!/bin/sh
2
3 test_description='git commit porcelain-ish'
4
5 . ./test-lib.sh
6
7 test_expect_success 'the basics' '
8
9 echo doing partial >"commit is" &&
10 mkdir not &&
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 &&
15 test_tick &&
16 git commit -a -m "initial with -a" &&
17
18 git cat-file blob HEAD:"commit is" >current.1 &&
19 git cat-file blob HEAD:not/forbid >current.2 &&
20
21 cmp current.1 "commit is" &&
22 cmp current.2 not/forbid
23
24 '
25
26 test_expect_success 'partial' '
27
28 echo another >"commit is" &&
29 echo another >not/forbid &&
30 test_tick &&
31 git commit -m "partial commit to handle a file" "commit is" &&
32
33 changed=$(git diff-tree --name-only HEAD^ HEAD) &&
34 test "$changed" = "commit is"
35
36 '
37
38 test_expect_success 'partial modification in a subdirecotry' '
39
40 test_tick &&
41 git commit -m "partial commit to subdirectory" not &&
42
43 changed=$(git diff-tree -r --name-only HEAD^ HEAD) &&
44 test "$changed" = "not/forbid"
45
46 '
47
48 test_expect_success 'partial removal' '
49
50 git rm not/forbid &&
51 git commit -m "partial commit to remove not/forbid" not &&
52
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"
57
58 '
59
60 test_expect_success 'sign off' '
61
62 >positive &&
63 git add positive &&
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"
68
69 '
70
71 test_expect_success 'multiple -m' '
72
73 >negative &&
74 git add negative &&
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"
79
80 '
81
82 test_expect_success 'verbose' '
83
84 echo minus >negative &&
85 git add 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
89
90 '
91
92 test_expect_success 'verbose respects diff config' '
93
94 git config color.diff always &&
95 git status -v >actual &&
96 grep "\[1mdiff --git" actual &&
97 git config --unset color.diff
98 '
99
100 test_expect_success 'cleanup commit messages (verbatim,-t)' '
101
102 echo >>negative &&
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
107
108 '
109
110 test_expect_success 'cleanup commit messages (verbatim,-F)' '
111
112 echo >>negative &&
113 git commit --cleanup=verbatim -F expect -a &&
114 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
115 test_cmp expect actual
116
117 '
118
119 test_expect_success 'cleanup commit messages (verbatim,-m)' '
120
121 echo >>negative &&
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
125
126 '
127
128 test_expect_success 'cleanup commit messages (whitespace,-F)' '
129
130 echo >>negative &&
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
136
137 '
138
139 test_expect_success 'cleanup commit messages (strip,-F)' '
140
141 echo >>negative &&
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
147
148 '
149
150 echo "sample
151
152 # Please enter the commit message for your changes. Lines starting
153 # with '#' will be ignored, and an empty message aborts the commit." >expect
154
155 test_expect_success 'cleanup commit messages (strip,-F,-e)' '
156
157 echo >>negative &&
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
162
163 '
164
165 echo "#
166 # Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
167 #" >> expect
168
169 test_expect_success 'author different from committer' '
170
171 echo >>negative &&
172 git commit -e -m "sample"
173 head -n 7 .git/COMMIT_EDITMSG >actual &&
174 test_cmp expect actual
175 '
176
177 mv expect expect.tmp
178 sed '$d' < expect.tmp > expect
179 rm -f expect.tmp
180 echo "# Committer:
181 #" >> expect
182
183 test_expect_success 'committer is automatic' '
184
185 echo >>negative &&
186 (
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"
191 ) &&
192 head -n 8 .git/COMMIT_EDITMSG | \
193 sed "s/^# Committer: .*/# Committer:/" >actual &&
194 test_cmp expect actual
195 '
196
197 pwd=`pwd`
198 cat >> .git/FAKE_EDITOR << EOF
199 #! /bin/sh
200 echo editor started > "$pwd/.git/result"
201 exit 0
202 EOF
203 chmod +x .git/FAKE_EDITOR
204
205 test_expect_success 'do not fire editor in the presence of conflicts' '
206
207 git clean -f &&
208 echo f >g &&
209 git add g &&
210 git commit -m "add g" &&
211 git branch second &&
212 echo master >g &&
213 echo g >h &&
214 git add g h &&
215 git commit -m "modify g and add h" &&
216 git checkout second &&
217 echo second >g &&
218 git add g &&
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 &&
223 (
224 GIT_EDITOR="$(pwd)/.git/FAKE_EDITOR" &&
225 export GIT_EDITOR &&
226 test_must_fail git commit
227 ) &&
228 test "$(cat .git/result)" = "editor not started"
229 '
230
231 pwd=`pwd`
232 cat >.git/FAKE_EDITOR <<EOF
233 #! $SHELL_PATH
234 # kill -TERM command added below.
235 EOF
236
237 test_expect_success EXECKEEPSPID 'a SIGTERM should break locks' '
238 echo >>negative &&
239 ! "$SHELL_PATH" -c '\''
240 echo kill -TERM $$ >> .git/FAKE_EDITOR
241 GIT_EDITOR=.git/FAKE_EDITOR
242 export GIT_EDITOR
243 exec git commit -a'\'' &&
244 test ! -f .git/index.lock
245 '
246
247 rm -f .git/MERGE_MSG .git/COMMIT_EDITMSG
248 git reset -q --hard
249
250 test_expect_success 'Hand committing of a redundant merge removes dups' '
251
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
258
259 '
260
261 test_expect_success 'A single-liner subject with a token plus colon is not a footer' '
262
263 git reset --hard &&
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
267
268 '
269
270 cat >.git/FAKE_EDITOR <<EOF
271 #!$SHELL_PATH
272 mv "\$1" "\$1.orig"
273 (
274 echo message
275 cat "\$1.orig"
276 ) >"\$1"
277 EOF
278
279 echo '## Custom template' >template
280
281 clear_config () {
282 (
283 git config --unset-all "$1"
284 case $? in
285 0|5) exit 0 ;;
286 *) exit 1 ;;
287 esac
288 )
289 }
290
291 try_commit () {
292 git reset --hard &&
293 echo >>negative &&
294 GIT_EDITOR=.git/FAKE_EDITOR git commit -a $* $use_template &&
295 case "$use_template" in
296 '')
297 ! grep "^## Custom template" .git/COMMIT_EDITMSG ;;
298 *)
299 grep "^## Custom template" .git/COMMIT_EDITMSG ;;
300 esac
301 }
302
303 try_commit_status_combo () {
304
305 test_expect_success 'commit' '
306 clear_config commit.status &&
307 try_commit "" &&
308 grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
309 '
310
311 test_expect_success 'commit' '
312 clear_config commit.status &&
313 try_commit "" &&
314 grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
315 '
316
317 test_expect_success 'commit --status' '
318 clear_config commit.status &&
319 try_commit --status &&
320 grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
321 '
322
323 test_expect_success 'commit --no-status' '
324 clear_config commit.status &&
325 try_commit --no-status
326 ! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
327 '
328
329 test_expect_success 'commit with commit.status = yes' '
330 clear_config commit.status &&
331 git config commit.status yes &&
332 try_commit "" &&
333 grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
334 '
335
336 test_expect_success 'commit with commit.status = no' '
337 clear_config commit.status &&
338 git config commit.status no &&
339 try_commit "" &&
340 ! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
341 '
342
343 test_expect_success 'commit --status with commit.status = yes' '
344 clear_config commit.status &&
345 git config commit.status yes &&
346 try_commit --status &&
347 grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
348 '
349
350 test_expect_success 'commit --no-status with commit.status = yes' '
351 clear_config commit.status &&
352 git config commit.status yes &&
353 try_commit --no-status &&
354 ! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
355 '
356
357 test_expect_success 'commit --status with commit.status = no' '
358 clear_config commit.status &&
359 git config commit.status no &&
360 try_commit --status &&
361 grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
362 '
363
364 test_expect_success 'commit --no-status with commit.status = no' '
365 clear_config commit.status &&
366 git config commit.status no &&
367 try_commit --no-status &&
368 ! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
369 '
370
371 }
372
373 try_commit_status_combo
374
375 use_template="-t template"
376
377 try_commit_status_combo
378
379 test_done