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 -p "$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"
142 if test -f "$GIT_DIR/info/exclude"
144 git-ls-files
--others $option \
145 --exclude-from="$GIT_DIR/info/exclude" \
146 --exclude-per-directory=.gitignore
148 git-ls-files
--others $option \
149 --exclude-per-directory=.gitignore
152 if [ -z "$hdr_shown" ]; then
154 echo '# Untracked files:'
155 echo '# (use "git add" to add to commit)'
162 if test -n "$verbose" -a -z "$IS_INITIAL"
164 git-diff-index
--cached -M -p --diff-filter=MDTCRA
$REFERENCE
166 case "$committable" in
170 echo "# No changes" ;;
172 echo "nothing to commit" ;;
181 test -z "$TMP_INDEX" || {
182 test -f "$TMP_INDEX" && rm -f "$TMP_INDEX"
187 ################################################################
188 # Command line argument parsing and sanity checking
204 only_include_assumed
=
206 while case "$#" in 0) break;; esac
209 -F|
--F|
-f|
--f|
--fi|
--fil|
--file)
210 case "$#" in 1) usage
;; esac
213 log_given
=t
$log_given
219 log_given
=t
$log_given
220 logfile
=`expr "z$1" : 'z-[Ff]\(.*\)'`
223 --F=*|
--f=*|
--fi=*|
--fil=*|
--file=*)
225 log_given
=t
$log_given
226 logfile
=`expr "z$1" : 'z-[^=]*=\(.*\)'`
233 --au=*|
--aut=*|
--auth=*|
--autho=*|
--author=*)
234 force_author
=`expr "z$1" : 'z-[^=]*=\(.*\)'`
237 --au|
--aut|
--auth|
--autho|
--author)
238 case "$#" in 1) usage
;; esac
243 -e|
--e|
--ed|
--edi|
--edit)
247 -i|
--i|
--in|
--inc|
--incl|
--inclu|
--includ|
--include)
251 -o|
--o|
--on|
--onl|
--only)
255 -m|
--m|
--me|
--mes|
--mess|
--messa|
--messag|
--message)
256 case "$#" in 1) usage
;; esac
258 log_given
=m
$log_given
259 if test "$log_message" = ''
263 log_message
="$log_message
271 log_given
=m
$log_given
272 if test "$log_message" = ''
274 log_message
=`expr "z$1" : 'z-m\(.*\)'`
276 log_message
="$log_message
278 `expr "z
$1" : 'z-m\(.*\)'`"
283 --m=*|
--me=*|
--mes=*|
--mess=*|
--messa=*|
--messag=*|
--message=*)
284 log_given
=m
$log_given
285 if test "$log_message" = ''
287 log_message
=`expr "z$1" : 'z-[^=]*=\(.*\)'`
289 log_message
="$log_message
291 `expr "z
$1" : 'zq-[^=]*=\(.*\)'`"
296 -n|
--n|
--no|
--no-|
--no-v|
--no-ve|
--no-ver|
--no-veri|
--no-verif|
--no-verify)
300 --a|
--am|
--ame|
--amen|
--amend)
302 log_given
=t
$log_given
307 case "$#" in 1) usage
;; esac
309 log_given
=t
$log_given
314 --ree=*|
--reed=*|
--reedi=*|
--reedit=*|
--reedit-=*|
--reedit-m=*|\
315 --reedit-me=*|
--reedit-mes=*|
--reedit-mess=*|
--reedit-messa=*|\
316 --reedit-messag=*|
--reedit-message=*)
317 log_given
=t
$log_given
318 use_commit
=`expr "z$1" : 'z-[^=]*=\(.*\)'`
322 --ree|
--reed|
--reedi|
--reedit|
--reedit-|
--reedit-m|
--reedit-me|\
323 --reedit-mes|
--reedit-mess|
--reedit-messa|
--reedit-messag|
--reedit-message)
324 case "$#" in 1) usage
;; esac
326 log_given
=t
$log_given
332 case "$#" in 1) usage
;; esac
334 log_given
=t
$log_given
339 --reu=*|
--reus=*|
--reuse=*|
--reuse-=*|
--reuse-m=*|
--reuse-me=*|\
340 --reuse-mes=*|
--reuse-mess=*|
--reuse-messa=*|
--reuse-messag=*|\
342 log_given
=t
$log_given
343 use_commit
=`expr "z$1" : 'z-[^=]*=\(.*\)'`
347 --reu|
--reus|
--reuse|
--reuse-|
--reuse-m|
--reuse-me|
--reuse-mes|\
348 --reuse-mess|
--reuse-messa|
--reuse-messag|
--reuse-message)
349 case "$#" in 1) usage
;; esac
351 log_given
=t
$log_given
356 -s|
--s|
--si|
--sig|
--sign|
--signo|
--signof|
--signoff)
360 -v|
--v|
--ve|
--ver|
--verb|
--verbo|
--verbos|
--verbose)
364 -u|
--u|
--un|
--unt|
--untr|
--untra|
--untrac|
--untrack|
--untracke|
--untracked|\
365 --untracked-|
--untracked-f|
--untracked-fi|
--untracked-fil|
--untracked-file|\
382 case "$edit_flag" in t
) no_edit
= ;; esac
384 ################################################################
385 # Sanity check options
387 case "$amend,$initial_commit" in
389 die
"You do not have anything to amend." ;;
391 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
392 die
"You are in the middle of a merge -- cannot amend."
398 die
"Only one of -c/-C/-F can be used." ;;
400 die
"Option -m cannot be combined with -c/-C/-F." ;;
403 case "$#,$also,$only,$amend" in
405 die
"Only one of --include/--only can be used." ;;
407 die
"No paths with --include/--only does not make sense." ;;
409 only_include_assumed
="# Clever... amending the last one with dirty index." ;;
413 only_include_assumed
="# Explicit paths specified without -i nor -o; assuming --only paths..."
418 case "$all,$also,$#" in
420 die
"Cannot use -a and -i at the same time." ;;
422 die
"Paths with -a does not make sense." ;;
424 die
"No paths with -i does not make sense." ;;
427 ################################################################
428 # Prepare index to have a tree to be committed
430 TOP
=`git-rev-parse --show-cdup`
441 GIT_INDEX_FILE
="$NEXT_INDEX"
442 export GIT_INDEX_FILE
443 git-diff-files
--name-only -z |
444 git-update-index
--remove -z --stdin
449 git-ls-files
--error-unmatch -- "$@" >/dev
/null ||
exit
451 git-diff-files
--name-only -z -- "$@" |
454 GIT_INDEX_FILE
="$NEXT_INDEX"
455 export GIT_INDEX_FILE
456 git-update-index
--remove -z --stdin
464 if test -f "$GIT_DIR/MERGE_HEAD"
466 refuse_partial
"Cannot do a partial commit during a merge."
468 TMP_INDEX
="$GIT_DIR/tmp-index$$"
469 if test -z "$initial_commit"
471 # make sure index is clean at the specified paths, or
472 # they are additions.
473 dirty_in_index
=`git-diff-index --cached --name-status \
474 --diff-filter=DMTU HEAD -- "$@"`
475 test -z "$dirty_in_index" ||
476 refuse_partial
"Different in index and the last commit:
479 commit_only
=`git-ls-files --error-unmatch -- "$@"` ||
exit
481 # Build the temporary index and update the real index
483 if test -z "$initial_commit"
485 cp "$THIS_INDEX" "$TMP_INDEX"
486 GIT_INDEX_FILE
="$TMP_INDEX" git-read-tree
-m HEAD
491 echo "$commit_only" |
492 GIT_INDEX_FILE
="$TMP_INDEX" \
493 git-update-index
--add --remove --stdin &&
496 echo "$commit_only" |
498 GIT_INDEX_FILE
="$NEXT_INDEX"
499 export GIT_INDEX_FILE
500 git-update-index
--remove --stdin
507 ################################################################
508 # If we do as-is commit, the index file will be THIS_INDEX,
509 # otherwise NEXT_INDEX after we make this commit. We leave
510 # the index as is if we abort.
512 if test -f "$NEXT_INDEX"
514 USE_INDEX
="$NEXT_INDEX"
516 USE_INDEX
="$THIS_INDEX"
519 GIT_INDEX_FILE
="$USE_INDEX" \
520 git-update-index
-q $unmerged_ok_if_status --refresh ||
exit
522 ################################################################
523 # If the request is status, just show it and exit.
531 ################################################################
532 # Grab commit message, write out tree and make commit.
534 if test t
= "$verify" && test -x "$GIT_DIR"/hooks
/pre-commit
538 GIT_INDEX_FILE
="$TMP_INDEX" "$GIT_DIR"/hooks
/pre-commit
540 GIT_INDEX_FILE
="$USE_INDEX" "$GIT_DIR"/hooks
/pre-commit
544 if test "$log_message" != ''
547 elif test "$logfile" != ""
549 if test "$logfile" = -
552 echo >&2 "(reading log message from standard input)"
557 elif test "$use_commit" != ""
559 git-cat-file commit
"$use_commit" |
sed -e '1,/^$/d'
560 elif test -f "$GIT_DIR/MERGE_HEAD" && test -f "$GIT_DIR/MERGE_MSG"
562 cat "$GIT_DIR/MERGE_MSG"
563 elif test -f "$GIT_DIR/SQUASH_MSG"
565 cat "$GIT_DIR/SQUASH_MSG"
566 fi | git-stripspace
>"$GIT_DIR"/COMMIT_EDITMSG
572 git-var GIT_COMMITTER_IDENT |
sed -e '
576 } >>"$GIT_DIR"/COMMIT_EDITMSG
580 if test -f "$GIT_DIR/MERGE_HEAD" && test -z "$no_edit"; then
582 echo "# It looks like you may be committing a MERGE."
583 echo "# If this is not correct, please remove the file"
584 echo "# $GIT_DIR/MERGE_HEAD"
585 echo "# and try again"
587 fi >>"$GIT_DIR"/COMMIT_EDITMSG
590 if test '' != "$force_author"
592 GIT_AUTHOR_NAME
=`expr "z$force_author" : 'z\(.*[^ ]\) *<.*'` &&
593 GIT_AUTHOR_EMAIL
=`expr "z$force_author" : '.*\(<.*\)'` &&
594 test '' != "$GIT_AUTHOR_NAME" &&
595 test '' != "$GIT_AUTHOR_EMAIL" ||
596 die
"malformed --author parameter"
597 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
598 elif test '' != "$use_commit"
602 s/'\''/'\''\\'\'\''/g
604 s/^author \([^<]*\) <[^>]*> .*$/\1/
606 s
/.
*/GIT_AUTHOR_NAME
='\''&'\''/p
609 s
/^author
[^
<]* <\
([^
>]*\
)> .
*$
/\
1/
611 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
614 s/^author [^<]* <[^>]*> \(.*\)$/\1/
616 s
/.
*/GIT_AUTHOR_DATE
='\''&'\''/p
621 set_author_env=`git-cat-file commit "$use_commit" |
622 LANG=C LC_ALL=C sed -ne "$pick_author_script"`
623 eval "$set_author_env"
624 export GIT_AUTHOR_NAME
625 export GIT_AUTHOR_EMAIL
626 export GIT_AUTHOR_DATE
630 if test -z "$initial_commit"
633 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
634 rloga='commit
(merge
)'
635 PARENTS="-p HEAD "`sed -e 's
/^
/-p /' "$GIT_DIR/MERGE_HEAD"`
636 elif test -n "$amend"; then
637 rloga='commit
(amend
)'
638 PARENTS=$(git-cat-file commit HEAD |
639 sed -n -e '/^$
/q
' -e 's
/^parent
/-p /p
')
641 current=$(git-rev-parse --verify HEAD)
643 if [ -z "$(git-ls-files)" ]; then
644 echo >&2 Nothing to commit
649 rloga='commit
(initial
)'
652 if test -z "$no_edit"
656 echo "# Please enter the commit message for your changes."
657 echo "# (Comment lines starting with '#' will not be included)"
658 test -z "$only_include_assumed" ||
echo "$only_include_assumed"
660 } >>"$GIT_DIR"/COMMIT_EDITMSG
662 # we need to check if there is anything to commit
663 run_status
>/dev
/null
665 if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" -a -z "$amend" ]
667 rm -f "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
674 case "${VISUAL:-$EDITOR},$TERM" in
676 echo >&2 "Terminal is dumb but no VISUAL nor EDITOR defined."
677 echo >&2 "Please supply the commit log message using either"
678 echo >&2 "-m or -F option. A boilerplate log message has"
679 echo >&2 "been prepared in $GIT_DIR/COMMIT_EDITMSG"
683 git-var GIT_AUTHOR_IDENT
> /dev
/null || die
684 git-var GIT_COMMITTER_IDENT
> /dev
/null || die
685 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG"
691 if test -x "$GIT_DIR"/hooks
/commit-msg
693 "$GIT_DIR"/hooks
/commit-msg
"$GIT_DIR"/COMMIT_EDITMSG ||
exit
697 if test -z "$no_edit"
705 ' "$GIT_DIR"/COMMIT_EDITMSG
707 cat "$GIT_DIR"/COMMIT_EDITMSG
709 git-stripspace
>"$GIT_DIR"/COMMIT_MSG
711 if cnt
=`grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG |
716 if test -z "$TMP_INDEX"
718 tree
=$
(GIT_INDEX_FILE
="$USE_INDEX" git-write-tree
)
720 tree
=$
(GIT_INDEX_FILE
="$TMP_INDEX" git-write-tree
) &&
723 commit
=$
(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree
$tree $PARENTS) &&
724 rlogm
=$
(sed -e 1q
"$GIT_DIR"/COMMIT_MSG
) &&
725 git-update-ref
-m "$rloga: $rlogm" HEAD
$commit $current &&
726 rm -f -- "$GIT_DIR/MERGE_HEAD" &&
727 if test -f "$NEXT_INDEX"
729 mv "$NEXT_INDEX" "$THIS_INDEX"
734 echo >&2 "* no commit message? aborting commit."
738 rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
739 if test -d "$GIT_DIR/rr-cache"
744 if test -x "$GIT_DIR"/hooks
/post-commit
&& test "$ret" = 0
746 "$GIT_DIR"/hooks
/post-commit