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 "Experienced git users:"
17 echo >&2 "You might have meant to say 'git commit -i paths...', perhaps?"
31 while case "$#" in 0) break;; esac
34 -F|
--F|
-f|
--f|
--fi|
--fil|
--file)
35 case "$#" in 1) usage
;; esac
45 logfile
=`expr "$1" : '-[Ff]\(.*\)'`
48 --F=*|
--f=*|
--fi=*|
--fil=*|
--file=*)
51 logfile
=`expr "$1" : '-[^=]*=\(.*\)'`
58 --au=*|
--aut=*|
--auth=*|
--autho=*|
--author=*)
59 force_author
=`expr "$1" : '-[^=]*=\(.*\)'`
62 --au|
--aut|
--auth|
--autho|
--author)
63 case "$#" in 1) usage
;; esac
68 -e|
--e|
--ed|
--edi|
--edit)
72 -i|
--i|
--in|
--inc|
--incl|
--inclu|
--includ|
--include)
76 -m|
--m|
--me|
--mes|
--mess|
--messa|
--messag|
--message)
77 case "$#" in 1) usage
;; esac
86 log_message
=`expr "$1" : '-m\(.*\)'`
90 --m=*|
--me=*|
--mes=*|
--mess=*|
--messa=*|
--messag=*|
--message=*)
92 log_message
=`expr "$1" : '-[^=]*=\(.*\)'`
96 -n|
--n|
--no|
--no-|
--no-v|
--no-ve|
--no-ver|
--no-veri|
--no-verif|
--no-verify)
101 case "$#" in 1) usage
;; esac
103 log_given
=t
$log_given
108 --ree=*|
--reed=*|
--reedi=*|
--reedit=*|
--reedit-=*|
--reedit-m=*|\
109 --reedit-me=*|
--reedit-mes=*|
--reedit-mess=*|
--reedit-messa=*|\
110 --reedit-messag=*|
--reedit-message=*)
111 log_given
=t
$log_given
112 use_commit
=`expr "$1" : '-[^=]*=\(.*\)'`
116 --ree|
--reed|
--reedi|
--reedit|
--reedit-|
--reedit-m|
--reedit-me|\
117 --reedit-mes|
--reedit-mess|
--reedit-messa|
--reedit-messag|
--reedit-message)
118 case "$#" in 1) usage
;; esac
120 log_given
=t
$log_given
126 case "$#" in 1) usage
;; esac
128 log_given
=t
$log_given
133 --reu=*|
--reus=*|
--reuse=*|
--reuse-=*|
--reuse-m=*|
--reuse-me=*|\
134 --reuse-mes=*|
--reuse-mess=*|
--reuse-messa=*|
--reuse-messag=*|\
136 log_given
=t
$log_given
137 use_commit
=`expr "$1" : '-[^=]*=\(.*\)'`
141 --reu|
--reus|
--reuse|
--reuse-|
--reuse-m|
--reuse-me|
--reuse-mes|\
142 --reuse-mess|
--reuse-messa|
--reuse-messag|
--reuse-message)
143 case "$#" in 1) usage
;; esac
145 log_given
=t
$log_given
150 -s|
--s|
--si|
--sig|
--sign|
--signo|
--signof|
--signoff)
154 -v|
--v|
--ve|
--ver|
--veri|
--verif|
--verify)
173 die
"Only one of -c/-C/-F/-m can be used." ;;
176 TOP
=`git-rev-parse --show-cdup`
180 die
"Cannot use -a and -i at the same time." ;;
182 SAVE_INDEX
="$GIT_DIR/save-index$$" &&
183 cp "$GIT_DIR/index" "$SAVE_INDEX" &&
189 git-diff-files
--name-only -z |
190 git-update-index
--remove -z --stdin
195 0) die
"No paths with -i does not make sense." ;;
197 SAVE_INDEX
="$GIT_DIR/save-index$$" &&
198 cp "$GIT_DIR/index" "$SAVE_INDEX" &&
199 git-diff-files
--name-only -z -- "$@" |
200 git-update-index
--remove -z --stdin
207 if test -f "$GIT_DIR/MERGE_HEAD"
209 refuse_partial
"Cannot do a partial commit during a merge."
211 TMP_INDEX
="$GIT_DIR/tmp-index$$"
212 if test -z "$initial_commit"
214 # make sure index is clean at the specified paths, or
215 # they are additions.
216 dirty_in_index
=`git-diff-index --cached --name-status \
217 --diff-filter=DMTXU HEAD -- "$@"`
218 test -z "$dirty_in_index" ||
219 refuse_partial
"Cannot do a partial commit of paths dirty in index:
223 commit_only
=`git-ls-files -- "$@"` ;;
228 git-update-index
-q --refresh ||
exit 1
231 test -f "$TMP_INDEX" && rm -f "$TMP_INDEX"
232 test -f "$SAVE_INDEX" && mv -f "$SAVE_INDEX" "$GIT_DIR/index"
237 if test -z "$initial_commit"
239 GIT_INDEX_FILE
="$TMP_INDEX" git-read-tree HEAD
243 echo "$commit_only" |
244 GIT_INDEX_FILE
="$TMP_INDEX" git-update-index
--add --remove --stdin &&
245 echo "$commit_only" |
246 git-update-index
--remove --stdin ||
253 if test t
= "$verify" && test -x "$GIT_DIR"/hooks
/pre-commit
257 GIT_INDEX_FILE
="$TMP_INDEX" "$GIT_DIR"/hooks
/pre-commit
259 "$GIT_DIR"/hooks
/pre-commit
263 if test "$log_message" != ''
266 elif test "$logfile" != ""
268 if test "$logfile" = -
271 echo >&2 "(reading log message from standard input)"
276 elif test "$use_commit" != ""
278 git-cat-file commit
"$use_commit" |
sed -e '1,/^$/d'
279 elif test -f "$GIT_DIR/MERGE_HEAD" && test -f "$GIT_DIR/MERGE_MSG"
281 cat "$GIT_DIR/MERGE_MSG"
282 fi | git-stripspace
>"$GIT_DIR"/COMMIT_EDITMSG
288 git-var GIT_COMMITTER_IDENT |
sed -e '
292 } >>"$GIT_DIR"/COMMIT_EDITMSG
296 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
298 echo "# It looks like you may be committing a MERGE."
299 echo "# If this is not correct, please remove the file"
300 echo "# $GIT_DIR/MERGE_HEAD"
301 echo "# and try again"
303 fi >>"$GIT_DIR"/COMMIT_EDITMSG
306 if test '' != "$use_commit"
310 s/'\''/'\''\\'\'\''/g
312 s/^author \([^<]*\) <[^>]*> .*$/\1/
314 s
/.
*/GIT_AUTHOR_NAME
='\''&'\''/p
317 s
/^author
[^
<]* <\
([^
>]*\
)> .
*$
/\
1/
319 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
322 s/^author [^<]* <[^>]*> \(.*\)$/\1/
324 s
/.
*/GIT_AUTHOR_DATE
='\''&'\''/p
329 set_author_env=`git-cat-file commit "$use_commit" |
330 LANG=C LC_ALL=C sed -ne "$pick_author_script"`
331 eval "$set_author_env"
332 export GIT_AUTHOR_NAME
333 export GIT_AUTHOR_EMAIL
334 export GIT_AUTHOR_DATE
335 elif test '' != "$force_author"
337 GIT_AUTHOR_NAME=`expr "$force_author" : '\
(.
*[^
]\
) *<.
*'` &&
338 GIT_AUTHOR_EMAIL=`expr "$force_author" : '.
*\
(<.
*\
)'` &&
339 test '' != "$GIT_AUTHOR_NAME" &&
340 test '' != "$GIT_AUTHOR_EMAIL" ||
341 die "malformatted --author parameter"
342 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
346 if test -z "$initial_commit"
348 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
349 PARENTS="-p HEAD "`sed -e 's
/^
/-p /' "$GIT_DIR/MERGE_HEAD"`
352 if [ -z "$(git-ls-files)" ]; then
353 echo Nothing to commit 1>&2
364 git-status >>"$GIT_DIR"/COMMIT_EDITMSG
366 if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" ]
368 rm -f "$GIT_DIR/COMMIT_EDITMSG"
378 case "${VISUAL:-$EDITOR},$TERM" in
380 echo >&2 "Terminal is dumb but no VISUAL nor EDITOR defined."
381 echo >&2 "Please supply the commit log message using either"
382 echo >&2 "-m or -F option. A boilerplate log message has"
383 echo >&2 "been prepared in $GIT_DIR/COMMIT_EDITMSG"
387 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG"
393 if test -x "$GIT_DIR"/hooks/commit-msg
395 "$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/COMMIT_EDITMSG || exit
399 grep -v '^
#' < "$GIT_DIR"/COMMIT_EDITMSG |
400 git-stripspace
> "$GIT_DIR"/COMMIT_MSG
402 if cnt
=`grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG |
407 if test -z "$TMP_INDEX"
409 tree
=$
(git-write-tree
)
411 tree
=$
(GIT_INDEX_FILE
="$TMP_INDEX" git-write-tree
) &&
414 commit
=$
(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree
$tree $PARENTS) &&
415 git-update-ref HEAD
$commit $current &&
416 rm -f -- "$GIT_DIR/MERGE_HEAD"
418 echo >&2 "* no commit message? aborting commit."
422 rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG"
425 if test -x "$GIT_DIR"/hooks
/post-commit
&& test "$ret" = 0
427 "$GIT_DIR"/hooks
/post-commit