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"
90 git-diff-index
-M --cached --name-status \
91 --diff-filter=MDTCRA HEAD |
96 report
"Updated but not checked in" "will commit"
108 report
"Updated but not checked in" "will commit"
113 git-diff-files
--name-status |
118 report
"Changed but not updated" \
119 "use git-update-index to mark for commit"
121 if test -f "$GIT_DIR/info/exclude"
123 git-ls-files
-z --others --directory \
124 --exclude-from="$GIT_DIR/info/exclude" \
125 --exclude-per-directory=.gitignore
127 git-ls-files
-z --others --directory \
128 --exclude-per-directory=.gitignore
139 print "#\n# Untracked files:\n";
140 print "# (use \"git add\" to add to commit)\n";
148 if test -n "$verbose"
150 git-diff-index
--cached -M -p --diff-filter=MDTCRA HEAD
152 case "$committable" in
154 echo "nothing to commit"
162 test -z "$TMP_INDEX" || {
163 test -f "$TMP_INDEX" && rm -f "$TMP_INDEX"
168 ################################################################
169 # Command line argument parsing and sanity checking
183 while case "$#" in 0) break;; esac
186 -F|
--F|
-f|
--f|
--fi|
--fil|
--file)
187 case "$#" in 1) usage
;; esac
190 log_given
=t
$log_given
196 log_given
=t
$log_given
197 logfile
=`expr "$1" : '-[Ff]\(.*\)'`
200 --F=*|
--f=*|
--fi=*|
--fil=*|
--file=*)
202 log_given
=t
$log_given
203 logfile
=`expr "$1" : '-[^=]*=\(.*\)'`
210 --au=*|
--aut=*|
--auth=*|
--autho=*|
--author=*)
211 force_author
=`expr "$1" : '-[^=]*=\(.*\)'`
214 --au|
--aut|
--auth|
--autho|
--author)
215 case "$#" in 1) usage
;; esac
220 -e|
--e|
--ed|
--edi|
--edit)
224 -i|
--i|
--in|
--inc|
--incl|
--inclu|
--includ|
--include)
228 -o|
--o|
--on|
--onl|
--only)
232 -m|
--m|
--me|
--mes|
--mess|
--messa|
--messag|
--message)
233 case "$#" in 1) usage
;; esac
235 log_given
=t
$log_given
241 log_given
=t
$log_given
242 log_message
=`expr "$1" : '-m\(.*\)'`
246 --m=*|
--me=*|
--mes=*|
--mess=*|
--messa=*|
--messag=*|
--message=*)
247 log_given
=t
$log_given
248 log_message
=`expr "$1" : '-[^=]*=\(.*\)'`
252 -n|
--n|
--no|
--no-|
--no-v|
--no-ve|
--no-ver|
--no-veri|
--no-verif|
--no-verify)
257 case "$#" in 1) usage
;; esac
259 log_given
=t
$log_given
264 --ree=*|
--reed=*|
--reedi=*|
--reedit=*|
--reedit-=*|
--reedit-m=*|\
265 --reedit-me=*|
--reedit-mes=*|
--reedit-mess=*|
--reedit-messa=*|\
266 --reedit-messag=*|
--reedit-message=*)
267 log_given
=t
$log_given
268 use_commit
=`expr "$1" : '-[^=]*=\(.*\)'`
272 --ree|
--reed|
--reedi|
--reedit|
--reedit-|
--reedit-m|
--reedit-me|\
273 --reedit-mes|
--reedit-mess|
--reedit-messa|
--reedit-messag|
--reedit-message)
274 case "$#" in 1) usage
;; esac
276 log_given
=t
$log_given
282 case "$#" in 1) usage
;; esac
284 log_given
=t
$log_given
289 --reu=*|
--reus=*|
--reuse=*|
--reuse-=*|
--reuse-m=*|
--reuse-me=*|\
290 --reuse-mes=*|
--reuse-mess=*|
--reuse-messa=*|
--reuse-messag=*|\
292 log_given
=t
$log_given
293 use_commit
=`expr "$1" : '-[^=]*=\(.*\)'`
297 --reu|
--reus|
--reuse|
--reuse-|
--reuse-m|
--reuse-me|
--reuse-mes|\
298 --reuse-mess|
--reuse-messa|
--reuse-messag|
--reuse-message)
299 case "$#" in 1) usage
;; esac
301 log_given
=t
$log_given
306 -s|
--s|
--si|
--sig|
--sign|
--signo|
--signof|
--signoff)
310 -v|
--v|
--ve|
--ver|
--verb|
--verbo|
--verbos|
--verbose)
327 ################################################################
328 # Sanity check options
332 die
"Only one of -c/-C/-F/-m can be used." ;;
335 case "$#,$also$only" in
337 die
"Only one of --include/--only can be used." ;;
339 die
"No paths with --include/--only does not make sense." ;;
343 echo >&2 "assuming --include paths..."
345 # Later when switch the defaults, we will replace them with these:
346 # echo >&2 "assuming --only paths..."
349 # If we are going to launch an editor, the message won't be
350 # shown without this...
351 test -z "$log_given$status_only" && sleep 1
355 case "$all,$also,$#" in
357 die
"Cannot use -a and -i at the same time." ;;
359 die
"Paths with -a does not make sense." ;;
361 die
"No paths with -i does not make sense." ;;
364 ################################################################
365 # Prepare index to have a tree to be committed
367 TOP
=`git-rev-parse --show-cdup`
378 GIT_INDEX_FILE
="$NEXT_INDEX"
379 export GIT_INDEX_FILE
380 git-diff-files
--name-only -z |
381 git-update-index
--remove -z --stdin
386 git-diff-files
--name-only -z -- "$@" |
389 GIT_INDEX_FILE
="$NEXT_INDEX"
390 export GIT_INDEX_FILE
391 git-update-index
--remove -z --stdin
399 if test -f "$GIT_DIR/MERGE_HEAD"
401 refuse_partial
"Cannot do a partial commit during a merge."
403 TMP_INDEX
="$GIT_DIR/tmp-index$$"
404 if test -z "$initial_commit"
406 # make sure index is clean at the specified paths, or
407 # they are additions.
408 dirty_in_index
=`git-diff-index --cached --name-status \
409 --diff-filter=DMTU HEAD -- "$@"`
410 test -z "$dirty_in_index" ||
411 refuse_partial
"Different in index and the last commit:
414 commit_only
=`git-ls-files -- "$@"`
416 # Build the temporary index and update the real index
418 if test -z "$initial_commit"
420 cp "$THIS_INDEX" "$TMP_INDEX"
421 GIT_INDEX_FILE
="$TMP_INDEX" git-read-tree
-m HEAD
426 echo "$commit_only" |
427 GIT_INDEX_FILE
="$TMP_INDEX" \
428 git-update-index
--add --remove --stdin &&
431 echo "$commit_only" |
433 GIT_INDEX_FILE
="$NEXT_INDEX"
434 export GIT_INDEX_FILE
435 git-update-index
--remove --stdin
442 ################################################################
443 # If we do as-is commit, the index file will be THIS_INDEX,
444 # otherwise NEXT_INDEX after we make this commit. We leave
445 # the index as is if we abort.
447 if test -f "$NEXT_INDEX"
449 USE_INDEX
="$NEXT_INDEX"
451 USE_INDEX
="$THIS_INDEX"
454 GIT_INDEX_FILE
="$USE_INDEX" \
455 git-update-index
-q $unmerged_ok_if_status --refresh ||
exit
457 ################################################################
458 # If the request is status, just show it and exit.
466 ################################################################
467 # Grab commit message, write out tree and make commit.
469 if test t
= "$verify" && test -x "$GIT_DIR"/hooks
/pre-commit
473 GIT_INDEX_FILE
="$TMP_INDEX" "$GIT_DIR"/hooks
/pre-commit
475 GIT_INDEX_FILE
="$USE_INDEX" "$GIT_DIR"/hooks
/pre-commit
479 if test "$log_message" != ''
482 elif test "$logfile" != ""
484 if test "$logfile" = -
487 echo >&2 "(reading log message from standard input)"
492 elif test "$use_commit" != ""
494 git-cat-file commit
"$use_commit" |
sed -e '1,/^$/d'
495 elif test -f "$GIT_DIR/MERGE_HEAD" && test -f "$GIT_DIR/MERGE_MSG"
497 cat "$GIT_DIR/MERGE_MSG"
498 fi | git-stripspace
>"$GIT_DIR"/COMMIT_EDITMSG
504 git-var GIT_COMMITTER_IDENT |
sed -e '
508 } >>"$GIT_DIR"/COMMIT_EDITMSG
512 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
514 echo "# It looks like you may be committing a MERGE."
515 echo "# If this is not correct, please remove the file"
516 echo "# $GIT_DIR/MERGE_HEAD"
517 echo "# and try again"
519 fi >>"$GIT_DIR"/COMMIT_EDITMSG
522 if test '' != "$force_author"
524 GIT_AUTHOR_NAME
=`expr "$force_author" : '\(.*[^ ]\) *<.*'` &&
525 GIT_AUTHOR_EMAIL
=`expr "$force_author" : '.*\(<.*\)'` &&
526 test '' != "$GIT_AUTHOR_NAME" &&
527 test '' != "$GIT_AUTHOR_EMAIL" ||
528 die
"malformatted --author parameter"
529 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
530 elif test '' != "$use_commit"
534 s/'\''/'\''\\'\'\''/g
536 s/^author \([^<]*\) <[^>]*> .*$/\1/
538 s
/.
*/GIT_AUTHOR_NAME
='\''&'\''/p
541 s
/^author
[^
<]* <\
([^
>]*\
)> .
*$
/\
1/
543 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
546 s/^author [^<]* <[^>]*> \(.*\)$/\1/
548 s
/.
*/GIT_AUTHOR_DATE
='\''&'\''/p
553 set_author_env=`git-cat-file commit "$use_commit" |
554 LANG=C LC_ALL=C sed -ne "$pick_author_script"`
555 eval "$set_author_env"
556 export GIT_AUTHOR_NAME
557 export GIT_AUTHOR_EMAIL
558 export GIT_AUTHOR_DATE
562 if test -z "$initial_commit"
564 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
565 PARENTS="-p HEAD "`sed -e 's
/^
/-p /' "$GIT_DIR/MERGE_HEAD"`
568 if [ -z "$(git-ls-files)" ]; then
569 echo >&2 Nothing to commit
575 run_status >>"$GIT_DIR"/COMMIT_EDITMSG
576 if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" ]
578 rm -f "$GIT_DIR/COMMIT_EDITMSG"
584 case "${VISUAL:-$EDITOR},$TERM" in
586 echo >&2 "Terminal is dumb but no VISUAL nor EDITOR defined."
587 echo >&2 "Please supply the commit log message using either"
588 echo >&2 "-m or -F option. A boilerplate log message has"
589 echo >&2 "been prepared in $GIT_DIR/COMMIT_EDITMSG"
593 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG"
599 if test -x "$GIT_DIR"/hooks/commit-msg
601 "$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/COMMIT_EDITMSG || exit
611 ' "$GIT_DIR"/COMMIT_EDITMSG |
612 git-stripspace >"$GIT_DIR"/COMMIT_MSG
614 if cnt=`grep -v -i '^Signed-off-by
' "$GIT_DIR"/COMMIT_MSG |
619 if test -z "$TMP_INDEX"
621 tree=$(GIT_INDEX_FILE="$USE_INDEX" git-write-tree)
623 tree=$(GIT_INDEX_FILE="$TMP_INDEX" git-write-tree) &&
626 commit=$(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree $tree $PARENTS) &&
627 git-update-ref HEAD $commit $current &&
628 rm -f -- "$GIT_DIR/MERGE_HEAD" &&
629 if test -f "$NEXT_INDEX"
631 mv "$NEXT_INDEX" "$THIS_INDEX"
636 echo >&2 "* no commit message? aborting commit."
640 rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG"
643 if test -x "$GIT_DIR"/hooks/post-commit && test "$ret" = 0
645 "$GIT_DIR"/hooks/post-commit