3 # Copyright (c) 2005 Linus Torvalds
6 . git-sh-setup-script || die "Not a git archive"
9 die 'git commit [-a] [-v | --no-verify] [-m <message>] [-F <logfile>] [(-C|-c) <commit>] [<path>...]'
12 all= logfile= use_commit= no_edit= log_given= log_message= verify=t signoff=
13 while case "$#" in 0) break;; esac
19 -F=*|--f=*|--fi=*|--fil=*|--file=*)
21 logfile=`expr "$1" : '-[^=]*=\(.*\)'`
24 -F|--f|--fi|--fil|--file)
25 case "$#" in 1) usage ;; esac; shift
30 -m=*|--m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*)
32 log_message=`expr "$1" : '-[^=]*=\(.*\)'`
35 -m|--m|--me|--mes|--mess|--messa|--messag|--message)
36 case "$#" in 1) usage ;; esac; shift
41 -c=*|--ree=*|--reed=*|--reedi=*|--reedit=*|--reedit-=*|--reedit-m=*|\
42 --reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\
43 --reedit-messag=*|--reedit-message=*)
45 use_commit=`expr "$1" : '-[^=]*=\(.*\)'`
47 -c|--ree|--reed|--reedi|--reedit|--reedit-|--reedit-m|--reedit-me|\
48 --reedit-mes|--reedit-mess|--reedit-messa|--reedit-messag|--reedit-message)
49 case "$#" in 1) usage ;; esac; shift
53 -C=*|--reu=*|--reus=*|--reuse=*|--reuse-=*|--reuse-m=*|--reuse-me=*|\
54 --reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\
57 use_commit=`expr "$1" : '-[^=]*=\(.*\)'`
60 -C|--reu|--reus|--reuse|--reuse-|--reuse-m|--reuse-me|--reuse-mes|\
61 --reuse-mess|--reuse-messa|--reuse-messag|--reuse-message)
62 case "$#" in 1) usage ;; esac; shift
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 xargs -0 git-update-cache -q --remove --
99 git-diff-files --name-only -z "$@" |
100 xargs -0 git-update-cache -q --remove --
103 git-update-cache -q --refresh || exit 1
107 if test -x "$GIT_DIR"/hooks/pre-commit
109 "$GIT_DIR"/hooks/pre-commit || exit
113 if [ ! -r "$GIT_DIR/HEAD" ]
116 echo "# Initial commit"
118 git-ls-files | sed 's/^/# New file: /'
120 elif [ -f "$GIT_DIR/MERGE_HEAD" ]; then
122 echo "# It looks like your may be committing a MERGE."
123 echo "# If this is not correct, please remove the file"
124 echo "# $GIT_DIR/MERGE_HEAD"
125 echo "# and try again"
128 if test "$log_message" != ''
131 elif test "$logfile" != ""
133 if test "$logfile" = -
136 echo >&2 "(reading log message from standard input)"
141 elif test "$use_commit" != ""
143 git-cat-file commit "$use_commit" | sed -e '1,/^$/d'
144 fi | git-stripspace >>.editmsg
147 if [ ! -r "$GIT_DIR/HEAD" ]; then
148 if [ -z "$(git-ls-files)" ]; then
149 echo Nothing to commit 1>&2
154 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
155 PARENTS="-p HEAD -p MERGE_HEAD"
157 if test "$use_commit" != ""
162 s/^author \([^<]*\) <[^>]*> .*$/\1/
164 s/.*/GIT_AUTHOR_NAME='\''&'\''/p
167 s/^author [^<]* <\([^>]*\)> .*$/\1/
169 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
172 s/^author [^<]* <[^>]*> \(.*\)$/\1/
174 s/.*/GIT_AUTHOR_DATE='\''&'\''/p
179 set_author_env=`git-cat-file commit "$use_commit" |
180 sed -ne "$pick_author_script"`
181 eval "$set_author_env"
182 export GIT_AUTHOR_NAME
183 export GIT_AUTHOR_EMAIL
184 export GIT_AUTHOR_DATE
188 git-var GIT_COMMITTER_IDENT | sed -e '
194 git-status-script >>.editmsg
196 if [ "$?" != "0" -a ! -f $GIT_DIR/MERGE_HEAD ]
198 sed -ne '/^#/p' .editmsg
204 ${VISUAL:-${EDITOR:-vi}} .editmsg
210 if test -x "$GIT_DIR"/hooks/commit-msg
212 "$GIT_DIR"/hooks/commit-msg .editmsg || exit
216 grep -v '^#' < .editmsg | git-stripspace > .cmitmsg
217 grep -v -i '^Signed-off-by' .cmitmsg >.cmitchk
220 tree=$(git-write-tree) &&
221 commit=$(cat .cmitmsg | git-commit-tree $tree $PARENTS) &&
222 echo $commit > "$GIT_DIR/HEAD" &&
223 rm -f -- "$GIT_DIR/MERGE_HEAD"
225 echo >&2 "* no commit message? aborting commit."
229 rm -f .cmitmsg .editmsg .cmitchk
231 if test -x "$GIT_DIR"/hooks/post-commit && test "$ret" = 0
233 "$GIT_DIR"/hooks/post-commit