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>...]'
11 git-rev-parse
--verify HEAD
>/dev
/null
2>&1 ||
16 echo >&2 "You might have meant to say 'git commit -i paths...', perhaps?"
20 SAVE_INDEX
="$GIT_DIR/save-index$$"
22 cp "$GIT_DIR/index" "$SAVE_INDEX"
28 if test '' != "$TMP_INDEX"
30 GIT_INDEX_FILE
="$TMP_INDEX" git-status
48 while case "$#" in 0) break;; esac
51 -F|
--F|
-f|
--f|
--fi|
--fil|
--file)
52 case "$#" in 1) usage
;; esac
62 logfile
=`expr "$1" : '-[Ff]\(.*\)'`
65 --F=*|
--f=*|
--fi=*|
--fil=*|
--file=*)
68 logfile
=`expr "$1" : '-[^=]*=\(.*\)'`
75 --au=*|
--aut=*|
--auth=*|
--autho=*|
--author=*)
76 force_author
=`expr "$1" : '-[^=]*=\(.*\)'`
79 --au|
--aut|
--auth|
--autho|
--author)
80 case "$#" in 1) usage
;; esac
85 -e|
--e|
--ed|
--edi|
--edit)
89 -i|
--i|
--in|
--inc|
--incl|
--inclu|
--includ|
--include)
93 -o|
--o|
--on|
--onl|
--only)
97 -m|
--m|
--me|
--mes|
--mess|
--messa|
--messag|
--message)
98 case "$#" in 1) usage
;; esac
100 log_given
=t
$log_given
106 log_given
=t
$log_given
107 log_message
=`expr "$1" : '-m\(.*\)'`
111 --m=*|
--me=*|
--mes=*|
--mess=*|
--messa=*|
--messag=*|
--message=*)
112 log_given
=t
$log_given
113 log_message
=`expr "$1" : '-[^=]*=\(.*\)'`
117 -n|
--n|
--no|
--no-|
--no-v|
--no-ve|
--no-ver|
--no-veri|
--no-verif|
--no-verify)
122 case "$#" in 1) usage
;; esac
124 log_given
=t
$log_given
129 --ree=*|
--reed=*|
--reedi=*|
--reedit=*|
--reedit-=*|
--reedit-m=*|\
130 --reedit-me=*|
--reedit-mes=*|
--reedit-mess=*|
--reedit-messa=*|\
131 --reedit-messag=*|
--reedit-message=*)
132 log_given
=t
$log_given
133 use_commit
=`expr "$1" : '-[^=]*=\(.*\)'`
137 --ree|
--reed|
--reedi|
--reedit|
--reedit-|
--reedit-m|
--reedit-me|\
138 --reedit-mes|
--reedit-mess|
--reedit-messa|
--reedit-messag|
--reedit-message)
139 case "$#" in 1) usage
;; esac
141 log_given
=t
$log_given
147 case "$#" in 1) usage
;; esac
149 log_given
=t
$log_given
154 --reu=*|
--reus=*|
--reuse=*|
--reuse-=*|
--reuse-m=*|
--reuse-me=*|\
155 --reuse-mes=*|
--reuse-mess=*|
--reuse-messa=*|
--reuse-messag=*|\
157 log_given
=t
$log_given
158 use_commit
=`expr "$1" : '-[^=]*=\(.*\)'`
162 --reu|
--reus|
--reuse|
--reuse-|
--reuse-m|
--reuse-me|
--reuse-mes|\
163 --reuse-mess|
--reuse-messa|
--reuse-messag|
--reuse-message)
164 case "$#" in 1) usage
;; esac
166 log_given
=t
$log_given
171 -s|
--s|
--si|
--sig|
--sign|
--signo|
--signof|
--signoff)
175 -v|
--v|
--ve|
--ver|
--veri|
--verif|
--verify)
194 die
"Only one of -c/-C/-F/-m can be used." ;;
197 case "$#,$also$only" in
199 die
"Only one of --include/--only can be used." ;;
201 die
"No paths with --include/--only does not make sense." ;;
205 echo >&2 "assuming --include paths..."
207 # Later when switch the defaults, we will replace them with these:
208 # echo >&2 "assuming --only paths..."
214 TOP
=`git-rev-parse --show-cdup`
222 die
"Cannot use -a and -i at the same time." ;;
226 *) die
"Paths with -a does not make sense." ;;
232 git-diff-files
--name-only -z |
233 git-update-index
--remove -z --stdin
238 0) die
"No paths with -i does not make sense." ;;
242 git-diff-files
--name-only -z -- "$@" |
243 (cd "$TOP" && git-update-index
--remove -z --stdin)
250 if test -f "$GIT_DIR/MERGE_HEAD"
252 refuse_partial
"Cannot do a partial commit during a merge."
254 TMP_INDEX
="$GIT_DIR/tmp-index$$"
255 if test -z "$initial_commit"
257 # make sure index is clean at the specified paths, or
258 # they are additions.
259 dirty_in_index
=`git-diff-index --cached --name-status \
260 --diff-filter=DMTU HEAD -- "$@"`
261 test -z "$dirty_in_index" ||
262 refuse_partial
"Different in index and the last commit:
265 commit_only
=`git-ls-files -- "$@"` ;;
270 git-update-index
-q --refresh ||
exit 1
273 test -z "$TMP_INDEX" || {
274 test -f "$TMP_INDEX" && rm -f "$TMP_INDEX"
276 test -f "$SAVE_INDEX" && mv -f "$SAVE_INDEX" "$GIT_DIR/index"
281 if test -z "$initial_commit"
283 GIT_INDEX_FILE
="$TMP_INDEX" git-read-tree HEAD
287 echo "$commit_only" |
288 GIT_INDEX_FILE
="$TMP_INDEX" git-update-index
--add --remove --stdin &&
290 echo "$commit_only" |
291 git-update-index
--remove --stdin ||
295 if test t
= "$verify" && test -x "$GIT_DIR"/hooks
/pre-commit
299 GIT_INDEX_FILE
="$TMP_INDEX" "$GIT_DIR"/hooks
/pre-commit
301 "$GIT_DIR"/hooks
/pre-commit
305 if test "$log_message" != ''
308 elif test "$logfile" != ""
310 if test "$logfile" = -
313 echo >&2 "(reading log message from standard input)"
318 elif test "$use_commit" != ""
320 git-cat-file commit
"$use_commit" |
sed -e '1,/^$/d'
321 elif test -f "$GIT_DIR/MERGE_HEAD" && test -f "$GIT_DIR/MERGE_MSG"
323 cat "$GIT_DIR/MERGE_MSG"
324 fi | git-stripspace
>"$GIT_DIR"/COMMIT_EDITMSG
330 git-var GIT_COMMITTER_IDENT |
sed -e '
334 } >>"$GIT_DIR"/COMMIT_EDITMSG
338 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
340 echo "# It looks like you may be committing a MERGE."
341 echo "# If this is not correct, please remove the file"
342 echo "# $GIT_DIR/MERGE_HEAD"
343 echo "# and try again"
345 fi >>"$GIT_DIR"/COMMIT_EDITMSG
348 if test '' != "$force_author"
350 GIT_AUTHOR_NAME
=`expr "$force_author" : '\(.*[^ ]\) *<.*'` &&
351 GIT_AUTHOR_EMAIL
=`expr "$force_author" : '.*\(<.*\)'` &&
352 test '' != "$GIT_AUTHOR_NAME" &&
353 test '' != "$GIT_AUTHOR_EMAIL" ||
354 die
"malformatted --author parameter"
355 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
356 elif test '' != "$use_commit"
360 s/'\''/'\''\\'\'\''/g
362 s/^author \([^<]*\) <[^>]*> .*$/\1/
364 s
/.
*/GIT_AUTHOR_NAME
='\''&'\''/p
367 s
/^author
[^
<]* <\
([^
>]*\
)> .
*$
/\
1/
369 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
372 s/^author [^<]* <[^>]*> \(.*\)$/\1/
374 s
/.
*/GIT_AUTHOR_DATE
='\''&'\''/p
379 set_author_env=`git-cat-file commit "$use_commit" |
380 LANG=C LC_ALL=C sed -ne "$pick_author_script"`
381 eval "$set_author_env"
382 export GIT_AUTHOR_NAME
383 export GIT_AUTHOR_EMAIL
384 export GIT_AUTHOR_DATE
388 if test -z "$initial_commit"
390 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
391 PARENTS="-p HEAD "`sed -e 's
/^
/-p /' "$GIT_DIR/MERGE_HEAD"`
394 if [ -z "$(git-ls-files)" ]; then
395 echo >&2 Nothing to commit
402 run_status >>"$GIT_DIR"/COMMIT_EDITMSG
403 if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" ]
405 rm -f "$GIT_DIR/COMMIT_EDITMSG"
411 case "${VISUAL:-$EDITOR},$TERM" in
413 echo >&2 "Terminal is dumb but no VISUAL nor EDITOR defined."
414 echo >&2 "Please supply the commit log message using either"
415 echo >&2 "-m or -F option. A boilerplate log message has"
416 echo >&2 "been prepared in $GIT_DIR/COMMIT_EDITMSG"
420 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG"
426 if test -x "$GIT_DIR"/hooks/commit-msg
428 "$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/COMMIT_EDITMSG || exit
432 grep -v '^
#' < "$GIT_DIR"/COMMIT_EDITMSG |
433 git-stripspace
> "$GIT_DIR"/COMMIT_MSG
435 if cnt
=`grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG |
440 if test -z "$TMP_INDEX"
442 tree
=$
(git-write-tree
)
444 tree
=$
(GIT_INDEX_FILE
="$TMP_INDEX" git-write-tree
) &&
447 commit
=$
(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree
$tree $PARENTS) &&
448 git-update-ref HEAD
$commit $current &&
449 rm -f -- "$GIT_DIR/MERGE_HEAD"
451 echo >&2 "* no commit message? aborting commit."
455 rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG"
458 if test -x "$GIT_DIR"/hooks
/post-commit
&& test "$ret" = 0
460 "$GIT_DIR"/hooks
/post-commit