]>
Commit | Line | Data |
---|---|---|
a3e870f2 | 1 | #!/bin/sh |
5fec3ef1 JH |
2 | # |
3 | # Copyright (c) 2005 Linus Torvalds | |
130fcca6 JH |
4 | # Copyright (c) 2006 Junio C Hamano |
5 | ||
6cbf07ef | 6 | USAGE='[-a | --interactive] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit> | --amend] [-u] [-e] [--author <author>] [[-i | -o] <path>...]' |
130fcca6 | 7 | SUBDIRECTORY_OK=Yes |
ae2b0f15 | 8 | . git-sh-setup |
7eff28a9 | 9 | require_work_tree |
b33e9666 | 10 | |
cf7bb589 | 11 | git-rev-parse --verify HEAD >/dev/null 2>&1 || initial_commit=t |
cf7bb589 JH |
12 | |
13 | case "$0" in | |
14 | *status) | |
15 | status_only=t | |
2b5f9a8c | 16 | ;; |
cf7bb589 JH |
17 | *commit) |
18 | status_only= | |
2b5f9a8c | 19 | ;; |
cf7bb589 | 20 | esac |
130fcca6 JH |
21 | |
22 | refuse_partial () { | |
23 | echo >&2 "$1" | |
130fcca6 JH |
24 | echo >&2 "You might have meant to say 'git commit -i paths...', perhaps?" |
25 | exit 1 | |
26 | } | |
27 | ||
cf7bb589 JH |
28 | THIS_INDEX="$GIT_DIR/index" |
29 | NEXT_INDEX="$GIT_DIR/next-index$$" | |
30 | rm -f "$NEXT_INDEX" | |
5a798fb5 | 31 | save_index () { |
cc7d5bcf | 32 | cp -p "$THIS_INDEX" "$NEXT_INDEX" |
cf7bb589 JH |
33 | } |
34 | ||
5a798fb5 | 35 | run_status () { |
cf7bb589 JH |
36 | # If TMP_INDEX is defined, that means we are doing |
37 | # "--only" partial commit, and that index file is used | |
38 | # to build the tree for the commit. Otherwise, if | |
39 | # NEXT_INDEX exists, that is the index file used to | |
40 | # make the commit. Otherwise we are using as-is commit | |
41 | # so the regular index file is what we use to compare. | |
42 | if test '' != "$TMP_INDEX" | |
43 | then | |
3de63c3f MW |
44 | GIT_INDEX_FILE="$TMP_INDEX" |
45 | export GIT_INDEX_FILE | |
cf7bb589 JH |
46 | elif test -f "$NEXT_INDEX" |
47 | then | |
3de63c3f MW |
48 | GIT_INDEX_FILE="$NEXT_INDEX" |
49 | export GIT_INDEX_FILE | |
cf7bb589 JH |
50 | fi |
51 | ||
3de63c3f MW |
52 | case "$status_only" in |
53 | t) color= ;; | |
54 | *) color=--nocolor ;; | |
55 | esac | |
56 | git-runstatus ${color} \ | |
57 | ${verbose:+--verbose} \ | |
58 | ${amend:+--amend} \ | |
2074cb0a | 59 | ${untracked_files:+--untracked} |
5a798fb5 JH |
60 | } |
61 | ||
cf7bb589 JH |
62 | trap ' |
63 | test -z "$TMP_INDEX" || { | |
64 | test -f "$TMP_INDEX" && rm -f "$TMP_INDEX" | |
65 | } | |
66 | rm -f "$NEXT_INDEX" | |
67 | ' 0 | |
68 | ||
69 | ################################################################ | |
70 | # Command line argument parsing and sanity checking | |
71 | ||
130fcca6 JH |
72 | all= |
73 | also= | |
6cbf07ef | 74 | interactive= |
5a798fb5 | 75 | only= |
130fcca6 JH |
76 | logfile= |
77 | use_commit= | |
b4019f04 | 78 | amend= |
cda8ab59 | 79 | edit_flag= |
130fcca6 JH |
80 | no_edit= |
81 | log_given= | |
82 | log_message= | |
83 | verify=t | |
ebd124c6 | 84 | quiet= |
cf7bb589 | 85 | verbose= |
130fcca6 JH |
86 | signoff= |
87 | force_author= | |
bba319b5 | 88 | only_include_assumed= |
443f8338 | 89 | untracked_files= |
0c091296 | 90 | while case "$#" in 0) break;; esac |
5fec3ef1 | 91 | do |
3de63c3f MW |
92 | case "$1" in |
93 | -F|--F|-f|--f|--fi|--fil|--file) | |
94 | case "$#" in 1) usage ;; esac | |
95 | shift | |
96 | no_edit=t | |
97 | log_given=t$log_given | |
98 | logfile="$1" | |
99 | shift | |
100 | ;; | |
101 | -F*|-f*) | |
102 | no_edit=t | |
103 | log_given=t$log_given | |
104 | logfile=`expr "z$1" : 'z-[Ff]\(.*\)'` | |
105 | shift | |
106 | ;; | |
107 | --F=*|--f=*|--fi=*|--fil=*|--file=*) | |
108 | no_edit=t | |
109 | log_given=t$log_given | |
110 | logfile=`expr "z$1" : 'z-[^=]*=\(.*\)'` | |
111 | shift | |
112 | ;; | |
113 | -a|--a|--al|--all) | |
114 | all=t | |
115 | shift | |
116 | ;; | |
117 | --au=*|--aut=*|--auth=*|--autho=*|--author=*) | |
118 | force_author=`expr "z$1" : 'z-[^=]*=\(.*\)'` | |
119 | shift | |
120 | ;; | |
121 | --au|--aut|--auth|--autho|--author) | |
122 | case "$#" in 1) usage ;; esac | |
123 | shift | |
124 | force_author="$1" | |
125 | shift | |
126 | ;; | |
127 | -e|--e|--ed|--edi|--edit) | |
128 | edit_flag=t | |
129 | shift | |
130 | ;; | |
131 | -i|--i|--in|--inc|--incl|--inclu|--includ|--include) | |
132 | also=t | |
133 | shift | |
134 | ;; | |
6cbf07ef PB |
135 | --int|--inte|--inter|--intera|--interac|--interact|--interacti|\ |
136 | --interactiv|--interactive) | |
137 | interactive=t | |
138 | shift | |
139 | ;; | |
3de63c3f MW |
140 | -o|--o|--on|--onl|--only) |
141 | only=t | |
142 | shift | |
143 | ;; | |
144 | -m|--m|--me|--mes|--mess|--messa|--messag|--message) | |
145 | case "$#" in 1) usage ;; esac | |
146 | shift | |
147 | log_given=m$log_given | |
148 | if test "$log_message" = '' | |
149 | then | |
150 | log_message="$1" | |
151 | else | |
152 | log_message="$log_message | |
6891281c SP |
153 | |
154 | $1" | |
3de63c3f MW |
155 | fi |
156 | no_edit=t | |
157 | shift | |
158 | ;; | |
159 | -m*) | |
160 | log_given=m$log_given | |
161 | if test "$log_message" = '' | |
162 | then | |
163 | log_message=`expr "z$1" : 'z-m\(.*\)'` | |
164 | else | |
165 | log_message="$log_message | |
6891281c | 166 | |
8096fae7 | 167 | `expr "z$1" : 'z-m\(.*\)'`" |
3de63c3f MW |
168 | fi |
169 | no_edit=t | |
170 | shift | |
171 | ;; | |
172 | --m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*) | |
173 | log_given=m$log_given | |
174 | if test "$log_message" = '' | |
175 | then | |
176 | log_message=`expr "z$1" : 'z-[^=]*=\(.*\)'` | |
177 | else | |
178 | log_message="$log_message | |
6891281c | 179 | |
8096fae7 | 180 | `expr "z$1" : 'zq-[^=]*=\(.*\)'`" |
3de63c3f MW |
181 | fi |
182 | no_edit=t | |
183 | shift | |
184 | ;; | |
185 | -n|--n|--no|--no-|--no-v|--no-ve|--no-ver|--no-veri|--no-verif|\ | |
186 | --no-verify) | |
187 | verify= | |
188 | shift | |
189 | ;; | |
190 | --a|--am|--ame|--amen|--amend) | |
191 | amend=t | |
192 | log_given=t$log_given | |
193 | use_commit=HEAD | |
194 | shift | |
195 | ;; | |
196 | -c) | |
197 | case "$#" in 1) usage ;; esac | |
198 | shift | |
199 | log_given=t$log_given | |
200 | use_commit="$1" | |
201 | no_edit= | |
202 | shift | |
203 | ;; | |
204 | --ree=*|--reed=*|--reedi=*|--reedit=*|--reedit-=*|--reedit-m=*|\ | |
205 | --reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\ | |
206 | --reedit-messag=*|--reedit-message=*) | |
207 | log_given=t$log_given | |
208 | use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'` | |
209 | no_edit= | |
210 | shift | |
211 | ;; | |
212 | --ree|--reed|--reedi|--reedit|--reedit-|--reedit-m|--reedit-me|\ | |
213 | --reedit-mes|--reedit-mess|--reedit-messa|--reedit-messag|\ | |
214 | --reedit-message) | |
215 | case "$#" in 1) usage ;; esac | |
216 | shift | |
217 | log_given=t$log_given | |
218 | use_commit="$1" | |
219 | no_edit= | |
220 | shift | |
221 | ;; | |
222 | -C) | |
223 | case "$#" in 1) usage ;; esac | |
224 | shift | |
225 | log_given=t$log_given | |
226 | use_commit="$1" | |
227 | no_edit=t | |
228 | shift | |
229 | ;; | |
230 | --reu=*|--reus=*|--reuse=*|--reuse-=*|--reuse-m=*|--reuse-me=*|\ | |
231 | --reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\ | |
232 | --reuse-message=*) | |
233 | log_given=t$log_given | |
234 | use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'` | |
235 | no_edit=t | |
236 | shift | |
237 | ;; | |
238 | --reu|--reus|--reuse|--reuse-|--reuse-m|--reuse-me|--reuse-mes|\ | |
239 | --reuse-mess|--reuse-messa|--reuse-messag|--reuse-message) | |
240 | case "$#" in 1) usage ;; esac | |
241 | shift | |
242 | log_given=t$log_given | |
243 | use_commit="$1" | |
244 | no_edit=t | |
245 | shift | |
246 | ;; | |
247 | -s|--s|--si|--sig|--sign|--signo|--signof|--signoff) | |
248 | signoff=t | |
249 | shift | |
250 | ;; | |
ebd124c6 NP |
251 | -q|--q|--qu|--qui|--quie|--quiet) |
252 | quiet=t | |
253 | shift | |
254 | ;; | |
3de63c3f MW |
255 | -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose) |
256 | verbose=t | |
257 | shift | |
258 | ;; | |
259 | -u|--u|--un|--unt|--untr|--untra|--untrac|--untrack|--untracke|\ | |
260 | --untracked|--untracked-|--untracked-f|--untracked-fi|--untracked-fil|\ | |
261 | --untracked-file|--untracked-files) | |
262 | untracked_files=t | |
263 | shift | |
264 | ;; | |
265 | --) | |
266 | shift | |
267 | break | |
268 | ;; | |
269 | -*) | |
270 | usage | |
271 | ;; | |
272 | *) | |
273 | break | |
274 | ;; | |
275 | esac | |
5fec3ef1 | 276 | done |
cda8ab59 | 277 | case "$edit_flag" in t) no_edit= ;; esac |
5fec3ef1 | 278 | |
cf7bb589 JH |
279 | ################################################################ |
280 | # Sanity check options | |
281 | ||
b4019f04 JH |
282 | case "$amend,$initial_commit" in |
283 | t,t) | |
3de63c3f | 284 | die "You do not have anything to amend." ;; |
b4019f04 | 285 | t,) |
3de63c3f MW |
286 | if [ -f "$GIT_DIR/MERGE_HEAD" ]; then |
287 | die "You are in the middle of a merge -- cannot amend." | |
288 | fi ;; | |
b4019f04 JH |
289 | esac |
290 | ||
0c091296 JH |
291 | case "$log_given" in |
292 | tt*) | |
497171e7 | 293 | die "Only one of -c/-C/-F/--amend can be used." ;; |
6891281c | 294 | *tm*|*mt*) |
497171e7 | 295 | die "Option -m cannot be combined with -c/-C/-F/--amend." ;; |
0c091296 JH |
296 | esac |
297 | ||
6a74642c JH |
298 | case "$#,$also,$only,$amend" in |
299 | *,t,t,*) | |
3de63c3f | 300 | die "Only one of --include/--only can be used." ;; |
6a74642c | 301 | 0,t,,* | 0,,t,) |
3de63c3f | 302 | die "No paths with --include/--only does not make sense." ;; |
6a74642c | 303 | 0,,t,t) |
3de63c3f | 304 | only_include_assumed="# Clever... amending the last one with dirty index." ;; |
6a74642c | 305 | 0,,,*) |
3de63c3f | 306 | ;; |
6a74642c | 307 | *,,,*) |
3de63c3f MW |
308 | only_include_assumed="# Explicit paths specified without -i nor -o; assuming --only paths..." |
309 | also= | |
310 | ;; | |
5a798fb5 JH |
311 | esac |
312 | unset only | |
6cbf07ef PB |
313 | case "$all,$interactive,$also,$#" in |
314 | *t,*t,*) | |
315 | die "Cannot use -a, --interactive or -i at the same time." ;; | |
cf7bb589 JH |
316 | t,,[1-9]*) |
317 | die "Paths with -a does not make sense." ;; | |
6cbf07ef PB |
318 | ,t,[1-9]*) |
319 | die "Paths with --interactive does not make sense." ;; | |
320 | ,,t,0) | |
cf7bb589 JH |
321 | die "No paths with -i does not make sense." ;; |
322 | esac | |
323 | ||
324 | ################################################################ | |
325 | # Prepare index to have a tree to be committed | |
5a798fb5 | 326 | |
130fcca6 | 327 | case "$all,$also" in |
130fcca6 | 328 | t,) |
755b99d8 FK |
329 | if test ! -f "$THIS_INDEX" |
330 | then | |
331 | die 'nothing to commit (use "git add file1 file2" to include for commit)' | |
332 | fi | |
5a798fb5 | 333 | save_index && |
130fcca6 | 334 | ( |
514c09fd JH |
335 | cd_to_toplevel && |
336 | GIT_INDEX_FILE="$NEXT_INDEX" && | |
337 | export GIT_INDEX_FILE && | |
130fcca6 JH |
338 | git-diff-files --name-only -z | |
339 | git-update-index --remove -z --stdin | |
514c09fd | 340 | ) || exit |
6a0049c0 | 341 | ;; |
130fcca6 | 342 | ,t) |
5a798fb5 | 343 | save_index && |
bba319b5 JH |
344 | git-ls-files --error-unmatch -- "$@" >/dev/null || exit |
345 | ||
130fcca6 | 346 | git-diff-files --name-only -z -- "$@" | |
cf7bb589 | 347 | ( |
514c09fd JH |
348 | cd_to_toplevel && |
349 | GIT_INDEX_FILE="$NEXT_INDEX" && | |
350 | export GIT_INDEX_FILE && | |
cf7bb589 | 351 | git-update-index --remove -z --stdin |
514c09fd | 352 | ) || exit |
22cff6a5 | 353 | ;; |
130fcca6 | 354 | ,) |
6cbf07ef PB |
355 | if test "$interactive" = t; then |
356 | git add --interactive || exit | |
357 | fi | |
130fcca6 JH |
358 | case "$#" in |
359 | 0) | |
3de63c3f | 360 | ;; # commit as-is |
130fcca6 | 361 | *) |
3de63c3f MW |
362 | if test -f "$GIT_DIR/MERGE_HEAD" |
363 | then | |
364 | refuse_partial "Cannot do a partial commit during a merge." | |
365 | fi | |
366 | TMP_INDEX="$GIT_DIR/tmp-index$$" | |
3de63c3f | 367 | commit_only=`git-ls-files --error-unmatch -- "$@"` || exit |
cf7bb589 | 368 | |
158d0577 | 369 | # Build a temporary index and update the real index |
3de63c3f MW |
370 | # the same way. |
371 | if test -z "$initial_commit" | |
372 | then | |
373 | cp "$THIS_INDEX" "$TMP_INDEX" | |
d3e41ebf | 374 | GIT_INDEX_FILE="$TMP_INDEX" git-read-tree -i -m HEAD |
3de63c3f MW |
375 | else |
376 | rm -f "$TMP_INDEX" | |
377 | fi || exit | |
cf7bb589 | 378 | |
3de63c3f MW |
379 | echo "$commit_only" | |
380 | GIT_INDEX_FILE="$TMP_INDEX" \ | |
381 | git-update-index --add --remove --stdin && | |
cf7bb589 | 382 | |
3de63c3f MW |
383 | save_index && |
384 | echo "$commit_only" | | |
385 | ( | |
386 | GIT_INDEX_FILE="$NEXT_INDEX" | |
387 | export GIT_INDEX_FILE | |
388 | git-update-index --remove --stdin | |
389 | ) || exit | |
390 | ;; | |
130fcca6 JH |
391 | esac |
392 | ;; | |
393 | esac | |
394 | ||
cf7bb589 JH |
395 | ################################################################ |
396 | # If we do as-is commit, the index file will be THIS_INDEX, | |
397 | # otherwise NEXT_INDEX after we make this commit. We leave | |
398 | # the index as is if we abort. | |
130fcca6 | 399 | |
cf7bb589 | 400 | if test -f "$NEXT_INDEX" |
130fcca6 | 401 | then |
cf7bb589 JH |
402 | USE_INDEX="$NEXT_INDEX" |
403 | else | |
404 | USE_INDEX="$THIS_INDEX" | |
130fcca6 JH |
405 | fi |
406 | ||
2b5f9a8c JH |
407 | case "$status_only" in |
408 | t) | |
409 | # This will silently fail in a read-only repository, which is | |
410 | # what we want. | |
411 | GIT_INDEX_FILE="$USE_INDEX" git-update-index -q --unmerged --refresh | |
cf7bb589 JH |
412 | run_status |
413 | exit $? | |
2b5f9a8c JH |
414 | ;; |
415 | '') | |
416 | GIT_INDEX_FILE="$USE_INDEX" git-update-index -q --refresh || exit | |
417 | ;; | |
cf7bb589 JH |
418 | esac |
419 | ||
420 | ################################################################ | |
421 | # Grab commit message, write out tree and make commit. | |
422 | ||
130fcca6 JH |
423 | if test t = "$verify" && test -x "$GIT_DIR"/hooks/pre-commit |
424 | then | |
425 | if test "$TMP_INDEX" | |
426 | then | |
427 | GIT_INDEX_FILE="$TMP_INDEX" "$GIT_DIR"/hooks/pre-commit | |
428 | else | |
cf7bb589 | 429 | GIT_INDEX_FILE="$USE_INDEX" "$GIT_DIR"/hooks/pre-commit |
130fcca6 JH |
430 | fi || exit |
431 | fi | |
0cfe1d30 | 432 | |
aba2da13 JH |
433 | if test "$log_message" != '' |
434 | then | |
435 | echo "$log_message" | |
436 | elif test "$logfile" != "" | |
437 | then | |
438 | if test "$logfile" = - | |
439 | then | |
440 | test -t 0 && | |
441 | echo >&2 "(reading log message from standard input)" | |
442 | cat | |
443 | else | |
444 | cat <"$logfile" | |
445 | fi | |
446 | elif test "$use_commit" != "" | |
447 | then | |
e0d10e1c | 448 | encoding=$(git config i18n.commitencoding || echo UTF-8) |
5ac2715f JH |
449 | git show -s --pretty=raw --encoding="$encoding" "$use_commit" | |
450 | sed -e '1,/^$/d' -e 's/^ //' | |
a9cb3c6e | 451 | elif test -f "$GIT_DIR/MERGE_MSG" |
e5215804 JH |
452 | then |
453 | cat "$GIT_DIR/MERGE_MSG" | |
7d0c6887 JH |
454 | elif test -f "$GIT_DIR/SQUASH_MSG" |
455 | then | |
456 | cat "$GIT_DIR/SQUASH_MSG" | |
f8e2c54c | 457 | fi | git-stripspace >"$GIT_DIR"/COMMIT_EDITMSG |
2d569933 JH |
458 | |
459 | case "$signoff" in | |
460 | t) | |
dbaa06a2 JH |
461 | need_blank_before_signoff= |
462 | tail -n 1 "$GIT_DIR"/COMMIT_EDITMSG | | |
463 | grep 'Signed-off-by:' >/dev/null || need_blank_before_signoff=yes | |
f6413391 | 464 | { |
dbaa06a2 | 465 | test -z "$need_blank_before_signoff" || echo |
f6413391 JH |
466 | git-var GIT_COMMITTER_IDENT | sed -e ' |
467 | s/>.*/>/ | |
468 | s/^/Signed-off-by: / | |
469 | ' | |
f8e2c54c | 470 | } >>"$GIT_DIR"/COMMIT_EDITMSG |
2d569933 JH |
471 | ;; |
472 | esac | |
473 | ||
475443c8 | 474 | if test -f "$GIT_DIR/MERGE_HEAD" && test -z "$no_edit"; then |
2d569933 | 475 | echo "#" |
b6ae5409 | 476 | echo "# It looks like you may be committing a MERGE." |
2d569933 JH |
477 | echo "# If this is not correct, please remove the file" |
478 | echo "# $GIT_DIR/MERGE_HEAD" | |
479 | echo "# and try again" | |
480 | echo "#" | |
f8e2c54c | 481 | fi >>"$GIT_DIR"/COMMIT_EDITMSG |
aba2da13 | 482 | |
130fcca6 | 483 | # Author |
83e24dce | 484 | if test '' != "$use_commit" |
130fcca6 JH |
485 | then |
486 | pick_author_script=' | |
487 | /^author /{ | |
488 | s/'\''/'\''\\'\'\''/g | |
489 | h | |
490 | s/^author \([^<]*\) <[^>]*> .*$/\1/ | |
491 | s/'\''/'\''\'\'\''/g | |
492 | s/.*/GIT_AUTHOR_NAME='\''&'\''/p | |
493 | ||
494 | g | |
495 | s/^author [^<]* <\([^>]*\)> .*$/\1/ | |
496 | s/'\''/'\''\'\'\''/g | |
497 | s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p | |
498 | ||
499 | g | |
500 | s/^author [^<]* <[^>]*> \(.*\)$/\1/ | |
501 | s/'\''/'\''\'\'\''/g | |
502 | s/.*/GIT_AUTHOR_DATE='\''&'\''/p | |
503 | ||
504 | q | |
505 | } | |
506 | ' | |
e0d10e1c | 507 | encoding=$(git config i18n.commitencoding || echo UTF-8) |
5ac2715f | 508 | set_author_env=`git show -s --pretty=raw --encoding="$encoding" "$use_commit" | |
130fcca6 JH |
509 | LANG=C LC_ALL=C sed -ne "$pick_author_script"` |
510 | eval "$set_author_env" | |
511 | export GIT_AUTHOR_NAME | |
512 | export GIT_AUTHOR_EMAIL | |
513 | export GIT_AUTHOR_DATE | |
130fcca6 | 514 | fi |
83e24dce JH |
515 | if test '' != "$force_author" |
516 | then | |
517 | GIT_AUTHOR_NAME=`expr "z$force_author" : 'z\(.*[^ ]\) *<.*'` && | |
518 | GIT_AUTHOR_EMAIL=`expr "z$force_author" : '.*\(<.*\)'` && | |
519 | test '' != "$GIT_AUTHOR_NAME" && | |
520 | test '' != "$GIT_AUTHOR_EMAIL" || | |
521 | die "malformed --author parameter" | |
522 | export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL | |
523 | fi | |
130fcca6 | 524 | |
96069cf0 | 525 | PARENTS="-p HEAD" |
130fcca6 | 526 | if test -z "$initial_commit" |
8098a178 | 527 | then |
a3a733e6 | 528 | rloga='commit' |
5fec3ef1 | 529 | if [ -f "$GIT_DIR/MERGE_HEAD" ]; then |
a3a733e6 | 530 | rloga='commit (merge)' |
91063bbc | 531 | PARENTS="-p HEAD "`sed -e 's/^/-p /' "$GIT_DIR/MERGE_HEAD"` |
b4019f04 | 532 | elif test -n "$amend"; then |
a3a733e6 | 533 | rloga='commit (amend)' |
b4019f04 JH |
534 | PARENTS=$(git-cat-file commit HEAD | |
535 | sed -n -e '/^$/q' -e 's/^parent /-p /p') | |
aba2da13 | 536 | fi |
cede7526 | 537 | current="$(git-rev-parse --verify HEAD)" |
8098a178 JH |
538 | else |
539 | if [ -z "$(git-ls-files)" ]; then | |
aeb80c70 | 540 | echo >&2 'nothing to commit (use "git add file1 file2" to include for commit)' |
8098a178 JH |
541 | exit 1 |
542 | fi | |
543 | PARENTS="" | |
a3a733e6 | 544 | rloga='commit (initial)' |
cede7526 | 545 | current='' |
96069cf0 | 546 | fi |
23913dc7 | 547 | set_reflog_action "$rloga" |
130fcca6 | 548 | |
475443c8 JH |
549 | if test -z "$no_edit" |
550 | then | |
551 | { | |
88a15314 MW |
552 | echo "" |
553 | echo "# Please enter the commit message for your changes." | |
554 | echo "# (Comment lines starting with '#' will not be included)" | |
475443c8 JH |
555 | test -z "$only_include_assumed" || echo "$only_include_assumed" |
556 | run_status | |
557 | } >>"$GIT_DIR"/COMMIT_EDITMSG | |
558 | else | |
559 | # we need to check if there is anything to commit | |
560 | run_status >/dev/null | |
561 | fi | |
8588452c | 562 | if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" -a -z "$amend" ] |
a3e870f2 | 563 | then |
7d0c6887 | 564 | rm -f "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG" |
5a798fb5 | 565 | run_status |
a3e870f2 LT |
566 | exit 1 |
567 | fi | |
475443c8 | 568 | |
0c091296 | 569 | case "$no_edit" in |
5fec3ef1 | 570 | '') |
7334f06c JH |
571 | case "${VISUAL:-$EDITOR},$TERM" in |
572 | ,dumb) | |
573 | echo >&2 "Terminal is dumb but no VISUAL nor EDITOR defined." | |
574 | echo >&2 "Please supply the commit log message using either" | |
575 | echo >&2 "-m or -F option. A boilerplate log message has" | |
576 | echo >&2 "been prepared in $GIT_DIR/COMMIT_EDITMSG" | |
130fcca6 JH |
577 | exit 1 |
578 | ;; | |
7334f06c | 579 | esac |
ec4e69c0 SE |
580 | git-var GIT_AUTHOR_IDENT > /dev/null || die |
581 | git-var GIT_COMMITTER_IDENT > /dev/null || die | |
f8e2c54c | 582 | ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG" |
5fec3ef1 JH |
583 | ;; |
584 | esac | |
89e2c5f1 JH |
585 | |
586 | case "$verify" in | |
587 | t) | |
588 | if test -x "$GIT_DIR"/hooks/commit-msg | |
589 | then | |
f8e2c54c | 590 | "$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/COMMIT_EDITMSG || exit |
89e2c5f1 JH |
591 | fi |
592 | esac | |
593 | ||
29f4ad86 YD |
594 | if test -z "$no_edit" |
595 | then | |
596 | sed -e ' | |
597 | /^diff --git a\/.*/{ | |
598 | s/// | |
599 | q | |
600 | } | |
601 | /^#/d | |
602 | ' "$GIT_DIR"/COMMIT_EDITMSG | |
603 | else | |
604 | cat "$GIT_DIR"/COMMIT_EDITMSG | |
605 | fi | | |
cf7bb589 | 606 | git-stripspace >"$GIT_DIR"/COMMIT_MSG |
f8e2c54c SB |
607 | |
608 | if cnt=`grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG | | |
609 | git-stripspace | | |
610 | wc -l` && | |
611 | test 0 -lt $cnt | |
0c091296 | 612 | then |
130fcca6 JH |
613 | if test -z "$TMP_INDEX" |
614 | then | |
cf7bb589 | 615 | tree=$(GIT_INDEX_FILE="$USE_INDEX" git-write-tree) |
130fcca6 JH |
616 | else |
617 | tree=$(GIT_INDEX_FILE="$TMP_INDEX" git-write-tree) && | |
618 | rm -f "$TMP_INDEX" | |
619 | fi && | |
f8e2c54c | 620 | commit=$(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree $tree $PARENTS) && |
67644a4d | 621 | rlogm=$(sed -e 1q "$GIT_DIR"/COMMIT_MSG) && |
23913dc7 | 622 | git-update-ref -m "$GIT_REFLOG_ACTION: $rlogm" HEAD $commit "$current" && |
a9cb3c6e | 623 | rm -f -- "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/MERGE_MSG" && |
cf7bb589 JH |
624 | if test -f "$NEXT_INDEX" |
625 | then | |
626 | mv "$NEXT_INDEX" "$THIS_INDEX" | |
627 | else | |
628 | : ;# happy | |
629 | fi | |
0c091296 JH |
630 | else |
631 | echo >&2 "* no commit message? aborting commit." | |
632 | false | |
633 | fi | |
170241b7 | 634 | ret="$?" |
7d0c6887 | 635 | rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG" |
c93d88a5 JH |
636 | |
637 | cd_to_toplevel | |
638 | ||
1536dd9c JH |
639 | if test -d "$GIT_DIR/rr-cache" |
640 | then | |
641 | git-rerere | |
642 | fi | |
89e2c5f1 | 643 | |
ebd124c6 | 644 | if test "$ret" = 0 |
89e2c5f1 | 645 | then |
ebd124c6 NP |
646 | if test -x "$GIT_DIR"/hooks/post-commit |
647 | then | |
648 | "$GIT_DIR"/hooks/post-commit | |
649 | fi | |
650 | if test -z "$quiet" | |
651 | then | |
652 | echo "Created${initial_commit:+ initial} commit $commit" | |
521f9c4d | 653 | git-diff-tree --shortstat --summary --root --no-commit-id HEAD -- |
ebd124c6 | 654 | fi |
89e2c5f1 | 655 | fi |
61f5cb7f | 656 | |
170241b7 | 657 | exit "$ret" |