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