3 # Copyright (c) 2005 Linus Torvalds
6 . git-sh-setup-script || die
"Not a git archive"
9 die
'git commit [-a] [-m <message>] [-F <logfile>] [(-C|-c) <commit>] [<path>...]'
12 all
= logfile
= use_commit
= no_edit
= log_given
= log_message
=
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
79 die
"Only one of -c/-C/-F/-m can be used." ;;
84 git-diff-files
--name-only -z |
85 xargs -0 git-update-cache
-q -- ||
exit 1 ;;
87 git-update-cache
-q --refresh -- "$@" ||
exit 1
90 if [ ! -r "$GIT_DIR/HEAD" ]; then
91 if [ -z "$(git-ls-files)" ]; then
92 echo Nothing to commit
1>&2
97 echo "# Initial commit"
99 t
) echo "# (ignoring your commit message for initial commit)"
103 git-ls-files |
sed 's/^/# New file: /'
109 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
111 echo "# It looks like your may be committing a MERGE."
112 echo "# If this is not correct, please remove the file"
113 echo "# $GIT_DIR/MERGE_HEAD"
114 echo "# and try again"
116 t
) echo "# (ignoring your commit message for merge commit)"
120 PARENTS
="-p HEAD -p MERGE_HEAD"
121 elif test "$log_message" != ''
124 elif test "$logfile" != ""
126 if test "$logfile" = -
129 echo >&2 "(reading log message from standard input)"
134 elif test "$use_commit" != ""
139 s/^author \([^<]*\) <[^>]*> .*$/\1/
141 s
/.
*/GIT_AUTHOR_NAME
='\''&'\''/p
144 s
/^author
[^
<]* <\
([^
>]*\
)> .
*$
/\
1/
146 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
149 s/^author [^<]* <[^>]*> \(.*\)$/\1/
151 s
/.
*/GIT_AUTHOR_DATE
='\''&'\''/p
156 set_author_env=`git-cat-file commit "$use_commit" |
157 sed -ne "$pick_author_script"`
158 eval "$set_author_env"
159 export GIT_AUTHOR_NAME
160 export GIT_AUTHOR_EMAIL
161 export GIT_AUTHOR_DATE
162 git-cat-file commit "$use_commit" |
165 git-status-script >>.editmsg
167 if [ "$?" != "0" -a ! -f $GIT_DIR/MERGE_HEAD ]
175 ${VISUAL:-${EDITOR:-vi}} .editmsg
178 grep -v '^
#' < .editmsg | git-stripspace > .cmitmsg
181 tree
=$
(git-write-tree
) &&
182 commit
=$
(cat .cmitmsg | git-commit-tree
$tree $PARENTS) &&
183 echo $commit > "$GIT_DIR/HEAD" &&
184 rm -f -- "$GIT_DIR/MERGE_HEAD"
186 echo >&2 "* no commit message? aborting commit."
190 rm -f .cmitmsg .editmsg