3 # Copyright (c) 2005 Linus Torvalds
6 USAGE='[-a] [-s] [-v | --no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit>] [-e] [<path>...]'
9 all= logfile= use_commit= no_edit= log_given= log_message= verify=t signoff=
10 while case "$#" in 0) break;; esac
16 -F=*|--f=*|--fi=*|--fil=*|--file=*)
18 logfile=`expr "$1" : '-[^=]*=\(.*\)'`
21 -F|--f|--fi|--fil|--file)
22 case "$#" in 1) usage ;; esac; shift
27 -m=*|--m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*)
29 log_message=`expr "$1" : '-[^=]*=\(.*\)'`
32 -m|--m|--me|--mes|--mess|--messa|--messag|--message)
33 case "$#" in 1) usage ;; esac; shift
38 -c=*|--ree=*|--reed=*|--reedi=*|--reedit=*|--reedit-=*|--reedit-m=*|\
39 --reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\
40 --reedit-messag=*|--reedit-message=*)
42 use_commit=`expr "$1" : '-[^=]*=\(.*\)'`
44 -c|--ree|--reed|--reedi|--reedit|--reedit-|--reedit-m|--reedit-me|\
45 --reedit-mes|--reedit-mess|--reedit-messa|--reedit-messag|--reedit-message)
46 case "$#" in 1) usage ;; esac; shift
50 -C=*|--reu=*|--reus=*|--reuse=*|--reuse-=*|--reuse-m=*|--reuse-me=*|\
51 --reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\
54 use_commit=`expr "$1" : '-[^=]*=\(.*\)'`
57 -C|--reu|--reus|--reuse|--reuse-|--reuse-m|--reuse-me|--reuse-mes|\
58 --reuse-mess|--reuse-messa|--reuse-messag|--reuse-message)
59 case "$#" in 1) usage ;; esac; shift
64 -e|--e|--ed|--edi|--edit)
67 -s|--s|--si|--sig|--sign|--signo|--signof|--signoff)
70 -n|--n|--no|--no-|--no-v|--no-ve|--no-ver|--no-veri|--no-verif|--no-verify)
73 -v|--v|--ve|--ver|--veri|--verif|--verify)
88 die "Only one of -c/-C/-F/-m can be used." ;;
93 git-diff-files --name-only -z |
94 git-update-index --remove -z --stdin
97 die "Cannot use -a and explicit files at the same time."
102 git-diff-files --name-only -z -- "$@" |
103 git-update-index --remove -z --stdin
106 git-update-index -q --refresh || exit 1
110 if test -x "$GIT_DIR"/hooks/pre-commit
112 "$GIT_DIR"/hooks/pre-commit || exit
116 if test "$log_message" != ''
119 elif test "$logfile" != ""
121 if test "$logfile" = -
124 echo >&2 "(reading log message from standard input)"
129 elif test "$use_commit" != ""
131 git-cat-file commit "$use_commit" | sed -e '1,/^$/d'
132 elif test -f "$GIT_DIR/MERGE_HEAD" && test -f "$GIT_DIR/MERGE_MSG"
134 cat "$GIT_DIR/MERGE_MSG"
135 fi | git-stripspace >"$GIT_DIR"/COMMIT_EDITMSG
141 git-var GIT_COMMITTER_IDENT | sed -e '
145 } >>"$GIT_DIR"/COMMIT_EDITMSG
149 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
151 echo "# It looks like you may be committing a MERGE."
152 echo "# If this is not correct, please remove the file"
153 echo "# $GIT_DIR/MERGE_HEAD"
154 echo "# and try again"
156 fi >>"$GIT_DIR"/COMMIT_EDITMSG
159 if GIT_DIR="$GIT_DIR" git-rev-parse --verify HEAD >/dev/null 2>&1
161 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
162 PARENTS="-p HEAD "`sed -e 's/^/-p /' "$GIT_DIR/MERGE_HEAD"`
164 if test "$use_commit" != ""
168 s/'\''/'\''\\'\'\''/g
170 s/^author \([^<]*\) <[^>]*> .*$/\1/
172 s/.*/GIT_AUTHOR_NAME='\''&'\''/p
175 s/^author [^<]* <\([^>]*\)> .*$/\1/
177 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
180 s/^author [^<]* <[^>]*> \(.*\)$/\1/
182 s/.*/GIT_AUTHOR_DATE='\''&'\''/p
187 set_author_env=`git-cat-file commit "$use_commit" |
188 LANG=C LC_ALL=C sed -ne "$pick_author_script"`
189 eval "$set_author_env"
190 export GIT_AUTHOR_NAME
191 export GIT_AUTHOR_EMAIL
192 export GIT_AUTHOR_DATE
195 if [ -z "$(git-ls-files)" ]; then
196 echo Nothing to commit 1>&2
201 git-status >>"$GIT_DIR"/COMMIT_EDITMSG
202 if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" ]
204 rm -f "$GIT_DIR/COMMIT_EDITMSG"
210 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG"
216 if test -x "$GIT_DIR"/hooks/commit-msg
218 "$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/COMMIT_EDITMSG || exit
222 grep -v '^#' < "$GIT_DIR"/COMMIT_EDITMSG |
223 git-stripspace > "$GIT_DIR"/COMMIT_MSG
225 if cnt=`grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG |
230 tree=$(git-write-tree) &&
231 commit=$(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree $tree $PARENTS) &&
232 git-update-ref HEAD $commit $current &&
233 rm -f -- "$GIT_DIR/MERGE_HEAD"
235 echo >&2 "* no commit message? aborting commit."
239 rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG"
241 if test -x "$GIT_DIR"/hooks/post-commit && test "$ret" = 0
243 "$GIT_DIR"/hooks/post-commit