2005-05-30 21:51:00 +02:00
|
|
|
#!/bin/sh
|
2005-06-25 11:22:05 +02:00
|
|
|
#
|
|
|
|
# Copyright (c) 2005 Linus Torvalds
|
|
|
|
#
|
|
|
|
|
2005-07-08 19:57:21 +02:00
|
|
|
. git-sh-setup-script || die "Not a git archive"
|
|
|
|
|
2005-06-25 11:22:05 +02:00
|
|
|
usage () {
|
2005-08-05 17:34:38 +02:00
|
|
|
die 'git commit [--all] [-m existing-commit] [<path>...]'
|
2005-06-25 11:22:05 +02:00
|
|
|
}
|
|
|
|
|
2005-07-19 13:20:39 +02:00
|
|
|
files=()
|
2005-06-25 11:22:05 +02:00
|
|
|
while case "$#" in 0) break ;; esac
|
|
|
|
do
|
|
|
|
case "$1" in
|
|
|
|
-m) shift
|
|
|
|
case "$#" in
|
|
|
|
0) usage ;;
|
2005-07-23 04:09:05 +02:00
|
|
|
*) use_commit=`git-rev-parse --verify "$1"` ||
|
2005-06-25 11:22:05 +02:00
|
|
|
exit ;;
|
|
|
|
esac
|
|
|
|
;;
|
2005-07-19 13:20:39 +02:00
|
|
|
--all)
|
|
|
|
files=($(git-diff-files --name-only))\
|
|
|
|
;;
|
2005-06-25 11:22:05 +02:00
|
|
|
*) break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2005-07-19 13:20:39 +02:00
|
|
|
git-update-cache -q --refresh -- "$@" "${files[@]}" || exit 1
|
2005-06-14 19:20:14 +02:00
|
|
|
PARENTS="-p HEAD"
|
2005-06-25 11:22:05 +02:00
|
|
|
if [ ! -r "$GIT_DIR/HEAD" ]; then
|
2005-06-14 19:20:14 +02:00
|
|
|
if [ -z "$(git-ls-files)" ]; then
|
|
|
|
echo Nothing to commit 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
(
|
|
|
|
echo "#"
|
|
|
|
echo "# Initial commit"
|
|
|
|
echo "#"
|
|
|
|
git-ls-files | sed 's/^/# New file: /'
|
|
|
|
echo "#"
|
|
|
|
) > .editmsg
|
|
|
|
PARENTS=""
|
|
|
|
else
|
2005-06-25 11:22:05 +02:00
|
|
|
if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
|
2005-06-14 19:20:14 +02:00
|
|
|
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 "#"
|
|
|
|
PARENTS="-p HEAD -p MERGE_HEAD"
|
2005-06-25 11:22:05 +02:00
|
|
|
elif test "$use_commit" != ""
|
|
|
|
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
|
|
|
|
git-cat-file commit "$use_commit" |
|
|
|
|
sed -e '1,/^$/d'
|
|
|
|
fi >.editmsg
|
|
|
|
git-status-script >>.editmsg
|
2005-06-14 19:20:14 +02:00
|
|
|
fi
|
2005-08-05 17:34:38 +02:00
|
|
|
if [ "$?" != "0" -a ! -f $GIT_DIR/MERGE_HEAD ]
|
2005-05-30 21:51:00 +02:00
|
|
|
then
|
|
|
|
cat .editmsg
|
2005-06-20 04:57:01 +02:00
|
|
|
rm .editmsg
|
2005-05-30 21:51:00 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2005-06-25 11:22:05 +02:00
|
|
|
case "$use_commit" in
|
|
|
|
'')
|
|
|
|
${VISUAL:-${EDITOR:-vi}} .editmsg
|
|
|
|
;;
|
|
|
|
esac
|
2005-05-30 21:51:00 +02:00
|
|
|
grep -v '^#' < .editmsg | git-stripspace > .cmitmsg
|
2005-06-20 04:57:01 +02:00
|
|
|
[ -s .cmitmsg ] &&
|
|
|
|
tree=$(git-write-tree) &&
|
|
|
|
commit=$(cat .cmitmsg | git-commit-tree $tree $PARENTS) &&
|
2005-06-25 11:22:05 +02:00
|
|
|
echo $commit > "$GIT_DIR/HEAD" &&
|
|
|
|
rm -f -- "$GIT_DIR/MERGE_HEAD"
|
2005-06-20 04:57:01 +02:00
|
|
|
ret="$?"
|
|
|
|
rm -f .cmitmsg .editmsg
|
|
|
|
exit "$ret"
|