You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
234 lines
5.0 KiB
234 lines
5.0 KiB
20 years ago
|
#!/bin/sh
|
||
20 years ago
|
#
|
||
|
# Copyright (c) 2005 Linus Torvalds
|
||
|
#
|
||
|
|
||
19 years ago
|
. git-sh-setup || die "Not a git archive"
|
||
20 years ago
|
|
||
20 years ago
|
usage () {
|
||
20 years ago
|
die 'git commit [-a] [-v | --no-verify] [-m <message>] [-F <logfile>] [(-C|-c) <commit>] [<path>...]'
|
||
20 years ago
|
}
|
||
|
|
||
20 years ago
|
all= logfile= use_commit= no_edit= log_given= log_message= verify=t signoff=
|
||
20 years ago
|
while case "$#" in 0) break;; esac
|
||
20 years ago
|
do
|
||
20 years ago
|
case "$1" in
|
||
|
-a|--a|--al|--all)
|
||
|
all=t
|
||
|
shift ;;
|
||
|
-F=*|--f=*|--fi=*|--fil=*|--file=*)
|
||
|
log_given=t$log_given
|
||
|
logfile=`expr "$1" : '-[^=]*=\(.*\)'`
|
||
|
no_edit=t
|
||
|
shift ;;
|
||
|
-F|--f|--fi|--fil|--file)
|
||
|
case "$#" in 1) usage ;; esac; shift
|
||
|
log_given=t$log_given
|
||
|
logfile="$1"
|
||
|
no_edit=t
|
||
|
shift ;;
|
||
|
-m=*|--m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*)
|
||
|
log_given=t$log_given
|
||
|
log_message=`expr "$1" : '-[^=]*=\(.*\)'`
|
||
|
no_edit=t
|
||
|
shift ;;
|
||
|
-m|--m|--me|--mes|--mess|--messa|--messag|--message)
|
||
|
case "$#" in 1) usage ;; esac; shift
|
||
|
log_given=t$log_given
|
||
|
log_message="$1"
|
||
|
no_edit=t
|
||
|
shift ;;
|
||
|
-c=*|--ree=*|--reed=*|--reedi=*|--reedit=*|--reedit-=*|--reedit-m=*|\
|
||
|
--reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\
|
||
|
--reedit-messag=*|--reedit-message=*)
|
||
|
log_given=t$log_given
|
||
|
use_commit=`expr "$1" : '-[^=]*=\(.*\)'`
|
||
|
shift ;;
|
||
|
-c|--ree|--reed|--reedi|--reedit|--reedit-|--reedit-m|--reedit-me|\
|
||
|
--reedit-mes|--reedit-mess|--reedit-messa|--reedit-messag|--reedit-message)
|
||
|
case "$#" in 1) usage ;; esac; shift
|
||
|
log_given=t$log_given
|
||
|
use_commit="$1"
|
||
|
shift ;;
|
||
|
-C=*|--reu=*|--reus=*|--reuse=*|--reuse-=*|--reuse-m=*|--reuse-me=*|\
|
||
|
--reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\
|
||
|
--reuse-message=*)
|
||
|
log_given=t$log_given
|
||
|
use_commit=`expr "$1" : '-[^=]*=\(.*\)'`
|
||
|
no_edit=t
|
||
|
shift ;;
|
||
|
-C|--reu|--reus|--reuse|--reuse-|--reuse-m|--reuse-me|--reuse-mes|\
|
||
|
--reuse-mess|--reuse-messa|--reuse-messag|--reuse-message)
|
||
|
case "$#" in 1) usage ;; esac; shift
|
||
|
log_given=t$log_given
|
||
|
use_commit="$1"
|
||
|
no_edit=t
|
||
|
shift ;;
|
||
20 years ago
|
-e|--e|--ed|--edi|--edit)
|
||
|
no_edit=
|
||
|
shift ;;
|
||
20 years ago
|
-s|--s|--si|--sig|--sign|--signo|--signof|--signoff)
|
||
|
signoff=t
|
||
|
shift ;;
|
||
20 years ago
|
-n|--n|--no|--no-|--no-v|--no-ve|--no-ver|--no-veri|--no-verif|--no-verify)
|
||
|
verify=
|
||
|
shift ;;
|
||
20 years ago
|
-v|--v|--ve|--ver|--veri|--verif|--verify)
|
||
|
verify=t
|
||
|
shift ;;
|
||
20 years ago
|
--)
|
||
20 years ago
|
shift
|
||
20 years ago
|
break ;;
|
||
|
-*)
|
||
|
usage ;;
|
||
|
*)
|
||
|
break ;;
|
||
|
esac
|
||
20 years ago
|
done
|
||
|
|
||
20 years ago
|
case "$log_given" in
|
||
|
tt*)
|
||
|
die "Only one of -c/-C/-F/-m can be used." ;;
|
||
|
esac
|
||
|
|
||
20 years ago
|
case "$all,$#" in
|
||
|
t,*)
|
||
20 years ago
|
git-diff-files --name-only -z |
|
||
19 years ago
|
xargs -0 git-update-index -q --remove --
|
||
20 years ago
|
;;
|
||
20 years ago
|
,0)
|
||
|
;;
|
||
20 years ago
|
*)
|
||
|
git-diff-files --name-only -z "$@" |
|
||
19 years ago
|
xargs -0 git-update-index -q --remove --
|
||
20 years ago
|
;;
|
||
|
esac || exit 1
|
||
19 years ago
|
git-update-index -q --refresh || exit 1
|
||
20 years ago
|
|
||
20 years ago
|
case "$verify" in
|
||
|
t)
|
||
20 years ago
|
if test -x "$GIT_DIR"/hooks/pre-commit
|
||
|
then
|
||
|
"$GIT_DIR"/hooks/pre-commit || exit
|
||
|
fi
|
||
20 years ago
|
esac
|
||
|
|
||
20 years ago
|
if test "$log_message" != ''
|
||
|
then
|
||
|
echo "$log_message"
|
||
|
elif test "$logfile" != ""
|
||
|
then
|
||
|
if test "$logfile" = -
|
||
|
then
|
||
|
test -t 0 &&
|
||
|
echo >&2 "(reading log message from standard input)"
|
||
|
cat
|
||
|
else
|
||
|
cat <"$logfile"
|
||
|
fi
|
||
|
elif test "$use_commit" != ""
|
||
|
then
|
||
|
git-cat-file commit "$use_commit" | sed -e '1,/^$/d'
|
||
19 years ago
|
fi | git-stripspace >.editmsg
|
||
|
|
||
|
case "$signoff" in
|
||
|
t)
|
||
|
git-var GIT_COMMITTER_IDENT | sed -e '
|
||
|
s/>.*/>/
|
||
|
s/^/Signed-off-by: /
|
||
|
' >>.editmsg
|
||
|
;;
|
||
|
esac
|
||
|
|
||
|
if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
|
||
|
echo "#"
|
||
|
echo "# It looks like your may be committing a MERGE."
|
||
|
echo "# If this is not correct, please remove the file"
|
||
|
echo "# $GIT_DIR/MERGE_HEAD"
|
||
|
echo "# and try again"
|
||
|
echo "#"
|
||
|
fi >>.editmsg
|
||
20 years ago
|
|
||
20 years ago
|
PARENTS="-p HEAD"
|
||
20 years ago
|
if [ ! -r "$GIT_DIR/HEAD" ]; then
|
||
20 years ago
|
if [ -z "$(git-ls-files)" ]; then
|
||
|
echo Nothing to commit 1>&2
|
||
|
exit 1
|
||
|
fi
|
||
|
PARENTS=""
|
||
|
else
|
||
20 years ago
|
if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
|
||
20 years ago
|
PARENTS="-p HEAD -p MERGE_HEAD"
|
||
20 years ago
|
fi
|
||
|
if test "$use_commit" != ""
|
||
20 years ago
|
then
|
||
|
pick_author_script='
|
||
|
/^author /{
|
||
|
h
|
||
|
s/^author \([^<]*\) <[^>]*> .*$/\1/
|
||
|
s/'\''/'\''\'\'\''/g
|
||
|
s/.*/GIT_AUTHOR_NAME='\''&'\''/p
|
||
|
|
||
|
g
|
||
|
s/^author [^<]* <\([^>]*\)> .*$/\1/
|
||
|
s/'\''/'\''\'\'\''/g
|
||
|
s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
|
||
|
|
||
|
g
|
||
|
s/^author [^<]* <[^>]*> \(.*\)$/\1/
|
||
|
s/'\''/'\''\'\'\''/g
|
||
|
s/.*/GIT_AUTHOR_DATE='\''&'\''/p
|
||
|
|
||
|
q
|
||
|
}
|
||
|
'
|
||
|
set_author_env=`git-cat-file commit "$use_commit" |
|
||
|
sed -ne "$pick_author_script"`
|
||
|
eval "$set_author_env"
|
||
|
export GIT_AUTHOR_NAME
|
||
|
export GIT_AUTHOR_EMAIL
|
||
|
export GIT_AUTHOR_DATE
|
||
20 years ago
|
fi
|
||
20 years ago
|
fi
|
||
19 years ago
|
git-status >>.editmsg
|
||
20 years ago
|
if [ "$?" != "0" -a ! -f $GIT_DIR/MERGE_HEAD ]
|
||
20 years ago
|
then
|
||
20 years ago
|
rm -f .editmsg
|
||
19 years ago
|
git-status
|
||
20 years ago
|
exit 1
|
||
|
fi
|
||
20 years ago
|
case "$no_edit" in
|
||
20 years ago
|
'')
|
||
|
${VISUAL:-${EDITOR:-vi}} .editmsg
|
||
|
;;
|
||
|
esac
|
||
20 years ago
|
|
||
|
case "$verify" in
|
||
|
t)
|
||
|
if test -x "$GIT_DIR"/hooks/commit-msg
|
||
|
then
|
||
|
"$GIT_DIR"/hooks/commit-msg .editmsg || exit
|
||
|
fi
|
||
|
esac
|
||
|
|
||
20 years ago
|
grep -v '^#' < .editmsg | git-stripspace > .cmitmsg
|
||
20 years ago
|
grep -v -i '^Signed-off-by' .cmitmsg >.cmitchk
|
||
|
if test -s .cmitchk
|
||
20 years ago
|
then
|
||
20 years ago
|
tree=$(git-write-tree) &&
|
||
|
commit=$(cat .cmitmsg | git-commit-tree $tree $PARENTS) &&
|
||
20 years ago
|
echo $commit > "$GIT_DIR/HEAD" &&
|
||
|
rm -f -- "$GIT_DIR/MERGE_HEAD"
|
||
20 years ago
|
else
|
||
|
echo >&2 "* no commit message? aborting commit."
|
||
|
false
|
||
|
fi
|
||
20 years ago
|
ret="$?"
|
||
20 years ago
|
rm -f .cmitmsg .editmsg .cmitchk
|
||
20 years ago
|
|
||
|
if test -x "$GIT_DIR"/hooks/post-commit && test "$ret" = 0
|
||
|
then
|
||
|
"$GIT_DIR"/hooks/post-commit
|
||
|
fi
|
||
20 years ago
|
exit "$ret"
|