3 # Copyright (c) 2005 Linus Torvalds
4 # Copyright (c) 2006 Junio C Hamano
6 USAGE
='[-a] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit>] [-u] [--amend] [-e] [--author <author>] [[-i | -o] <path>...]'
10 git-rev-parse
--verify HEAD
>/dev
/null
2>&1 || initial_commit
=t
15 unmerged_ok_if_status
=--unmerged ;;
18 unmerged_ok_if_status
= ;;
23 echo >&2 "You might have meant to say 'git commit -i paths...', perhaps?"
27 THIS_INDEX
="$GIT_DIR/index"
28 NEXT_INDEX
="$GIT_DIR/next-index$$"
31 cp -p "$THIS_INDEX" "$NEXT_INDEX"
35 # If TMP_INDEX is defined, that means we are doing
36 # "--only" partial commit, and that index file is used
37 # to build the tree for the commit. Otherwise, if
38 # NEXT_INDEX exists, that is the index file used to
39 # make the commit. Otherwise we are using as-is commit
40 # so the regular index file is what we use to compare.
41 if test '' != "$TMP_INDEX"
43 GIT_INDEX_FILE
="$TMP_INDEX"
45 elif test -f "$NEXT_INDEX"
47 GIT_INDEX_FILE
="$NEXT_INDEX"
51 case "$status_only" in
55 git-runstatus
${color} \
56 ${verbose:+--verbose} \
58 ${untracked_files:+--untracked}
62 test -z "$TMP_INDEX" || {
63 test -f "$TMP_INDEX" && rm -f "$TMP_INDEX"
68 ################################################################
69 # Command line argument parsing and sanity checking
88 while case "$#" in 0) break;; esac
91 -F|
--F|
-f|
--f|
--fi|
--fil|
--file)
92 case "$#" in 1) usage
;; esac
101 log_given
=t
$log_given
102 logfile
=`expr "z$1" : 'z-[Ff]\(.*\)'`
105 --F=*|
--f=*|
--fi=*|
--fil=*|
--file=*)
107 log_given
=t
$log_given
108 logfile
=`expr "z$1" : 'z-[^=]*=\(.*\)'`
115 --au=*|
--aut=*|
--auth=*|
--autho=*|
--author=*)
116 force_author
=`expr "z$1" : 'z-[^=]*=\(.*\)'`
119 --au|
--aut|
--auth|
--autho|
--author)
120 case "$#" in 1) usage
;; esac
125 -e|
--e|
--ed|
--edi|
--edit)
129 -i|
--i|
--in|
--inc|
--incl|
--inclu|
--includ|
--include)
133 -o|
--o|
--on|
--onl|
--only)
137 -m|
--m|
--me|
--mes|
--mess|
--messa|
--messag|
--message)
138 case "$#" in 1) usage
;; esac
140 log_given
=m
$log_given
141 if test "$log_message" = ''
145 log_message
="$log_message
153 log_given
=m
$log_given
154 if test "$log_message" = ''
156 log_message
=`expr "z$1" : 'z-m\(.*\)'`
158 log_message
="$log_message
160 `expr "z
$1" : 'z-m\(.*\)'`"
165 --m=*|
--me=*|
--mes=*|
--mess=*|
--messa=*|
--messag=*|
--message=*)
166 log_given
=m
$log_given
167 if test "$log_message" = ''
169 log_message
=`expr "z$1" : 'z-[^=]*=\(.*\)'`
171 log_message
="$log_message
173 `expr "z
$1" : 'zq-[^=]*=\(.*\)'`"
178 -n|
--n|
--no|
--no-|
--no-v|
--no-ve|
--no-ver|
--no-veri|
--no-verif|\
183 --a|
--am|
--ame|
--amen|
--amend)
185 log_given
=t
$log_given
190 case "$#" in 1) usage
;; esac
192 log_given
=t
$log_given
197 --ree=*|
--reed=*|
--reedi=*|
--reedit=*|
--reedit-=*|
--reedit-m=*|\
198 --reedit-me=*|
--reedit-mes=*|
--reedit-mess=*|
--reedit-messa=*|\
199 --reedit-messag=*|
--reedit-message=*)
200 log_given
=t
$log_given
201 use_commit
=`expr "z$1" : 'z-[^=]*=\(.*\)'`
205 --ree|
--reed|
--reedi|
--reedit|
--reedit-|
--reedit-m|
--reedit-me|\
206 --reedit-mes|
--reedit-mess|
--reedit-messa|
--reedit-messag|\
208 case "$#" in 1) usage
;; esac
210 log_given
=t
$log_given
216 case "$#" in 1) usage
;; esac
218 log_given
=t
$log_given
223 --reu=*|
--reus=*|
--reuse=*|
--reuse-=*|
--reuse-m=*|
--reuse-me=*|\
224 --reuse-mes=*|
--reuse-mess=*|
--reuse-messa=*|
--reuse-messag=*|\
226 log_given
=t
$log_given
227 use_commit
=`expr "z$1" : 'z-[^=]*=\(.*\)'`
231 --reu|
--reus|
--reuse|
--reuse-|
--reuse-m|
--reuse-me|
--reuse-mes|\
232 --reuse-mess|
--reuse-messa|
--reuse-messag|
--reuse-message)
233 case "$#" in 1) usage
;; esac
235 log_given
=t
$log_given
240 -s|
--s|
--si|
--sig|
--sign|
--signo|
--signof|
--signoff)
244 -q|
--q|
--qu|
--qui|
--quie|
--quiet)
248 -v|
--v|
--ve|
--ver|
--verb|
--verbo|
--verbos|
--verbose)
252 -u|
--u|
--un|
--unt|
--untr|
--untra|
--untrac|
--untrack|
--untracke|\
253 --untracked|
--untracked-|
--untracked-f|
--untracked-fi|
--untracked-fil|\
254 --untracked-file|
--untracked-files)
270 case "$edit_flag" in t
) no_edit
= ;; esac
272 ################################################################
273 # Sanity check options
275 case "$amend,$initial_commit" in
277 die
"You do not have anything to amend." ;;
279 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
280 die
"You are in the middle of a merge -- cannot amend."
286 die
"Only one of -c/-C/-F can be used." ;;
288 die
"Option -m cannot be combined with -c/-C/-F." ;;
291 case "$#,$also,$only,$amend" in
293 die
"Only one of --include/--only can be used." ;;
295 die
"No paths with --include/--only does not make sense." ;;
297 only_include_assumed
="# Clever... amending the last one with dirty index." ;;
301 only_include_assumed
="# Explicit paths specified without -i nor -o; assuming --only paths..."
306 case "$all,$also,$#" in
308 die
"Cannot use -a and -i at the same time." ;;
310 die
"Paths with -a does not make sense." ;;
312 die
"No paths with -i does not make sense." ;;
315 ################################################################
316 # Prepare index to have a tree to be committed
318 TOP
=`git-rev-parse --show-cdup`
329 GIT_INDEX_FILE
="$NEXT_INDEX"
330 export GIT_INDEX_FILE
331 git-diff-files
--name-only -z |
332 git-update-index
--remove -z --stdin
337 git-ls-files
--error-unmatch -- "$@" >/dev
/null ||
exit
339 git-diff-files
--name-only -z -- "$@" |
342 GIT_INDEX_FILE
="$NEXT_INDEX"
343 export GIT_INDEX_FILE
344 git-update-index
--remove -z --stdin
352 if test -f "$GIT_DIR/MERGE_HEAD"
354 refuse_partial
"Cannot do a partial commit during a merge."
356 TMP_INDEX
="$GIT_DIR/tmp-index$$"
357 commit_only
=`git-ls-files --error-unmatch -- "$@"` ||
exit
359 # Build a temporary index and update the real index
361 if test -z "$initial_commit"
363 cp "$THIS_INDEX" "$TMP_INDEX"
364 GIT_INDEX_FILE
="$TMP_INDEX" git-read-tree
-m HEAD
369 echo "$commit_only" |
370 GIT_INDEX_FILE
="$TMP_INDEX" \
371 git-update-index
--add --remove --stdin &&
374 echo "$commit_only" |
376 GIT_INDEX_FILE
="$NEXT_INDEX"
377 export GIT_INDEX_FILE
378 git-update-index
--remove --stdin
385 ################################################################
386 # If we do as-is commit, the index file will be THIS_INDEX,
387 # otherwise NEXT_INDEX after we make this commit. We leave
388 # the index as is if we abort.
390 if test -f "$NEXT_INDEX"
392 USE_INDEX
="$NEXT_INDEX"
394 USE_INDEX
="$THIS_INDEX"
397 GIT_INDEX_FILE
="$USE_INDEX" \
398 git-update-index
-q $unmerged_ok_if_status --refresh ||
exit
400 ################################################################
401 # If the request is status, just show it and exit.
409 ################################################################
410 # Grab commit message, write out tree and make commit.
412 if test t
= "$verify" && test -x "$GIT_DIR"/hooks
/pre-commit
416 GIT_INDEX_FILE
="$TMP_INDEX" "$GIT_DIR"/hooks
/pre-commit
418 GIT_INDEX_FILE
="$USE_INDEX" "$GIT_DIR"/hooks
/pre-commit
422 if test "$log_message" != ''
425 elif test "$logfile" != ""
427 if test "$logfile" = -
430 echo >&2 "(reading log message from standard input)"
435 elif test "$use_commit" != ""
437 git-cat-file commit
"$use_commit" |
sed -e '1,/^$/d'
438 elif test -f "$GIT_DIR/MERGE_MSG"
440 cat "$GIT_DIR/MERGE_MSG"
441 elif test -f "$GIT_DIR/SQUASH_MSG"
443 cat "$GIT_DIR/SQUASH_MSG"
444 fi | git-stripspace
>"$GIT_DIR"/COMMIT_EDITMSG
450 git-var GIT_COMMITTER_IDENT |
sed -e '
454 } >>"$GIT_DIR"/COMMIT_EDITMSG
458 if test -f "$GIT_DIR/MERGE_HEAD" && test -z "$no_edit"; then
460 echo "# It looks like you may be committing a MERGE."
461 echo "# If this is not correct, please remove the file"
462 echo "# $GIT_DIR/MERGE_HEAD"
463 echo "# and try again"
465 fi >>"$GIT_DIR"/COMMIT_EDITMSG
468 if test '' != "$force_author"
470 GIT_AUTHOR_NAME
=`expr "z$force_author" : 'z\(.*[^ ]\) *<.*'` &&
471 GIT_AUTHOR_EMAIL
=`expr "z$force_author" : '.*\(<.*\)'` &&
472 test '' != "$GIT_AUTHOR_NAME" &&
473 test '' != "$GIT_AUTHOR_EMAIL" ||
474 die
"malformed --author parameter"
475 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
476 elif test '' != "$use_commit"
480 s/'\''/'\''\\'\'\''/g
482 s/^author \([^<]*\) <[^>]*> .*$/\1/
484 s
/.
*/GIT_AUTHOR_NAME
='\''&'\''/p
487 s
/^author
[^
<]* <\
([^
>]*\
)> .
*$
/\
1/
489 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
492 s/^author [^<]* <[^>]*> \(.*\)$/\1/
494 s
/.
*/GIT_AUTHOR_DATE
='\''&'\''/p
499 set_author_env=`git-cat-file commit "$use_commit" |
500 LANG=C LC_ALL=C sed -ne "$pick_author_script"`
501 eval "$set_author_env"
502 export GIT_AUTHOR_NAME
503 export GIT_AUTHOR_EMAIL
504 export GIT_AUTHOR_DATE
508 if test -z "$initial_commit"
511 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
512 rloga='commit
(merge
)'
513 PARENTS="-p HEAD "`sed -e 's
/^
/-p /' "$GIT_DIR/MERGE_HEAD"`
514 elif test -n "$amend"; then
515 rloga='commit
(amend
)'
516 PARENTS=$(git-cat-file commit HEAD |
517 sed -n -e '/^$
/q
' -e 's
/^parent
/-p /p
')
519 current="$(git-rev-parse --verify HEAD)"
521 if [ -z "$(git-ls-files)" ]; then
522 echo >&2 'nothing to commit
(use
"git add file1 file2" to include
for commit
)'
526 rloga='commit
(initial
)'
530 if test -z "$no_edit"
534 echo "# Please enter the commit message for your changes."
535 echo "# (Comment lines starting with '#' will not be included)"
536 test -z "$only_include_assumed" ||
echo "$only_include_assumed"
538 } >>"$GIT_DIR"/COMMIT_EDITMSG
540 # we need to check if there is anything to commit
541 run_status
>/dev
/null
543 if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" -a -z "$amend" ]
545 rm -f "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
552 case "${VISUAL:-$EDITOR},$TERM" in
554 echo >&2 "Terminal is dumb but no VISUAL nor EDITOR defined."
555 echo >&2 "Please supply the commit log message using either"
556 echo >&2 "-m or -F option. A boilerplate log message has"
557 echo >&2 "been prepared in $GIT_DIR/COMMIT_EDITMSG"
561 git-var GIT_AUTHOR_IDENT
> /dev
/null || die
562 git-var GIT_COMMITTER_IDENT
> /dev
/null || die
563 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG"
569 if test -x "$GIT_DIR"/hooks
/commit-msg
571 "$GIT_DIR"/hooks
/commit-msg
"$GIT_DIR"/COMMIT_EDITMSG ||
exit
575 if test -z "$no_edit"
583 ' "$GIT_DIR"/COMMIT_EDITMSG
585 cat "$GIT_DIR"/COMMIT_EDITMSG
587 git-stripspace
>"$GIT_DIR"/COMMIT_MSG
589 if cnt
=`grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG |
594 if test -z "$TMP_INDEX"
596 tree
=$
(GIT_INDEX_FILE
="$USE_INDEX" git-write-tree
)
598 tree
=$
(GIT_INDEX_FILE
="$TMP_INDEX" git-write-tree
) &&
601 commit
=$
(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree
$tree $PARENTS) &&
602 rlogm
=$
(sed -e 1q
"$GIT_DIR"/COMMIT_MSG
) &&
603 git-update-ref
-m "$rloga: $rlogm" HEAD
$commit "$current" &&
604 rm -f -- "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/MERGE_MSG" &&
605 if test -f "$NEXT_INDEX"
607 mv "$NEXT_INDEX" "$THIS_INDEX"
612 echo >&2 "* no commit message? aborting commit."
616 rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
617 if test -d "$GIT_DIR/rr-cache"
624 if test -x "$GIT_DIR"/hooks
/post-commit
626 "$GIT_DIR"/hooks
/post-commit
630 echo "Created${initial_commit:+ initial} commit $commit"
631 git-diff-tree
--shortstat --summary --root --no-commit-id HEAD