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
= verify
= 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 -v|
--v|
--ve|
--ver|
--veri|
--verif|
--verify)
85 die
"Only one of -c/-C/-F/-m can be used." ;;
90 git-diff-files
--name-only -z |
91 xargs -0 git-update-cache
-q -- ||
exit 1 ;;
93 git-update-cache
-q --refresh -- "$@" ||
exit 1
97 # This is slightly modified from Andrew Morton's Perfect Patch.
98 # Lines you introduce should not have trailing whitespace.
99 # Also check for an indentation that has SP before a TAB.
104 my $reported_filename = "";
107 my ($why, $line) = @_;
110 print "* You have some suspicious patch lines:\n";
114 if ($reported_filename ne $filename) {
115 print "* In $filename\n";
116 $reported_filename = $filename;
118 print "* $why (line $lineno)\n$line\n";
120 open $fh, "-|", qw(git-diff-cache -p -M --cached HEAD);
122 if (m|^diff --git a/(.*) b/\1$|) {
126 if (/^@@ -\S+ \+(\d+)/) {
138 bad_line("trailing whitespace", $_);
141 bad_line("indent SP followed by a TAB", $_);
150 if [ ! -r "$GIT_DIR/HEAD" ]; then
151 if [ -z "$(git-ls-files)" ]; then
152 echo Nothing to commit
1>&2
157 echo "# Initial commit"
159 t
) echo "# (ignoring your commit message for initial commit)"
163 git-ls-files |
sed 's/^/# New file: /'
169 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
171 echo "# It looks like your may be committing a MERGE."
172 echo "# If this is not correct, please remove the file"
173 echo "# $GIT_DIR/MERGE_HEAD"
174 echo "# and try again"
176 t
) echo "# (ignoring your commit message for merge commit)"
180 PARENTS
="-p HEAD -p MERGE_HEAD"
181 elif test "$log_message" != ''
184 elif test "$logfile" != ""
186 if test "$logfile" = -
189 echo >&2 "(reading log message from standard input)"
194 elif test "$use_commit" != ""
199 s/^author \([^<]*\) <[^>]*> .*$/\1/
201 s
/.
*/GIT_AUTHOR_NAME
='\''&'\''/p
204 s
/^author
[^
<]* <\
([^
>]*\
)> .
*$
/\
1/
206 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
209 s/^author [^<]* <[^>]*> \(.*\)$/\1/
211 s
/.
*/GIT_AUTHOR_DATE
='\''&'\''/p
216 set_author_env=`git-cat-file commit "$use_commit" |
217 sed -ne "$pick_author_script"`
218 eval "$set_author_env"
219 export GIT_AUTHOR_NAME
220 export GIT_AUTHOR_EMAIL
221 export GIT_AUTHOR_DATE
222 git-cat-file commit "$use_commit" |
225 git-stripspace >.editmsg
228 git-var GIT_COMMITTER_IDENT | sed -e '
230 s
/^
/Signed-off-by
: /' >>.editmsg ;;
232 git-status-script >>.editmsg
234 if [ "$?" != "0" -a ! -f $GIT_DIR/MERGE_HEAD ]
242 ${VISUAL:-${EDITOR:-vi}} .editmsg
245 grep -v '^
#' < .editmsg | git-stripspace > .cmitmsg
246 grep -v -i '^Signed-off-by' .cmitmsg
>.cmitchk
249 tree
=$
(git-write-tree
) &&
250 commit
=$
(cat .cmitmsg | git-commit-tree
$tree $PARENTS) &&
251 echo $commit > "$GIT_DIR/HEAD" &&
252 rm -f -- "$GIT_DIR/MERGE_HEAD"
254 echo >&2 "* no commit message? aborting commit."
258 rm -f .cmitmsg .editmsg .cmitchk