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>) [--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"
137 if test -f "$GIT_DIR/info/exclude"
139 git-ls-files
-z --others --directory \
140 --exclude-from="$GIT_DIR/info/exclude" \
141 --exclude-per-directory=.gitignore
143 git-ls-files
-z --others --directory \
144 --exclude-per-directory=.gitignore
155 print "#\n# Untracked files:\n";
156 print "# (use \"git add\" to add to commit)\n";
164 if test -n "$verbose" -a -z "$IS_INITIAL"
166 git-diff-index
--cached -M -p --diff-filter=MDTCRA
$REFERENCE
168 case "$committable" in
170 echo "nothing to commit"
178 test -z "$TMP_INDEX" || {
179 test -f "$TMP_INDEX" && rm -f "$TMP_INDEX"
184 ################################################################
185 # Command line argument parsing and sanity checking
200 only_include_assumed
=
201 while case "$#" in 0) break;; esac
204 -F|
--F|
-f|
--f|
--fi|
--fil|
--file)
205 case "$#" in 1) usage
;; esac
208 log_given
=t
$log_given
214 log_given
=t
$log_given
215 logfile
=`expr "$1" : '-[Ff]\(.*\)'`
218 --F=*|
--f=*|
--fi=*|
--fil=*|
--file=*)
220 log_given
=t
$log_given
221 logfile
=`expr "$1" : '-[^=]*=\(.*\)'`
228 --au=*|
--aut=*|
--auth=*|
--autho=*|
--author=*)
229 force_author
=`expr "$1" : '-[^=]*=\(.*\)'`
232 --au|
--aut|
--auth|
--autho|
--author)
233 case "$#" in 1) usage
;; esac
238 -e|
--e|
--ed|
--edi|
--edit)
242 -i|
--i|
--in|
--inc|
--incl|
--inclu|
--includ|
--include)
246 -o|
--o|
--on|
--onl|
--only)
250 -m|
--m|
--me|
--mes|
--mess|
--messa|
--messag|
--message)
251 case "$#" in 1) usage
;; esac
253 log_given
=t
$log_given
259 log_given
=t
$log_given
260 log_message
=`expr "$1" : '-m\(.*\)'`
264 --m=*|
--me=*|
--mes=*|
--mess=*|
--messa=*|
--messag=*|
--message=*)
265 log_given
=t
$log_given
266 log_message
=`expr "$1" : '-[^=]*=\(.*\)'`
270 -n|
--n|
--no|
--no-|
--no-v|
--no-ve|
--no-ver|
--no-veri|
--no-verif|
--no-verify)
274 --a|
--am|
--ame|
--amen|
--amend)
276 log_given
=t
$log_given
281 case "$#" in 1) usage
;; esac
283 log_given
=t
$log_given
288 --ree=*|
--reed=*|
--reedi=*|
--reedit=*|
--reedit-=*|
--reedit-m=*|\
289 --reedit-me=*|
--reedit-mes=*|
--reedit-mess=*|
--reedit-messa=*|\
290 --reedit-messag=*|
--reedit-message=*)
291 log_given
=t
$log_given
292 use_commit
=`expr "$1" : '-[^=]*=\(.*\)'`
296 --ree|
--reed|
--reedi|
--reedit|
--reedit-|
--reedit-m|
--reedit-me|\
297 --reedit-mes|
--reedit-mess|
--reedit-messa|
--reedit-messag|
--reedit-message)
298 case "$#" in 1) usage
;; esac
300 log_given
=t
$log_given
306 case "$#" in 1) usage
;; esac
308 log_given
=t
$log_given
313 --reu=*|
--reus=*|
--reuse=*|
--reuse-=*|
--reuse-m=*|
--reuse-me=*|\
314 --reuse-mes=*|
--reuse-mess=*|
--reuse-messa=*|
--reuse-messag=*|\
316 log_given
=t
$log_given
317 use_commit
=`expr "$1" : '-[^=]*=\(.*\)'`
321 --reu|
--reus|
--reuse|
--reuse-|
--reuse-m|
--reuse-me|
--reuse-mes|\
322 --reuse-mess|
--reuse-messa|
--reuse-messag|
--reuse-message)
323 case "$#" in 1) usage
;; esac
325 log_given
=t
$log_given
330 -s|
--s|
--si|
--sig|
--sign|
--signo|
--signof|
--signoff)
334 -v|
--v|
--ve|
--ver|
--verb|
--verbo|
--verbos|
--verbose)
351 ################################################################
352 # Sanity check options
354 case "$amend,$initial_commit" in
356 die
"You do not have anything to amend." ;;
358 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
359 die
"You are in the middle of a merge -- cannot amend."
365 die
"Only one of -c/-C/-F/-m can be used." ;;
368 case "$#,$also$only" in
370 die
"Only one of --include/--only can be used." ;;
372 die
"No paths with --include/--only does not make sense." ;;
376 only_include_assumed
="# Explicit paths specified without -i nor -o; assuming --only paths..."
381 case "$all,$also,$#" in
383 die
"Cannot use -a and -i at the same time." ;;
385 die
"Paths with -a does not make sense." ;;
387 die
"No paths with -i does not make sense." ;;
390 ################################################################
391 # Prepare index to have a tree to be committed
393 TOP
=`git-rev-parse --show-cdup`
404 GIT_INDEX_FILE
="$NEXT_INDEX"
405 export GIT_INDEX_FILE
406 git-diff-files
--name-only -z |
407 git-update-index
--remove -z --stdin
412 git-ls-files
--error-unmatch -- "$@" >/dev
/null ||
exit
414 git-diff-files
--name-only -z -- "$@" |
417 GIT_INDEX_FILE
="$NEXT_INDEX"
418 export GIT_INDEX_FILE
419 git-update-index
--remove -z --stdin
427 if test -f "$GIT_DIR/MERGE_HEAD"
429 refuse_partial
"Cannot do a partial commit during a merge."
431 TMP_INDEX
="$GIT_DIR/tmp-index$$"
432 if test -z "$initial_commit"
434 # make sure index is clean at the specified paths, or
435 # they are additions.
436 dirty_in_index
=`git-diff-index --cached --name-status \
437 --diff-filter=DMTU HEAD -- "$@"`
438 test -z "$dirty_in_index" ||
439 refuse_partial
"Different in index and the last commit:
442 commit_only
=`git-ls-files --error-unmatch -- "$@"` ||
exit
444 # Build the temporary index and update the real index
446 if test -z "$initial_commit"
448 cp "$THIS_INDEX" "$TMP_INDEX"
449 GIT_INDEX_FILE
="$TMP_INDEX" git-read-tree
-m HEAD
454 echo "$commit_only" |
455 GIT_INDEX_FILE
="$TMP_INDEX" \
456 git-update-index
--add --remove --stdin &&
459 echo "$commit_only" |
461 GIT_INDEX_FILE
="$NEXT_INDEX"
462 export GIT_INDEX_FILE
463 git-update-index
--remove --stdin
470 ################################################################
471 # If we do as-is commit, the index file will be THIS_INDEX,
472 # otherwise NEXT_INDEX after we make this commit. We leave
473 # the index as is if we abort.
475 if test -f "$NEXT_INDEX"
477 USE_INDEX
="$NEXT_INDEX"
479 USE_INDEX
="$THIS_INDEX"
482 GIT_INDEX_FILE
="$USE_INDEX" \
483 git-update-index
-q $unmerged_ok_if_status --refresh ||
exit
485 ################################################################
486 # If the request is status, just show it and exit.
494 ################################################################
495 # Grab commit message, write out tree and make commit.
497 if test t
= "$verify" && test -x "$GIT_DIR"/hooks
/pre-commit
501 GIT_INDEX_FILE
="$TMP_INDEX" "$GIT_DIR"/hooks
/pre-commit
503 GIT_INDEX_FILE
="$USE_INDEX" "$GIT_DIR"/hooks
/pre-commit
507 if test "$log_message" != ''
510 elif test "$logfile" != ""
512 if test "$logfile" = -
515 echo >&2 "(reading log message from standard input)"
520 elif test "$use_commit" != ""
522 git-cat-file commit
"$use_commit" |
sed -e '1,/^$/d'
523 elif test -f "$GIT_DIR/MERGE_HEAD" && test -f "$GIT_DIR/MERGE_MSG"
525 cat "$GIT_DIR/MERGE_MSG"
526 fi | git-stripspace
>"$GIT_DIR"/COMMIT_EDITMSG
532 git-var GIT_COMMITTER_IDENT |
sed -e '
536 } >>"$GIT_DIR"/COMMIT_EDITMSG
540 if test -f "$GIT_DIR/MERGE_HEAD" && test -z "$no_edit"; then
542 echo "# It looks like you may be committing a MERGE."
543 echo "# If this is not correct, please remove the file"
544 echo "# $GIT_DIR/MERGE_HEAD"
545 echo "# and try again"
547 fi >>"$GIT_DIR"/COMMIT_EDITMSG
550 if test '' != "$force_author"
552 GIT_AUTHOR_NAME
=`expr "$force_author" : '\(.*[^ ]\) *<.*'` &&
553 GIT_AUTHOR_EMAIL
=`expr "$force_author" : '.*\(<.*\)'` &&
554 test '' != "$GIT_AUTHOR_NAME" &&
555 test '' != "$GIT_AUTHOR_EMAIL" ||
556 die
"malformatted --author parameter"
557 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
558 elif test '' != "$use_commit"
562 s/'\''/'\''\\'\'\''/g
564 s/^author \([^<]*\) <[^>]*> .*$/\1/
566 s
/.
*/GIT_AUTHOR_NAME
='\''&'\''/p
569 s
/^author
[^
<]* <\
([^
>]*\
)> .
*$
/\
1/
571 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
574 s/^author [^<]* <[^>]*> \(.*\)$/\1/
576 s
/.
*/GIT_AUTHOR_DATE
='\''&'\''/p
581 set_author_env=`git-cat-file commit "$use_commit" |
582 LANG=C LC_ALL=C sed -ne "$pick_author_script"`
583 eval "$set_author_env"
584 export GIT_AUTHOR_NAME
585 export GIT_AUTHOR_EMAIL
586 export GIT_AUTHOR_DATE
590 if test -z "$initial_commit"
592 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
593 PARENTS="-p HEAD "`sed -e 's
/^
/-p /' "$GIT_DIR/MERGE_HEAD"`
594 elif test -n "$amend"; then
595 PARENTS=$(git-cat-file commit HEAD |
596 sed -n -e '/^$
/q
' -e 's
/^parent
/-p /p
')
598 current=$(git-rev-parse --verify HEAD)
600 if [ -z "$(git-ls-files)" ]; then
601 echo >&2 Nothing to commit
608 if test -z "$no_edit"
611 test -z "$only_include_assumed" || echo "$only_include_assumed"
613 } >>"$GIT_DIR"/COMMIT_EDITMSG
615 # we need to check if there is anything to commit
616 run_status >/dev/null
618 if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" -a -z "$amend" ]
620 rm -f "$GIT_DIR/COMMIT_EDITMSG"
627 case "${VISUAL:-$EDITOR},$TERM" in
629 echo >&2 "Terminal is dumb but no VISUAL nor EDITOR defined."
630 echo >&2 "Please supply the commit log message using either"
631 echo >&2 "-m or -F option. A boilerplate log message has"
632 echo >&2 "been prepared in $GIT_DIR/COMMIT_EDITMSG"
636 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG"
642 if test -x "$GIT_DIR"/hooks/commit-msg
644 "$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/COMMIT_EDITMSG || exit
654 ' "$GIT_DIR"/COMMIT_EDITMSG |
655 git-stripspace >"$GIT_DIR"/COMMIT_MSG
657 if cnt=`grep -v -i '^Signed-off-by
' "$GIT_DIR"/COMMIT_MSG |
662 if test -z "$TMP_INDEX"
664 tree=$(GIT_INDEX_FILE="$USE_INDEX" git-write-tree)
666 tree=$(GIT_INDEX_FILE="$TMP_INDEX" git-write-tree) &&
669 commit=$(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree $tree $PARENTS) &&
670 git-update-ref HEAD $commit $current &&
671 rm -f -- "$GIT_DIR/MERGE_HEAD" &&
672 if test -f "$NEXT_INDEX"
674 mv "$NEXT_INDEX" "$THIS_INDEX"
679 echo >&2 "* no commit message? aborting commit."
683 rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG"
684 if test -d "$GIT_DIR/rr-cache"
689 if test -x "$GIT_DIR"/hooks/post-commit && test "$ret" = 0
691 "$GIT_DIR"/hooks/post-commit