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