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
11 branch
=$
(GIT_DIR
="$GIT_DIR" git-symbolic-ref HEAD
)
16 unmerged_ok_if_status
=--unmerged ;;
19 unmerged_ok_if_status
= ;;
24 echo >&2 "You might have meant to say 'git commit -i paths...', perhaps?"
28 THIS_INDEX
="$GIT_DIR/index"
29 NEXT_INDEX
="$GIT_DIR/next-index$$"
32 cp "$THIS_INDEX" "$NEXT_INDEX"
42 while read status name newname
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";;
58 printf '%s' "$trailer"
64 # We always show status for the whole tree.
67 IS_INITIAL
="$initial_commit"
71 # If we are amending the initial commit, there
73 if git-rev-parse
--verify "HEAD^1" >/dev
/null
2>&1
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"
91 GIT_INDEX_FILE
="$TMP_INDEX"
93 elif test -f "$NEXT_INDEX"
95 GIT_INDEX_FILE
="$NEXT_INDEX"
100 refs
/heads
/master
) ;;
101 *) echo "# On branch $branch" ;;
104 if test -z "$IS_INITIAL"
106 git-diff-index
-M --cached --name-status \
107 --diff-filter=MDTCRA
$REFERENCE |
112 report
"Updated but not checked in" "will commit"
124 report
"Updated but not checked in" "will commit"
129 git-diff-files
--name-status |
134 report
"Changed but not updated" \
135 "use git-update-index to mark for commit"
138 if test -z "$untracked_files"; then
139 option
="--directory --no-empty-directory"
141 if test -f "$GIT_DIR/info/exclude"
143 git-ls-files
-z --others $option \
144 --exclude-from="$GIT_DIR/info/exclude" \
145 --exclude-per-directory=.gitignore
147 git-ls-files
-z --others $option \
148 --exclude-per-directory=.gitignore
159 print "#\n# Untracked files:\n";
160 print "# (use \"git add\" to add to commit)\n";
168 if test -n "$verbose" -a -z "$IS_INITIAL"
170 git-diff-index
--cached -M -p --diff-filter=MDTCRA
$REFERENCE
172 case "$committable" in
176 echo "# No changes" ;;
178 echo "nothing to commit" ;;
187 test -z "$TMP_INDEX" || {
188 test -f "$TMP_INDEX" && rm -f "$TMP_INDEX"
193 ################################################################
194 # Command line argument parsing and sanity checking
209 only_include_assumed
=
211 while case "$#" in 0) break;; esac
214 -F|
--F|
-f|
--f|
--fi|
--fil|
--file)
215 case "$#" in 1) usage
;; esac
218 log_given
=t
$log_given
224 log_given
=t
$log_given
225 logfile
=`expr "$1" : '-[Ff]\(.*\)'`
228 --F=*|
--f=*|
--fi=*|
--fil=*|
--file=*)
230 log_given
=t
$log_given
231 logfile
=`expr "$1" : '-[^=]*=\(.*\)'`
238 --au=*|
--aut=*|
--auth=*|
--autho=*|
--author=*)
239 force_author
=`expr "$1" : '-[^=]*=\(.*\)'`
242 --au|
--aut|
--auth|
--autho|
--author)
243 case "$#" in 1) usage
;; esac
248 -e|
--e|
--ed|
--edi|
--edit)
252 -i|
--i|
--in|
--inc|
--incl|
--inclu|
--includ|
--include)
256 -o|
--o|
--on|
--onl|
--only)
260 -m|
--m|
--me|
--mes|
--mess|
--messa|
--messag|
--message)
261 case "$#" in 1) usage
;; esac
263 log_given
=t
$log_given
269 log_given
=t
$log_given
270 log_message
=`expr "$1" : '-m\(.*\)'`
274 --m=*|
--me=*|
--mes=*|
--mess=*|
--messa=*|
--messag=*|
--message=*)
275 log_given
=t
$log_given
276 log_message
=`expr "$1" : '-[^=]*=\(.*\)'`
280 -n|
--n|
--no|
--no-|
--no-v|
--no-ve|
--no-ver|
--no-veri|
--no-verif|
--no-verify)
284 --a|
--am|
--ame|
--amen|
--amend)
286 log_given
=t
$log_given
291 case "$#" in 1) usage
;; esac
293 log_given
=t
$log_given
298 --ree=*|
--reed=*|
--reedi=*|
--reedit=*|
--reedit-=*|
--reedit-m=*|\
299 --reedit-me=*|
--reedit-mes=*|
--reedit-mess=*|
--reedit-messa=*|\
300 --reedit-messag=*|
--reedit-message=*)
301 log_given
=t
$log_given
302 use_commit
=`expr "$1" : '-[^=]*=\(.*\)'`
306 --ree|
--reed|
--reedi|
--reedit|
--reedit-|
--reedit-m|
--reedit-me|\
307 --reedit-mes|
--reedit-mess|
--reedit-messa|
--reedit-messag|
--reedit-message)
308 case "$#" in 1) usage
;; esac
310 log_given
=t
$log_given
316 case "$#" in 1) usage
;; esac
318 log_given
=t
$log_given
323 --reu=*|
--reus=*|
--reuse=*|
--reuse-=*|
--reuse-m=*|
--reuse-me=*|\
324 --reuse-mes=*|
--reuse-mess=*|
--reuse-messa=*|
--reuse-messag=*|\
326 log_given
=t
$log_given
327 use_commit
=`expr "$1" : '-[^=]*=\(.*\)'`
331 --reu|
--reus|
--reuse|
--reuse-|
--reuse-m|
--reuse-me|
--reuse-mes|\
332 --reuse-mess|
--reuse-messa|
--reuse-messag|
--reuse-message)
333 case "$#" in 1) usage
;; esac
335 log_given
=t
$log_given
340 -s|
--s|
--si|
--sig|
--sign|
--signo|
--signof|
--signoff)
344 -v|
--v|
--ve|
--ver|
--verb|
--verbo|
--verbos|
--verbose)
348 -u|
--u|
--un|
--unt|
--untr|
--untra|
--untrac|
--untrack|
--untracke|
--untracked|\
349 --untracked-|
--untracked-f|
--untracked-fi|
--untracked-fil|
--untracked-file|\
367 ################################################################
368 # Sanity check options
370 case "$amend,$initial_commit" in
372 die
"You do not have anything to amend." ;;
374 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
375 die
"You are in the middle of a merge -- cannot amend."
381 die
"Only one of -c/-C/-F/-m can be used." ;;
384 case "$#,$also,$only,$amend" in
386 die
"Only one of --include/--only can be used." ;;
388 die
"No paths with --include/--only does not make sense." ;;
390 only_include_assumed
="# Clever... amending the last one with dirty index." ;;
394 only_include_assumed
="# Explicit paths specified without -i nor -o; assuming --only paths..."
399 case "$all,$also,$#" in
401 die
"Cannot use -a and -i at the same time." ;;
403 die
"Paths with -a does not make sense." ;;
405 die
"No paths with -i does not make sense." ;;
408 ################################################################
409 # Prepare index to have a tree to be committed
411 TOP
=`git-rev-parse --show-cdup`
422 GIT_INDEX_FILE
="$NEXT_INDEX"
423 export GIT_INDEX_FILE
424 git-diff-files
--name-only -z |
425 git-update-index
--remove -z --stdin
430 git-ls-files
--error-unmatch -- "$@" >/dev
/null ||
exit
432 git-diff-files
--name-only -z -- "$@" |
435 GIT_INDEX_FILE
="$NEXT_INDEX"
436 export GIT_INDEX_FILE
437 git-update-index
--remove -z --stdin
445 if test -f "$GIT_DIR/MERGE_HEAD"
447 refuse_partial
"Cannot do a partial commit during a merge."
449 TMP_INDEX
="$GIT_DIR/tmp-index$$"
450 if test -z "$initial_commit"
452 # make sure index is clean at the specified paths, or
453 # they are additions.
454 dirty_in_index
=`git-diff-index --cached --name-status \
455 --diff-filter=DMTU HEAD -- "$@"`
456 test -z "$dirty_in_index" ||
457 refuse_partial
"Different in index and the last commit:
460 commit_only
=`git-ls-files --error-unmatch -- "$@"` ||
exit
462 # Build the temporary index and update the real index
464 if test -z "$initial_commit"
466 cp "$THIS_INDEX" "$TMP_INDEX"
467 GIT_INDEX_FILE
="$TMP_INDEX" git-read-tree
-m HEAD
472 echo "$commit_only" |
473 GIT_INDEX_FILE
="$TMP_INDEX" \
474 git-update-index
--add --remove --stdin &&
477 echo "$commit_only" |
479 GIT_INDEX_FILE
="$NEXT_INDEX"
480 export GIT_INDEX_FILE
481 git-update-index
--remove --stdin
488 ################################################################
489 # If we do as-is commit, the index file will be THIS_INDEX,
490 # otherwise NEXT_INDEX after we make this commit. We leave
491 # the index as is if we abort.
493 if test -f "$NEXT_INDEX"
495 USE_INDEX
="$NEXT_INDEX"
497 USE_INDEX
="$THIS_INDEX"
500 GIT_INDEX_FILE
="$USE_INDEX" \
501 git-update-index
-q $unmerged_ok_if_status --refresh ||
exit
503 ################################################################
504 # If the request is status, just show it and exit.
512 ################################################################
513 # Grab commit message, write out tree and make commit.
515 if test t
= "$verify" && test -x "$GIT_DIR"/hooks
/pre-commit
519 GIT_INDEX_FILE
="$TMP_INDEX" "$GIT_DIR"/hooks
/pre-commit
521 GIT_INDEX_FILE
="$USE_INDEX" "$GIT_DIR"/hooks
/pre-commit
525 if test "$log_message" != ''
528 elif test "$logfile" != ""
530 if test "$logfile" = -
533 echo >&2 "(reading log message from standard input)"
538 elif test "$use_commit" != ""
540 git-cat-file commit
"$use_commit" |
sed -e '1,/^$/d'
541 elif test -f "$GIT_DIR/MERGE_HEAD" && test -f "$GIT_DIR/MERGE_MSG"
543 cat "$GIT_DIR/MERGE_MSG"
544 fi | git-stripspace
>"$GIT_DIR"/COMMIT_EDITMSG
550 git-var GIT_COMMITTER_IDENT |
sed -e '
554 } >>"$GIT_DIR"/COMMIT_EDITMSG
558 if test -f "$GIT_DIR/MERGE_HEAD" && test -z "$no_edit"; then
560 echo "# It looks like you may be committing a MERGE."
561 echo "# If this is not correct, please remove the file"
562 echo "# $GIT_DIR/MERGE_HEAD"
563 echo "# and try again"
565 fi >>"$GIT_DIR"/COMMIT_EDITMSG
568 if test '' != "$force_author"
570 GIT_AUTHOR_NAME
=`expr "z$force_author" : 'z\(.*[^ ]\) *<.*'` &&
571 GIT_AUTHOR_EMAIL
=`expr "z$force_author" : '.*\(<.*\)'` &&
572 test '' != "$GIT_AUTHOR_NAME" &&
573 test '' != "$GIT_AUTHOR_EMAIL" ||
574 die
"malformatted --author parameter"
575 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
576 elif test '' != "$use_commit"
580 s/'\''/'\''\\'\'\''/g
582 s/^author \([^<]*\) <[^>]*> .*$/\1/
584 s
/.
*/GIT_AUTHOR_NAME
='\''&'\''/p
587 s
/^author
[^
<]* <\
([^
>]*\
)> .
*$
/\
1/
589 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
592 s/^author [^<]* <[^>]*> \(.*\)$/\1/
594 s
/.
*/GIT_AUTHOR_DATE
='\''&'\''/p
599 set_author_env=`git-cat-file commit "$use_commit" |
600 LANG=C LC_ALL=C sed -ne "$pick_author_script"`
601 eval "$set_author_env"
602 export GIT_AUTHOR_NAME
603 export GIT_AUTHOR_EMAIL
604 export GIT_AUTHOR_DATE
608 if test -z "$initial_commit"
610 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
611 PARENTS="-p HEAD "`sed -e 's
/^
/-p /' "$GIT_DIR/MERGE_HEAD"`
612 elif test -n "$amend"; then
613 PARENTS=$(git-cat-file commit HEAD |
614 sed -n -e '/^$
/q
' -e 's
/^parent
/-p /p
')
616 current=$(git-rev-parse --verify HEAD)
618 if [ -z "$(git-ls-files)" ]; then
619 echo >&2 Nothing to commit
626 if test -z "$no_edit"
629 test -z "$only_include_assumed" || echo "$only_include_assumed"
631 } >>"$GIT_DIR"/COMMIT_EDITMSG
633 # we need to check if there is anything to commit
634 run_status >/dev/null
636 if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" -a -z "$amend" ]
638 rm -f "$GIT_DIR/COMMIT_EDITMSG"
645 case "${VISUAL:-$EDITOR},$TERM" in
647 echo >&2 "Terminal is dumb but no VISUAL nor EDITOR defined."
648 echo >&2 "Please supply the commit log message using either"
649 echo >&2 "-m or -F option. A boilerplate log message has"
650 echo >&2 "been prepared in $GIT_DIR/COMMIT_EDITMSG"
654 git-var GIT_AUTHOR_IDENT > /dev/null || die
655 git-var GIT_COMMITTER_IDENT > /dev/null || die
656 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG"
662 if test -x "$GIT_DIR"/hooks/commit-msg
664 "$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/COMMIT_EDITMSG || exit
674 ' "$GIT_DIR"/COMMIT_EDITMSG |
675 git-stripspace >"$GIT_DIR"/COMMIT_MSG
677 if cnt=`grep -v -i '^Signed-off-by
' "$GIT_DIR"/COMMIT_MSG |
682 if test -z "$TMP_INDEX"
684 tree=$(GIT_INDEX_FILE="$USE_INDEX" git-write-tree)
686 tree=$(GIT_INDEX_FILE="$TMP_INDEX" git-write-tree) &&
689 commit=$(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree $tree $PARENTS) &&
690 git-update-ref HEAD $commit $current &&
691 rm -f -- "$GIT_DIR/MERGE_HEAD" &&
692 if test -f "$NEXT_INDEX"
694 mv "$NEXT_INDEX" "$THIS_INDEX"
699 echo >&2 "* no commit message? aborting commit."
703 rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG"
704 if test -d "$GIT_DIR/rr-cache"
709 if test -x "$GIT_DIR"/hooks/post-commit && test "$ret" = 0
711 "$GIT_DIR"/hooks/post-commit