3 # Copyright (c) 2005 Linus Torvalds
4 # Copyright (c) 2006 Junio C Hamano
6 USAGE
='[-a] [-i] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit>] [-e] [--author <author>] [<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 # If TMP_INDEX is defined, that means we are doing
68 # "--only" partial commit, and that index file is used
69 # to build the tree for the commit. Otherwise, if
70 # NEXT_INDEX exists, that is the index file used to
71 # make the commit. Otherwise we are using as-is commit
72 # so the regular index file is what we use to compare.
73 if test '' != "$TMP_INDEX"
75 GIT_INDEX_FILE
="$TMP_INDEX"
77 elif test -f "$NEXT_INDEX"
79 GIT_INDEX_FILE
="$NEXT_INDEX"
85 *) echo "# On branch $branch" ;;
88 if test -z "$initial_commit"
92 git-diff-index
-M --cached --name-status \
93 --diff-filter=MDTCRA HEAD |
98 report
"Updated but not checked in" "will commit"
100 if git-diff-index
--cached -M -p --diff-filter=MDTCRA HEAD |
119 report
"Updated but not checked in" "will commit"
124 git-diff-files
--name-status |
129 report
"Changed but not updated" \
130 "use git-update-index to mark for commit"
132 if test -f "$GIT_DIR/info/exclude"
134 git-ls-files
-z --others --directory \
135 --exclude-from="$GIT_DIR/info/exclude" \
136 --exclude-per-directory=.gitignore
138 git-ls-files
-z --others --directory \
139 --exclude-per-directory=.gitignore
150 print "#\n# Untracked files:\n";
151 print "# (use \"git add\" to add to commit)\n";
158 case "$committable" in
160 echo "nothing to commit"
168 test -z "$TMP_INDEX" || {
169 test -f "$TMP_INDEX" && rm -f "$TMP_INDEX"
174 ################################################################
175 # Command line argument parsing and sanity checking
189 while case "$#" in 0) break;; esac
192 -F|
--F|
-f|
--f|
--fi|
--fil|
--file)
193 case "$#" in 1) usage
;; esac
196 log_given
=t
$log_given
202 log_given
=t
$log_given
203 logfile
=`expr "$1" : '-[Ff]\(.*\)'`
206 --F=*|
--f=*|
--fi=*|
--fil=*|
--file=*)
208 log_given
=t
$log_given
209 logfile
=`expr "$1" : '-[^=]*=\(.*\)'`
216 --au=*|
--aut=*|
--auth=*|
--autho=*|
--author=*)
217 force_author
=`expr "$1" : '-[^=]*=\(.*\)'`
220 --au|
--aut|
--auth|
--autho|
--author)
221 case "$#" in 1) usage
;; esac
226 -e|
--e|
--ed|
--edi|
--edit)
230 -i|
--i|
--in|
--inc|
--incl|
--inclu|
--includ|
--include)
234 -o|
--o|
--on|
--onl|
--only)
238 -m|
--m|
--me|
--mes|
--mess|
--messa|
--messag|
--message)
239 case "$#" in 1) usage
;; esac
241 log_given
=t
$log_given
247 log_given
=t
$log_given
248 log_message
=`expr "$1" : '-m\(.*\)'`
252 --m=*|
--me=*|
--mes=*|
--mess=*|
--messa=*|
--messag=*|
--message=*)
253 log_given
=t
$log_given
254 log_message
=`expr "$1" : '-[^=]*=\(.*\)'`
258 -n|
--n|
--no|
--no-|
--no-v|
--no-ve|
--no-ver|
--no-veri|
--no-verif|
--no-verify)
263 case "$#" in 1) usage
;; esac
265 log_given
=t
$log_given
270 --ree=*|
--reed=*|
--reedi=*|
--reedit=*|
--reedit-=*|
--reedit-m=*|\
271 --reedit-me=*|
--reedit-mes=*|
--reedit-mess=*|
--reedit-messa=*|\
272 --reedit-messag=*|
--reedit-message=*)
273 log_given
=t
$log_given
274 use_commit
=`expr "$1" : '-[^=]*=\(.*\)'`
278 --ree|
--reed|
--reedi|
--reedit|
--reedit-|
--reedit-m|
--reedit-me|\
279 --reedit-mes|
--reedit-mess|
--reedit-messa|
--reedit-messag|
--reedit-message)
280 case "$#" in 1) usage
;; esac
282 log_given
=t
$log_given
288 case "$#" in 1) usage
;; esac
290 log_given
=t
$log_given
295 --reu=*|
--reus=*|
--reuse=*|
--reuse-=*|
--reuse-m=*|
--reuse-me=*|\
296 --reuse-mes=*|
--reuse-mess=*|
--reuse-messa=*|
--reuse-messag=*|\
298 log_given
=t
$log_given
299 use_commit
=`expr "$1" : '-[^=]*=\(.*\)'`
303 --reu|
--reus|
--reuse|
--reuse-|
--reuse-m|
--reuse-me|
--reuse-mes|\
304 --reuse-mess|
--reuse-messa|
--reuse-messag|
--reuse-message)
305 case "$#" in 1) usage
;; esac
307 log_given
=t
$log_given
312 -s|
--s|
--si|
--sig|
--sign|
--signo|
--signof|
--signoff)
316 -v|
--v|
--ve|
--ver|
--verb|
--verbo|
--verbos|
--verbose)
333 ################################################################
334 # Sanity check options
338 die
"Only one of -c/-C/-F/-m can be used." ;;
341 case "$#,$also$only" in
343 die
"Only one of --include/--only can be used." ;;
345 die
"No paths with --include/--only does not make sense." ;;
349 echo >&2 "assuming --include paths..."
351 # Later when switch the defaults, we will replace them with these:
352 # echo >&2 "assuming --only paths..."
355 # If we are going to launch an editor, the message won't be
356 # shown without this...
357 test -z "$log_given$status_only" && sleep 1
361 case "$all,$also,$#" in
363 die
"Cannot use -a and -i at the same time." ;;
365 die
"Paths with -a does not make sense." ;;
367 die
"No paths with -i does not make sense." ;;
370 ################################################################
371 # Prepare index to have a tree to be committed
373 TOP
=`git-rev-parse --show-cdup`
384 GIT_INDEX_FILE
="$NEXT_INDEX"
385 export GIT_INDEX_FILE
386 git-diff-files
--name-only -z |
387 git-update-index
--remove -z --stdin
392 git-diff-files
--name-only -z -- "$@" |
395 GIT_INDEX_FILE
="$NEXT_INDEX"
396 export GIT_INDEX_FILE
397 git-update-index
--remove -z --stdin
405 if test -f "$GIT_DIR/MERGE_HEAD"
407 refuse_partial
"Cannot do a partial commit during a merge."
409 TMP_INDEX
="$GIT_DIR/tmp-index$$"
410 if test -z "$initial_commit"
412 # make sure index is clean at the specified paths, or
413 # they are additions.
414 dirty_in_index
=`git-diff-index --cached --name-status \
415 --diff-filter=DMTU HEAD -- "$@"`
416 test -z "$dirty_in_index" ||
417 refuse_partial
"Different in index and the last commit:
420 commit_only
=`git-ls-files -- "$@"`
422 # Build the temporary index and update the real index
424 if test -z "$initial_commit"
426 cp "$THIS_INDEX" "$TMP_INDEX"
427 GIT_INDEX_FILE
="$TMP_INDEX" git-read-tree
-m HEAD
432 echo "$commit_only" |
433 GIT_INDEX_FILE
="$TMP_INDEX" \
434 git-update-index
--add --remove --stdin &&
437 echo "$commit_only" |
439 GIT_INDEX_FILE
="$NEXT_INDEX"
440 export GIT_INDEX_FILE
441 git-update-index
--remove --stdin
448 ################################################################
449 # If we do as-is commit, the index file will be THIS_INDEX,
450 # otherwise NEXT_INDEX after we make this commit. We leave
451 # the index as is if we abort.
453 if test -f "$NEXT_INDEX"
455 USE_INDEX
="$NEXT_INDEX"
457 USE_INDEX
="$THIS_INDEX"
460 GIT_INDEX_FILE
="$USE_INDEX" \
461 git-update-index
-q $unmerged_ok_if_status --refresh ||
exit
463 ################################################################
464 # If the request is status, just show it and exit.
472 ################################################################
473 # Grab commit message, write out tree and make commit.
475 if test t
= "$verify" && test -x "$GIT_DIR"/hooks
/pre-commit
479 GIT_INDEX_FILE
="$TMP_INDEX" "$GIT_DIR"/hooks
/pre-commit
481 GIT_INDEX_FILE
="$USE_INDEX" "$GIT_DIR"/hooks
/pre-commit
485 if test "$log_message" != ''
488 elif test "$logfile" != ""
490 if test "$logfile" = -
493 echo >&2 "(reading log message from standard input)"
498 elif test "$use_commit" != ""
500 git-cat-file commit
"$use_commit" |
sed -e '1,/^$/d'
501 elif test -f "$GIT_DIR/MERGE_HEAD" && test -f "$GIT_DIR/MERGE_MSG"
503 cat "$GIT_DIR/MERGE_MSG"
504 fi | git-stripspace
>"$GIT_DIR"/COMMIT_EDITMSG
510 git-var GIT_COMMITTER_IDENT |
sed -e '
514 } >>"$GIT_DIR"/COMMIT_EDITMSG
518 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
520 echo "# It looks like you may be committing a MERGE."
521 echo "# If this is not correct, please remove the file"
522 echo "# $GIT_DIR/MERGE_HEAD"
523 echo "# and try again"
525 fi >>"$GIT_DIR"/COMMIT_EDITMSG
528 if test '' != "$force_author"
530 GIT_AUTHOR_NAME
=`expr "$force_author" : '\(.*[^ ]\) *<.*'` &&
531 GIT_AUTHOR_EMAIL
=`expr "$force_author" : '.*\(<.*\)'` &&
532 test '' != "$GIT_AUTHOR_NAME" &&
533 test '' != "$GIT_AUTHOR_EMAIL" ||
534 die
"malformatted --author parameter"
535 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
536 elif test '' != "$use_commit"
540 s/'\''/'\''\\'\'\''/g
542 s/^author \([^<]*\) <[^>]*> .*$/\1/
544 s
/.
*/GIT_AUTHOR_NAME
='\''&'\''/p
547 s
/^author
[^
<]* <\
([^
>]*\
)> .
*$
/\
1/
549 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
552 s/^author [^<]* <[^>]*> \(.*\)$/\1/
554 s
/.
*/GIT_AUTHOR_DATE
='\''&'\''/p
559 set_author_env=`git-cat-file commit "$use_commit" |
560 LANG=C LC_ALL=C sed -ne "$pick_author_script"`
561 eval "$set_author_env"
562 export GIT_AUTHOR_NAME
563 export GIT_AUTHOR_EMAIL
564 export GIT_AUTHOR_DATE
568 if test -z "$initial_commit"
570 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
571 PARENTS="-p HEAD "`sed -e 's
/^
/-p /' "$GIT_DIR/MERGE_HEAD"`
574 if [ -z "$(git-ls-files)" ]; then
575 echo >&2 Nothing to commit
582 test -z "$verbose" || echo '---'
584 } >>"$GIT_DIR"/COMMIT_EDITMSG
585 if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" ]
587 rm -f "$GIT_DIR/COMMIT_EDITMSG"
593 case "${VISUAL:-$EDITOR},$TERM" in
595 echo >&2 "Terminal is dumb but no VISUAL nor EDITOR defined."
596 echo >&2 "Please supply the commit log message using either"
597 echo >&2 "-m or -F option. A boilerplate log message has"
598 echo >&2 "been prepared in $GIT_DIR/COMMIT_EDITMSG"
602 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG"
608 if test -x "$GIT_DIR"/hooks/commit-msg
610 "$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/COMMIT_EDITMSG || exit
620 ' "$GIT_DIR"/COMMIT_EDITMSG |
621 git-stripspace >"$GIT_DIR"/COMMIT_MSG
623 if cnt=`grep -v -i '^Signed-off-by
' "$GIT_DIR"/COMMIT_MSG |
628 if test -z "$TMP_INDEX"
630 tree=$(GIT_INDEX_FILE="$USE_INDEX" git-write-tree)
632 tree=$(GIT_INDEX_FILE="$TMP_INDEX" git-write-tree) &&
635 commit=$(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree $tree $PARENTS) &&
636 git-update-ref HEAD $commit $current &&
637 rm -f -- "$GIT_DIR/MERGE_HEAD" &&
638 if test -f "$NEXT_INDEX"
640 mv "$NEXT_INDEX" "$THIS_INDEX"
645 echo >&2 "* no commit message? aborting commit."
649 rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG"
652 if test -x "$GIT_DIR"/hooks/post-commit && test "$ret" = 0
654 "$GIT_DIR"/hooks/post-commit