]> git.ipfire.org Git - thirdparty/git.git/blame - git-commit.sh
Merge branch 'js/patch'
[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
443f8338 6USAGE='[-a] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit>] [-u] [--amend] [-e] [--author <author>] [[-i | -o] <path>...]'
130fcca6 7SUBDIRECTORY_OK=Yes
ae2b0f15 8. git-sh-setup
b33e9666 9
cf7bb589
JH
10git-rev-parse --verify HEAD >/dev/null 2>&1 || initial_commit=t
11branch=$(GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD)
12
13case "$0" in
14*status)
15 status_only=t
16 unmerged_ok_if_status=--unmerged ;;
17*commit)
18 status_only=
19 unmerged_ok_if_status= ;;
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 () {
cf7bb589
JH
32 cp "$THIS_INDEX" "$NEXT_INDEX"
33}
34
35report () {
36 header="#
37# $1:
38# ($2)
39#
40"
41 trailer=""
42 while read status name newname
43 do
44 printf '%s' "$header"
45 header=""
46 trailer="#
47"
48 case "$status" in
49 M ) echo "# modified: $name";;
50 D*) echo "# deleted: $name";;
51 T ) echo "# typechange: $name";;
52 C*) echo "# copied: $name -> $newname";;
53 R*) echo "# renamed: $name -> $newname";;
54 A*) echo "# new file: $name";;
55 U ) echo "# unmerged: $name";;
56 esac
57 done
58 printf '%s' "$trailer"
59 [ "$header" ]
5a798fb5
JH
60}
61
62run_status () {
cf7bb589
JH
63 (
64 # We always show status for the whole tree.
65 cd "$TOP"
66
b4019f04
JH
67 IS_INITIAL="$initial_commit"
68 REFERENCE=HEAD
69 case "$amend" in
70 t)
71 # If we are amending the initial commit, there
72 # is no HEAD^1.
73 if git-rev-parse --verify "HEAD^1" >/dev/null 2>&1
74 then
75 REFERENCE="HEAD^1"
76 IS_INITIAL=
77 else
78 IS_INITIAL=t
79 fi
80 ;;
81 esac
82
cf7bb589
JH
83 # If TMP_INDEX is defined, that means we are doing
84 # "--only" partial commit, and that index file is used
85 # to build the tree for the commit. Otherwise, if
86 # NEXT_INDEX exists, that is the index file used to
87 # make the commit. Otherwise we are using as-is commit
88 # so the regular index file is what we use to compare.
89 if test '' != "$TMP_INDEX"
90 then
91 GIT_INDEX_FILE="$TMP_INDEX"
92 export GIT_INDEX_FILE
93 elif test -f "$NEXT_INDEX"
94 then
95 GIT_INDEX_FILE="$NEXT_INDEX"
96 export GIT_INDEX_FILE
97 fi
98
99 case "$branch" in
100 refs/heads/master) ;;
101 *) echo "# On branch $branch" ;;
102 esac
103
b4019f04 104 if test -z "$IS_INITIAL"
cf7bb589 105 then
9ae6be80 106 git-diff-index -M --cached --name-status \
b4019f04 107 --diff-filter=MDTCRA $REFERENCE |
9ae6be80
JH
108 sed -e '
109 s/\\/\\\\/g
110 s/ /\\ /g
111 ' |
112 report "Updated but not checked in" "will commit"
cf7bb589
JH
113 committable="$?"
114 else
115 echo '#
116# Initial commit
117#'
118 git-ls-files |
119 sed -e '
120 s/\\/\\\\/g
121 s/ /\\ /g
122 s/^/A /
123 ' |
124 report "Updated but not checked in" "will commit"
125
126 committable="$?"
127 fi
128
129 git-diff-files --name-status |
130 sed -e '
131 s/\\/\\\\/g
132 s/ /\\ /g
133 ' |
134 report "Changed but not updated" \
135 "use git-update-index to mark for commit"
136
443f8338
ML
137 option=""
138 if test -z "$untracked_files"; then
139 option="--directory --no-empty-directory"
140 fi
cf7bb589
JH
141 if test -f "$GIT_DIR/info/exclude"
142 then
443f8338 143 git-ls-files -z --others $option \
cf7bb589
JH
144 --exclude-from="$GIT_DIR/info/exclude" \
145 --exclude-per-directory=.gitignore
146 else
443f8338 147 git-ls-files -z --others $option \
cf7bb589
JH
148 --exclude-per-directory=.gitignore
149 fi |
150 perl -e '$/ = "\0";
151 my $shown = 0;
152 while (<>) {
153 chomp;
154 s|\\|\\\\|g;
155 s|\t|\\t|g;
156 s|\n|\\n|g;
157 s/^/# /;
158 if (!$shown) {
159 print "#\n# Untracked files:\n";
160 print "# (use \"git add\" to add to commit)\n";
161 print "#\n";
162 $shown = 1;
163 }
164 print "$_\n";
165 }
166 '
9ae6be80 167
1fa7a68f 168 if test -n "$verbose" -a -z "$IS_INITIAL"
9ae6be80 169 then
b4019f04 170 git-diff-index --cached -M -p --diff-filter=MDTCRA $REFERENCE
9ae6be80 171 fi
cf7bb589
JH
172 case "$committable" in
173 0)
6a74642c
JH
174 case "$amend" in
175 t)
176 echo "# No changes" ;;
177 *)
178 echo "nothing to commit" ;;
179 esac
180 exit 1 ;;
cf7bb589
JH
181 esac
182 exit 0
183 )
5a798fb5
JH
184}
185
cf7bb589
JH
186trap '
187 test -z "$TMP_INDEX" || {
188 test -f "$TMP_INDEX" && rm -f "$TMP_INDEX"
189 }
190 rm -f "$NEXT_INDEX"
191' 0
192
193################################################################
194# Command line argument parsing and sanity checking
195
130fcca6
JH
196all=
197also=
5a798fb5 198only=
130fcca6
JH
199logfile=
200use_commit=
b4019f04 201amend=
cda8ab59 202edit_flag=
130fcca6
JH
203no_edit=
204log_given=
205log_message=
206verify=t
cf7bb589 207verbose=
130fcca6
JH
208signoff=
209force_author=
bba319b5 210only_include_assumed=
443f8338 211untracked_files=
0c091296 212while case "$#" in 0) break;; esac
5fec3ef1 213do
0c091296 214 case "$1" in
130fcca6
JH
215 -F|--F|-f|--f|--fi|--fil|--file)
216 case "$#" in 1) usage ;; esac
217 shift
218 no_edit=t
219 log_given=t$log_given
220 logfile="$1"
221 shift
222 ;;
223 -F*|-f*)
224 no_edit=t
225 log_given=t$log_given
8096fae7 226 logfile=`expr "z$1" : 'z-[Ff]\(.*\)'`
130fcca6
JH
227 shift
228 ;;
229 --F=*|--f=*|--fi=*|--fil=*|--file=*)
230 no_edit=t
231 log_given=t$log_given
8096fae7 232 logfile=`expr "z$1" : 'z-[^=]*=\(.*\)'`
130fcca6
JH
233 shift
234 ;;
0c091296 235 -a|--a|--al|--all)
130fcca6
JH
236 all=t
237 shift
238 ;;
239 --au=*|--aut=*|--auth=*|--autho=*|--author=*)
8096fae7 240 force_author=`expr "z$1" : 'z-[^=]*=\(.*\)'`
130fcca6
JH
241 shift
242 ;;
243 --au|--aut|--auth|--autho|--author)
244 case "$#" in 1) usage ;; esac
245 shift
246 force_author="$1"
247 shift
248 ;;
249 -e|--e|--ed|--edi|--edit)
cda8ab59 250 edit_flag=t
130fcca6
JH
251 shift
252 ;;
253 -i|--i|--in|--inc|--incl|--inclu|--includ|--include)
254 also=t
255 shift
256 ;;
5a798fb5
JH
257 -o|--o|--on|--onl|--only)
258 only=t
259 shift
260 ;;
0c091296 261 -m|--m|--me|--mes|--mess|--messa|--messag|--message)
130fcca6
JH
262 case "$#" in 1) usage ;; esac
263 shift
6891281c
SP
264 log_given=m$log_given
265 if test "$log_message" = ''
266 then
267 log_message="$1"
268 else
269 log_message="$log_message
270
271$1"
272 fi
130fcca6
JH
273 no_edit=t
274 shift
275 ;;
276 -m*)
6891281c
SP
277 log_given=m$log_given
278 if test "$log_message" = ''
279 then
8096fae7 280 log_message=`expr "z$1" : 'z-m\(.*\)'`
6891281c
SP
281 else
282 log_message="$log_message
283
8096fae7 284`expr "z$1" : 'z-m\(.*\)'`"
6891281c 285 fi
130fcca6
JH
286 no_edit=t
287 shift
288 ;;
289 --m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*)
6891281c
SP
290 log_given=m$log_given
291 if test "$log_message" = ''
292 then
8096fae7 293 log_message=`expr "z$1" : 'z-[^=]*=\(.*\)'`
6891281c
SP
294 else
295 log_message="$log_message
296
8096fae7 297`expr "z$1" : 'zq-[^=]*=\(.*\)'`"
6891281c 298 fi
130fcca6
JH
299 no_edit=t
300 shift
301 ;;
302 -n|--n|--no|--no-|--no-v|--no-ve|--no-ver|--no-veri|--no-verif|--no-verify)
303 verify=
304 shift
305 ;;
b4019f04
JH
306 --a|--am|--ame|--amen|--amend)
307 amend=t
308 log_given=t$log_given
309 use_commit=HEAD
310 shift
311 ;;
130fcca6
JH
312 -c)
313 case "$#" in 1) usage ;; esac
314 shift
315 log_given=t$log_given
316 use_commit="$1"
317 no_edit=
318 shift
319 ;;
320 --ree=*|--reed=*|--reedi=*|--reedit=*|--reedit-=*|--reedit-m=*|\
0c091296
JH
321 --reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\
322 --reedit-messag=*|--reedit-message=*)
130fcca6 323 log_given=t$log_given
8096fae7 324 use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'`
130fcca6
JH
325 no_edit=
326 shift
327 ;;
328 --ree|--reed|--reedi|--reedit|--reedit-|--reedit-m|--reedit-me|\
0c091296 329 --reedit-mes|--reedit-mess|--reedit-messa|--reedit-messag|--reedit-message)
130fcca6
JH
330 case "$#" in 1) usage ;; esac
331 shift
332 log_given=t$log_given
333 use_commit="$1"
334 no_edit=
335 shift
336 ;;
337 -C)
338 case "$#" in 1) usage ;; esac
339 shift
340 log_given=t$log_given
341 use_commit="$1"
342 no_edit=t
343 shift
344 ;;
345 --reu=*|--reus=*|--reuse=*|--reuse-=*|--reuse-m=*|--reuse-me=*|\
0c091296
JH
346 --reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\
347 --reuse-message=*)
130fcca6 348 log_given=t$log_given
8096fae7 349 use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'`
130fcca6
JH
350 no_edit=t
351 shift
352 ;;
353 --reu|--reus|--reuse|--reuse-|--reuse-m|--reuse-me|--reuse-mes|\
0c091296 354 --reuse-mess|--reuse-messa|--reuse-messag|--reuse-message)
130fcca6
JH
355 case "$#" in 1) usage ;; esac
356 shift
357 log_given=t$log_given
358 use_commit="$1"
359 no_edit=t
360 shift
361 ;;
0cfe1d30 362 -s|--s|--si|--sig|--sign|--signo|--signof|--signoff)
130fcca6
JH
363 signoff=t
364 shift
365 ;;
cf7bb589
JH
366 -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
367 verbose=t
368 shift
130fcca6 369 ;;
443f8338
ML
370 -u|--u|--un|--unt|--untr|--untra|--untrac|--untrack|--untracke|--untracked|\
371 --untracked-|--untracked-f|--untracked-fi|--untracked-fil|--untracked-file|\
372 --untracked-files)
373 untracked_files=t
374 shift
375 ;;
0c091296 376 --)
130fcca6
JH
377 shift
378 break
379 ;;
0c091296 380 -*)
130fcca6
JH
381 usage
382 ;;
0c091296 383 *)
130fcca6
JH
384 break
385 ;;
0c091296 386 esac
5fec3ef1 387done
cda8ab59 388case "$edit_flag" in t) no_edit= ;; esac
5fec3ef1 389
cf7bb589
JH
390################################################################
391# Sanity check options
392
b4019f04
JH
393case "$amend,$initial_commit" in
394t,t)
395 die "You do not have anything to amend." ;;
396t,)
397 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
398 die "You are in the middle of a merge -- cannot amend."
399 fi ;;
400esac
401
0c091296
JH
402case "$log_given" in
403tt*)
6891281c
SP
404 die "Only one of -c/-C/-F can be used." ;;
405*tm*|*mt*)
406 die "Option -m cannot be combined with -c/-C/-F." ;;
0c091296
JH
407esac
408
6a74642c
JH
409case "$#,$also,$only,$amend" in
410*,t,t,*)
5a798fb5 411 die "Only one of --include/--only can be used." ;;
6a74642c 4120,t,,* | 0,,t,)
5a798fb5 413 die "No paths with --include/--only does not make sense." ;;
6a74642c
JH
4140,,t,t)
415 only_include_assumed="# Clever... amending the last one with dirty index." ;;
4160,,,*)
5a798fb5 417 ;;
6a74642c 418*,,,*)
756e3ee0 419 only_include_assumed="# Explicit paths specified without -i nor -o; assuming --only paths..."
4170a195 420 also=
5a798fb5
JH
421 ;;
422esac
423unset only
cf7bb589
JH
424case "$all,$also,$#" in
425t,t,*)
426 die "Cannot use -a and -i at the same time." ;;
427t,,[1-9]*)
428 die "Paths with -a does not make sense." ;;
429,t,0)
430 die "No paths with -i does not make sense." ;;
431esac
432
433################################################################
434# Prepare index to have a tree to be committed
5a798fb5 435
130fcca6 436TOP=`git-rev-parse --show-cdup`
5a798fb5
JH
437if test -z "$TOP"
438then
439 TOP=./
440fi
130fcca6
JH
441
442case "$all,$also" in
130fcca6 443t,)
5a798fb5 444 save_index &&
130fcca6 445 (
5a798fb5 446 cd "$TOP"
cf7bb589
JH
447 GIT_INDEX_FILE="$NEXT_INDEX"
448 export GIT_INDEX_FILE
130fcca6
JH
449 git-diff-files --name-only -z |
450 git-update-index --remove -z --stdin
451 )
6a0049c0 452 ;;
130fcca6 453,t)
5a798fb5 454 save_index &&
bba319b5
JH
455 git-ls-files --error-unmatch -- "$@" >/dev/null || exit
456
130fcca6 457 git-diff-files --name-only -z -- "$@" |
cf7bb589
JH
458 (
459 cd "$TOP"
460 GIT_INDEX_FILE="$NEXT_INDEX"
461 export GIT_INDEX_FILE
462 git-update-index --remove -z --stdin
463 )
22cff6a5 464 ;;
130fcca6
JH
465,)
466 case "$#" in
467 0)
468 ;; # commit as-is
469 *)
470 if test -f "$GIT_DIR/MERGE_HEAD"
471 then
472 refuse_partial "Cannot do a partial commit during a merge."
473 fi
474 TMP_INDEX="$GIT_DIR/tmp-index$$"
475 if test -z "$initial_commit"
476 then
477 # make sure index is clean at the specified paths, or
478 # they are additions.
479 dirty_in_index=`git-diff-index --cached --name-status \
5a798fb5 480 --diff-filter=DMTU HEAD -- "$@"`
130fcca6 481 test -z "$dirty_in_index" ||
5a798fb5 482 refuse_partial "Different in index and the last commit:
130fcca6
JH
483$dirty_in_index"
484 fi
bba319b5 485 commit_only=`git-ls-files --error-unmatch -- "$@"` || exit
cf7bb589
JH
486
487 # Build the temporary index and update the real index
488 # the same way.
489 if test -z "$initial_commit"
490 then
491 cp "$THIS_INDEX" "$TMP_INDEX"
492 GIT_INDEX_FILE="$TMP_INDEX" git-read-tree -m HEAD
493 else
494 rm -f "$TMP_INDEX"
495 fi || exit
496
497 echo "$commit_only" |
498 GIT_INDEX_FILE="$TMP_INDEX" \
499 git-update-index --add --remove --stdin &&
500
501 save_index &&
502 echo "$commit_only" |
503 (
504 GIT_INDEX_FILE="$NEXT_INDEX"
505 export GIT_INDEX_FILE
506 git-update-index --remove --stdin
507 ) || exit
508 ;;
130fcca6
JH
509 esac
510 ;;
511esac
512
cf7bb589
JH
513################################################################
514# If we do as-is commit, the index file will be THIS_INDEX,
515# otherwise NEXT_INDEX after we make this commit. We leave
516# the index as is if we abort.
130fcca6 517
cf7bb589 518if test -f "$NEXT_INDEX"
130fcca6 519then
cf7bb589
JH
520 USE_INDEX="$NEXT_INDEX"
521else
522 USE_INDEX="$THIS_INDEX"
130fcca6
JH
523fi
524
cf7bb589
JH
525GIT_INDEX_FILE="$USE_INDEX" \
526 git-update-index -q $unmerged_ok_if_status --refresh || exit
527
528################################################################
529# If the request is status, just show it and exit.
530
531case "$0" in
532*status)
533 run_status
534 exit $?
535esac
536
537################################################################
538# Grab commit message, write out tree and make commit.
539
130fcca6
JH
540if test t = "$verify" && test -x "$GIT_DIR"/hooks/pre-commit
541then
542 if test "$TMP_INDEX"
543 then
544 GIT_INDEX_FILE="$TMP_INDEX" "$GIT_DIR"/hooks/pre-commit
545 else
cf7bb589 546 GIT_INDEX_FILE="$USE_INDEX" "$GIT_DIR"/hooks/pre-commit
130fcca6
JH
547 fi || exit
548fi
0cfe1d30 549
aba2da13
JH
550if test "$log_message" != ''
551then
552 echo "$log_message"
553elif test "$logfile" != ""
554then
555 if test "$logfile" = -
556 then
557 test -t 0 &&
558 echo >&2 "(reading log message from standard input)"
559 cat
560 else
561 cat <"$logfile"
562 fi
563elif test "$use_commit" != ""
564then
565 git-cat-file commit "$use_commit" | sed -e '1,/^$/d'
e5215804
JH
566elif test -f "$GIT_DIR/MERGE_HEAD" && test -f "$GIT_DIR/MERGE_MSG"
567then
568 cat "$GIT_DIR/MERGE_MSG"
7d0c6887
JH
569elif test -f "$GIT_DIR/SQUASH_MSG"
570then
571 cat "$GIT_DIR/SQUASH_MSG"
f8e2c54c 572fi | git-stripspace >"$GIT_DIR"/COMMIT_EDITMSG
2d569933
JH
573
574case "$signoff" in
575t)
f6413391
JH
576 {
577 echo
578 git-var GIT_COMMITTER_IDENT | sed -e '
579 s/>.*/>/
580 s/^/Signed-off-by: /
581 '
f8e2c54c 582 } >>"$GIT_DIR"/COMMIT_EDITMSG
2d569933
JH
583 ;;
584esac
585
475443c8 586if test -f "$GIT_DIR/MERGE_HEAD" && test -z "$no_edit"; then
2d569933 587 echo "#"
b6ae5409 588 echo "# It looks like you may be committing a MERGE."
2d569933
JH
589 echo "# If this is not correct, please remove the file"
590 echo "# $GIT_DIR/MERGE_HEAD"
591 echo "# and try again"
592 echo "#"
f8e2c54c 593fi >>"$GIT_DIR"/COMMIT_EDITMSG
aba2da13 594
130fcca6 595# Author
5a798fb5
JH
596if test '' != "$force_author"
597then
f327dbce
MW
598 GIT_AUTHOR_NAME=`expr "z$force_author" : 'z\(.*[^ ]\) *<.*'` &&
599 GIT_AUTHOR_EMAIL=`expr "z$force_author" : '.*\(<.*\)'` &&
5a798fb5
JH
600 test '' != "$GIT_AUTHOR_NAME" &&
601 test '' != "$GIT_AUTHOR_EMAIL" ||
602 die "malformatted --author parameter"
603 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
604elif test '' != "$use_commit"
130fcca6
JH
605then
606 pick_author_script='
607 /^author /{
608 s/'\''/'\''\\'\'\''/g
609 h
610 s/^author \([^<]*\) <[^>]*> .*$/\1/
611 s/'\''/'\''\'\'\''/g
612 s/.*/GIT_AUTHOR_NAME='\''&'\''/p
613
614 g
615 s/^author [^<]* <\([^>]*\)> .*$/\1/
616 s/'\''/'\''\'\'\''/g
617 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
618
619 g
620 s/^author [^<]* <[^>]*> \(.*\)$/\1/
621 s/'\''/'\''\'\'\''/g
622 s/.*/GIT_AUTHOR_DATE='\''&'\''/p
623
624 q
625 }
626 '
627 set_author_env=`git-cat-file commit "$use_commit" |
628 LANG=C LC_ALL=C sed -ne "$pick_author_script"`
629 eval "$set_author_env"
630 export GIT_AUTHOR_NAME
631 export GIT_AUTHOR_EMAIL
632 export GIT_AUTHOR_DATE
130fcca6
JH
633fi
634
96069cf0 635PARENTS="-p HEAD"
130fcca6 636if test -z "$initial_commit"
8098a178 637then
5fec3ef1 638 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
91063bbc 639 PARENTS="-p HEAD "`sed -e 's/^/-p /' "$GIT_DIR/MERGE_HEAD"`
b4019f04
JH
640 elif test -n "$amend"; then
641 PARENTS=$(git-cat-file commit HEAD |
642 sed -n -e '/^$/q' -e 's/^parent /-p /p')
aba2da13 643 fi
b8310152 644 current=$(git-rev-parse --verify HEAD)
8098a178
JH
645else
646 if [ -z "$(git-ls-files)" ]; then
5a798fb5 647 echo >&2 Nothing to commit
8098a178
JH
648 exit 1
649 fi
650 PARENTS=""
b8310152 651 current=
96069cf0 652fi
130fcca6 653
475443c8
JH
654if test -z "$no_edit"
655then
656 {
88a15314
MW
657 echo ""
658 echo "# Please enter the commit message for your changes."
659 echo "# (Comment lines starting with '#' will not be included)"
475443c8
JH
660 test -z "$only_include_assumed" || echo "$only_include_assumed"
661 run_status
662 } >>"$GIT_DIR"/COMMIT_EDITMSG
663else
664 # we need to check if there is anything to commit
665 run_status >/dev/null
666fi
8588452c 667if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" -a -z "$amend" ]
a3e870f2 668then
7d0c6887 669 rm -f "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
5a798fb5 670 run_status
a3e870f2
LT
671 exit 1
672fi
475443c8 673
0c091296 674case "$no_edit" in
5fec3ef1 675'')
7334f06c
JH
676 case "${VISUAL:-$EDITOR},$TERM" in
677 ,dumb)
678 echo >&2 "Terminal is dumb but no VISUAL nor EDITOR defined."
679 echo >&2 "Please supply the commit log message using either"
680 echo >&2 "-m or -F option. A boilerplate log message has"
681 echo >&2 "been prepared in $GIT_DIR/COMMIT_EDITMSG"
130fcca6
JH
682 exit 1
683 ;;
7334f06c 684 esac
ec4e69c0
SE
685 git-var GIT_AUTHOR_IDENT > /dev/null || die
686 git-var GIT_COMMITTER_IDENT > /dev/null || die
f8e2c54c 687 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG"
5fec3ef1
JH
688 ;;
689esac
89e2c5f1
JH
690
691case "$verify" in
692t)
693 if test -x "$GIT_DIR"/hooks/commit-msg
694 then
f8e2c54c 695 "$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/COMMIT_EDITMSG || exit
89e2c5f1
JH
696 fi
697esac
698
29f4ad86
YD
699if test -z "$no_edit"
700then
701 sed -e '
702 /^diff --git a\/.*/{
703 s///
704 q
705 }
706 /^#/d
707 ' "$GIT_DIR"/COMMIT_EDITMSG
708else
709 cat "$GIT_DIR"/COMMIT_EDITMSG
710fi |
cf7bb589 711git-stripspace >"$GIT_DIR"/COMMIT_MSG
f8e2c54c
SB
712
713if cnt=`grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG |
714 git-stripspace |
715 wc -l` &&
716 test 0 -lt $cnt
0c091296 717then
130fcca6
JH
718 if test -z "$TMP_INDEX"
719 then
cf7bb589 720 tree=$(GIT_INDEX_FILE="$USE_INDEX" git-write-tree)
130fcca6
JH
721 else
722 tree=$(GIT_INDEX_FILE="$TMP_INDEX" git-write-tree) &&
723 rm -f "$TMP_INDEX"
724 fi &&
f8e2c54c 725 commit=$(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree $tree $PARENTS) &&
67644a4d
SP
726 rlogm=$(sed -e 1q "$GIT_DIR"/COMMIT_MSG) &&
727 git-update-ref -m "commit: $rlogm" HEAD $commit $current &&
cf7bb589
JH
728 rm -f -- "$GIT_DIR/MERGE_HEAD" &&
729 if test -f "$NEXT_INDEX"
730 then
731 mv "$NEXT_INDEX" "$THIS_INDEX"
732 else
733 : ;# happy
734 fi
0c091296
JH
735else
736 echo >&2 "* no commit message? aborting commit."
737 false
738fi
170241b7 739ret="$?"
7d0c6887 740rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
1536dd9c
JH
741if test -d "$GIT_DIR/rr-cache"
742then
743 git-rerere
744fi
89e2c5f1
JH
745
746if test -x "$GIT_DIR"/hooks/post-commit && test "$ret" = 0
747then
748 "$GIT_DIR"/hooks/post-commit
749fi
170241b7 750exit "$ret"