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 --
94 git-diff-files
--name-only -z "$@" |
95 xargs -0 git-update-cache
-q --
98 git-update-cache
-q --refresh ||
exit 1
102 # This is slightly modified from Andrew Morton's Perfect Patch.
103 # Lines you introduce should not have trailing whitespace.
104 # Also check for an indentation that has SP before a TAB.
109 my $reported_filename = "";
112 my ($why, $line) = @_;
115 print "* You have some suspicious patch lines:\n";
119 if ($reported_filename ne $filename) {
120 print "* In $filename\n";
121 $reported_filename = $filename;
123 print "* $why (line $lineno)\n$line\n";
125 open $fh, "-|", qw(git-diff-cache -p -M --cached HEAD);
127 if (m|^diff --git a/(.*) b/\1$|) {
131 if (/^@@ -\S+ \+(\d+)/) {
143 bad_line("trailing whitespace", $_);
146 bad_line("indent SP followed by a TAB", $_);
155 if [ ! -r "$GIT_DIR/HEAD" ]; then
156 if [ -z "$(git-ls-files)" ]; then
157 echo Nothing to commit
1>&2
162 echo "# Initial commit"
164 t
) echo "# (ignoring your commit message for initial commit)"
168 git-ls-files |
sed 's/^/# New file: /'
174 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
177 echo "# It looks like your may be committing a MERGE."
178 echo "# If this is not correct, please remove the file"
179 echo "# $GIT_DIR/MERGE_HEAD"
180 echo "# and try again"
182 t
) echo "# (ignoring your commit message for merge commit)"
187 git-stripspace
>.editmsg
188 PARENTS
="-p HEAD -p MERGE_HEAD"
189 elif test "$log_message" != ''
191 echo "$log_message" |
192 git-stripspace
>.editmsg
193 elif test "$logfile" != ""
195 if test "$logfile" = -
198 echo >&2 "(reading log message from standard input)"
203 git-stripspace
>.editmsg
204 elif test "$use_commit" != ""
209 s/^author \([^<]*\) <[^>]*> .*$/\1/
211 s
/.
*/GIT_AUTHOR_NAME
='\''&'\''/p
214 s
/^author
[^
<]* <\
([^
>]*\
)> .
*$
/\
1/
216 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
219 s/^author [^<]* <[^>]*> \(.*\)$/\1/
221 s
/.
*/GIT_AUTHOR_DATE
='\''&'\''/p
226 set_author_env=`git-cat-file commit "$use_commit" |
227 sed -ne "$pick_author_script"`
228 eval "$set_author_env"
229 export GIT_AUTHOR_NAME
230 export GIT_AUTHOR_EMAIL
231 export GIT_AUTHOR_DATE
232 git-cat-file commit "$use_commit" |
234 git-stripspace >.editmsg
239 git-var GIT_COMMITTER_IDENT | sed -e '
241 s
/^
/Signed-off-by
: /' >>.editmsg ;;
243 git-status-script >>.editmsg
245 if [ "$?" != "0" -a ! -f $GIT_DIR/MERGE_HEAD ]
253 ${VISUAL:-${EDITOR:-vi}} .editmsg
256 grep -v '^
#' < .editmsg | git-stripspace > .cmitmsg
257 grep -v -i '^Signed-off-by' .cmitmsg
>.cmitchk
260 tree
=$
(git-write-tree
) &&
261 commit
=$
(cat .cmitmsg | git-commit-tree
$tree $PARENTS) &&
262 echo $commit > "$GIT_DIR/HEAD" &&
263 rm -f -- "$GIT_DIR/MERGE_HEAD"
265 echo >&2 "* no commit message? aborting commit."
269 rm -f .cmitmsg .editmsg .cmitchk