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.
640 lines
14 KiB
640 lines
14 KiB
20 years ago
|
#!/bin/sh
|
||
20 years ago
|
#
|
||
|
# Copyright (c) 2005 Linus Torvalds
|
||
19 years ago
|
# Copyright (c) 2006 Junio C Hamano
|
||
|
|
||
18 years ago
|
USAGE='[-a | --interactive] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit> | --amend] [-u] [-e] [--author <author>] [--template <file>] [[-i | -o] <path>...]'
|
||
19 years ago
|
SUBDIRECTORY_OK=Yes
|
||
17 years ago
|
OPTIONS_SPEC=
|
||
19 years ago
|
. git-sh-setup
|
||
18 years ago
|
require_work_tree
|
||
20 years ago
|
|
||
18 years ago
|
git rev-parse --verify HEAD >/dev/null 2>&1 || initial_commit=t
|
||
19 years ago
|
|
||
|
case "$0" in
|
||
|
*status)
|
||
|
status_only=t
|
||
18 years ago
|
;;
|
||
19 years ago
|
*commit)
|
||
|
status_only=
|
||
18 years ago
|
;;
|
||
19 years ago
|
esac
|
||
19 years ago
|
|
||
|
refuse_partial () {
|
||
|
echo >&2 "$1"
|
||
|
echo >&2 "You might have meant to say 'git commit -i paths...', perhaps?"
|
||
|
exit 1
|
||
|
}
|
||
|
|
||
17 years ago
|
TMP_INDEX=
|
||
17 years ago
|
THIS_INDEX="${GIT_INDEX_FILE:-$GIT_DIR/index}"
|
||
19 years ago
|
NEXT_INDEX="$GIT_DIR/next-index$$"
|
||
|
rm -f "$NEXT_INDEX"
|
||
19 years ago
|
save_index () {
|
||
19 years ago
|
cp -p "$THIS_INDEX" "$NEXT_INDEX"
|
||
19 years ago
|
}
|
||
|
|
||
19 years ago
|
run_status () {
|
||
19 years ago
|
# If TMP_INDEX is defined, that means we are doing
|
||
|
# "--only" partial commit, and that index file is used
|
||
|
# to build the tree for the commit. Otherwise, if
|
||
|
# NEXT_INDEX exists, that is the index file used to
|
||
|
# make the commit. Otherwise we are using as-is commit
|
||
|
# so the regular index file is what we use to compare.
|
||
|
if test '' != "$TMP_INDEX"
|
||
|
then
|
||
18 years ago
|
GIT_INDEX_FILE="$TMP_INDEX"
|
||
|
export GIT_INDEX_FILE
|
||
19 years ago
|
elif test -f "$NEXT_INDEX"
|
||
|
then
|
||
18 years ago
|
GIT_INDEX_FILE="$NEXT_INDEX"
|
||
|
export GIT_INDEX_FILE
|
||
19 years ago
|
fi
|
||
|
|
||
18 years ago
|
if test "$status_only" = "t" -o "$use_status_color" = "t"; then
|
||
|
color=
|
||
|
else
|
||
|
color=--nocolor
|
||
|
fi
|
||
18 years ago
|
git runstatus ${color} \
|
||
18 years ago
|
${verbose:+--verbose} \
|
||
|
${amend:+--amend} \
|
||
19 years ago
|
${untracked_files:+--untracked}
|
||
19 years ago
|
}
|
||
|
|
||
19 years ago
|
trap '
|
||
|
test -z "$TMP_INDEX" || {
|
||
|
test -f "$TMP_INDEX" && rm -f "$TMP_INDEX"
|
||
|
}
|
||
|
rm -f "$NEXT_INDEX"
|
||
|
' 0
|
||
|
|
||
|
################################################################
|
||
|
# Command line argument parsing and sanity checking
|
||
|
|
||
19 years ago
|
all=
|
||
|
also=
|
||
17 years ago
|
allow_empty=f
|
||
18 years ago
|
interactive=
|
||
19 years ago
|
only=
|
||
19 years ago
|
logfile=
|
||
|
use_commit=
|
||
19 years ago
|
amend=
|
||
19 years ago
|
edit_flag=
|
||
19 years ago
|
no_edit=
|
||
|
log_given=
|
||
|
log_message=
|
||
|
verify=t
|
||
18 years ago
|
quiet=
|
||
19 years ago
|
verbose=
|
||
19 years ago
|
signoff=
|
||
|
force_author=
|
||
19 years ago
|
only_include_assumed=
|
||
19 years ago
|
untracked_files=
|
||
18 years ago
|
templatefile="`git config commit.template`"
|
||
18 years ago
|
while test $# != 0
|
||
20 years ago
|
do
|
||
18 years ago
|
case "$1" in
|
||
|
-F|--F|-f|--f|--fi|--fil|--file)
|
||
|
case "$#" in 1) usage ;; esac
|
||
|
shift
|
||
|
no_edit=t
|
||
|
log_given=t$log_given
|
||
|
logfile="$1"
|
||
|
;;
|
||
|
-F*|-f*)
|
||
|
no_edit=t
|
||
|
log_given=t$log_given
|
||
18 years ago
|
logfile="${1#-[Ff]}"
|
||
18 years ago
|
;;
|
||
|
--F=*|--f=*|--fi=*|--fil=*|--file=*)
|
||
|
no_edit=t
|
||
|
log_given=t$log_given
|
||
18 years ago
|
logfile="${1#*=}"
|
||
18 years ago
|
;;
|
||
|
-a|--a|--al|--all)
|
||
|
all=t
|
||
|
;;
|
||
17 years ago
|
--allo|--allow|--allow-|--allow-e|--allow-em|--allow-emp|\
|
||
|
--allow-empt|--allow-empty)
|
||
|
allow_empty=t
|
||
|
;;
|
||
18 years ago
|
--au=*|--aut=*|--auth=*|--autho=*|--author=*)
|
||
18 years ago
|
force_author="${1#*=}"
|
||
18 years ago
|
;;
|
||
|
--au|--aut|--auth|--autho|--author)
|
||
|
case "$#" in 1) usage ;; esac
|
||
|
shift
|
||
|
force_author="$1"
|
||
|
;;
|
||
|
-e|--e|--ed|--edi|--edit)
|
||
|
edit_flag=t
|
||
|
;;
|
||
|
-i|--i|--in|--inc|--incl|--inclu|--includ|--include)
|
||
|
also=t
|
||
|
;;
|
||
18 years ago
|
--int|--inte|--inter|--intera|--interac|--interact|--interacti|\
|
||
|
--interactiv|--interactive)
|
||
|
interactive=t
|
||
|
;;
|
||
18 years ago
|
-o|--o|--on|--onl|--only)
|
||
|
only=t
|
||
|
;;
|
||
|
-m|--m|--me|--mes|--mess|--messa|--messag|--message)
|
||
|
case "$#" in 1) usage ;; esac
|
||
|
shift
|
||
|
log_given=m$log_given
|
||
18 years ago
|
log_message="${log_message:+${log_message}
|
||
19 years ago
|
|
||
18 years ago
|
}$1"
|
||
18 years ago
|
no_edit=t
|
||
|
;;
|
||
|
-m*)
|
||
|
log_given=m$log_given
|
||
18 years ago
|
log_message="${log_message:+${log_message}
|
||
19 years ago
|
|
||
18 years ago
|
}${1#-m}"
|
||
18 years ago
|
no_edit=t
|
||
|
;;
|
||
|
--m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*)
|
||
|
log_given=m$log_given
|
||
18 years ago
|
log_message="${log_message:+${log_message}
|
||
19 years ago
|
|
||
18 years ago
|
}${1#*=}"
|
||
18 years ago
|
no_edit=t
|
||
|
;;
|
||
|
-n|--n|--no|--no-|--no-v|--no-ve|--no-ver|--no-veri|--no-verif|\
|
||
|
--no-verify)
|
||
|
verify=
|
||
|
;;
|
||
|
--a|--am|--ame|--amen|--amend)
|
||
|
amend=t
|
||
|
use_commit=HEAD
|
||
|
;;
|
||
|
-c)
|
||
|
case "$#" in 1) usage ;; esac
|
||
|
shift
|
||
|
log_given=t$log_given
|
||
|
use_commit="$1"
|
||
|
no_edit=
|
||
|
;;
|
||
|
--ree=*|--reed=*|--reedi=*|--reedit=*|--reedit-=*|--reedit-m=*|\
|
||
|
--reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\
|
||
|
--reedit-messag=*|--reedit-message=*)
|
||
|
log_given=t$log_given
|
||
18 years ago
|
use_commit="${1#*=}"
|
||
18 years ago
|
no_edit=
|
||
|
;;
|
||
|
--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"
|
||
|
no_edit=
|
||
|
;;
|
||
|
-C)
|
||
|
case "$#" in 1) usage ;; esac
|
||
|
shift
|
||
|
log_given=t$log_given
|
||
|
use_commit="$1"
|
||
|
no_edit=t
|
||
|
;;
|
||
|
--reu=*|--reus=*|--reuse=*|--reuse-=*|--reuse-m=*|--reuse-me=*|\
|
||
|
--reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\
|
||
|
--reuse-message=*)
|
||
|
log_given=t$log_given
|
||
18 years ago
|
use_commit="${1#*=}"
|
||
18 years ago
|
no_edit=t
|
||
|
;;
|
||
|
--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
|
||
|
;;
|
||
|
-s|--s|--si|--sig|--sign|--signo|--signof|--signoff)
|
||
|
signoff=t
|
||
|
;;
|
||
18 years ago
|
-t|--t|--te|--tem|--temp|--templ|--templa|--templat|--template)
|
||
|
case "$#" in 1) usage ;; esac
|
||
|
shift
|
||
|
templatefile="$1"
|
||
|
no_edit=
|
||
|
;;
|
||
18 years ago
|
-q|--q|--qu|--qui|--quie|--quiet)
|
||
|
quiet=t
|
||
|
;;
|
||
18 years ago
|
-v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
|
||
|
verbose=t
|
||
|
;;
|
||
|
-u|--u|--un|--unt|--untr|--untra|--untrac|--untrack|--untracke|\
|
||
|
--untracked|--untracked-|--untracked-f|--untracked-fi|--untracked-fil|\
|
||
|
--untracked-file|--untracked-files)
|
||
|
untracked_files=t
|
||
|
;;
|
||
|
--)
|
||
|
shift
|
||
|
break
|
||
|
;;
|
||
|
-*)
|
||
|
usage
|
||
|
;;
|
||
|
*)
|
||
|
break
|
||
|
;;
|
||
|
esac
|
||
18 years ago
|
shift
|
||
20 years ago
|
done
|
||
19 years ago
|
case "$edit_flag" in t) no_edit= ;; esac
|
||
20 years ago
|
|
||
19 years ago
|
################################################################
|
||
|
# Sanity check options
|
||
|
|
||
19 years ago
|
case "$amend,$initial_commit" in
|
||
|
t,t)
|
||
18 years ago
|
die "You do not have anything to amend." ;;
|
||
19 years ago
|
t,)
|
||
18 years ago
|
if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
|
||
|
die "You are in the middle of a merge -- cannot amend."
|
||
|
fi ;;
|
||
19 years ago
|
esac
|
||
|
|
||
20 years ago
|
case "$log_given" in
|
||
|
tt*)
|
||
18 years ago
|
die "Only one of -c/-C/-F can be used." ;;
|
||
19 years ago
|
*tm*|*mt*)
|
||
18 years ago
|
die "Option -m cannot be combined with -c/-C/-F." ;;
|
||
20 years ago
|
esac
|
||
|
|
||
19 years ago
|
case "$#,$also,$only,$amend" in
|
||
|
*,t,t,*)
|
||
18 years ago
|
die "Only one of --include/--only can be used." ;;
|
||
19 years ago
|
0,t,,* | 0,,t,)
|
||
18 years ago
|
die "No paths with --include/--only does not make sense." ;;
|
||
19 years ago
|
0,,t,t)
|
||
18 years ago
|
only_include_assumed="# Clever... amending the last one with dirty index." ;;
|
||
19 years ago
|
0,,,*)
|
||
18 years ago
|
;;
|
||
19 years ago
|
*,,,*)
|
||
18 years ago
|
only_include_assumed="# Explicit paths specified without -i nor -o; assuming --only paths..."
|
||
|
also=
|
||
|
;;
|
||
19 years ago
|
esac
|
||
|
unset only
|
||
18 years ago
|
case "$all,$interactive,$also,$#" in
|
||
|
*t,*t,*)
|
||
|
die "Cannot use -a, --interactive or -i at the same time." ;;
|
||
17 years ago
|
t,,,[1-9]*)
|
||
19 years ago
|
die "Paths with -a does not make sense." ;;
|
||
17 years ago
|
,t,,[1-9]*)
|
||
18 years ago
|
die "Paths with --interactive does not make sense." ;;
|
||
|
,,t,0)
|
||
19 years ago
|
die "No paths with -i does not make sense." ;;
|
||
|
esac
|
||
|
|
||
18 years ago
|
if test ! -z "$templatefile" -a -z "$log_given"
|
||
|
then
|
||
|
if test ! -f "$templatefile"
|
||
|
then
|
||
|
die "Commit template file does not exist."
|
||
|
fi
|
||
|
fi
|
||
|
|
||
19 years ago
|
################################################################
|
||
|
# Prepare index to have a tree to be committed
|
||
19 years ago
|
|
||
19 years ago
|
case "$all,$also" in
|
||
|
t,)
|
||
18 years ago
|
if test ! -f "$THIS_INDEX"
|
||
|
then
|
||
|
die 'nothing to commit (use "git add file1 file2" to include for commit)'
|
||
|
fi
|
||
19 years ago
|
save_index &&
|
||
19 years ago
|
(
|
||
18 years ago
|
cd_to_toplevel &&
|
||
|
GIT_INDEX_FILE="$NEXT_INDEX" &&
|
||
|
export GIT_INDEX_FILE &&
|
||
18 years ago
|
git diff-files --name-only -z |
|
||
|
git update-index --remove -z --stdin
|
||
18 years ago
|
) || exit
|
||
20 years ago
|
;;
|
||
19 years ago
|
,t)
|
||
19 years ago
|
save_index &&
|
||
18 years ago
|
git ls-files --error-unmatch -- "$@" >/dev/null || exit
|
||
19 years ago
|
|
||
18 years ago
|
git diff-files --name-only -z -- "$@" |
|
||
19 years ago
|
(
|
||
18 years ago
|
cd_to_toplevel &&
|
||
|
GIT_INDEX_FILE="$NEXT_INDEX" &&
|
||
|
export GIT_INDEX_FILE &&
|
||
18 years ago
|
git update-index --remove -z --stdin
|
||
18 years ago
|
) || exit
|
||
20 years ago
|
;;
|
||
19 years ago
|
,)
|
||
18 years ago
|
if test "$interactive" = t; then
|
||
|
git add --interactive || exit
|
||
|
fi
|
||
19 years ago
|
case "$#" in
|
||
|
0)
|
||
18 years ago
|
;; # commit as-is
|
||
19 years ago
|
*)
|
||
18 years ago
|
if test -f "$GIT_DIR/MERGE_HEAD"
|
||
|
then
|
||
|
refuse_partial "Cannot do a partial commit during a merge."
|
||
|
fi
|
||
18 years ago
|
|
||
18 years ago
|
TMP_INDEX="$GIT_DIR/tmp-index$$"
|
||
18 years ago
|
W=
|
||
|
test -z "$initial_commit" && W=--with-tree=HEAD
|
||
|
commit_only=`git ls-files --error-unmatch $W -- "$@"` || exit
|
||
19 years ago
|
|
||
18 years ago
|
# Build a temporary index and update the real index
|
||
18 years ago
|
# the same way.
|
||
|
if test -z "$initial_commit"
|
||
|
then
|
||
18 years ago
|
GIT_INDEX_FILE="$THIS_INDEX" \
|
||
18 years ago
|
git read-tree --index-output="$TMP_INDEX" -i -m HEAD
|
||
18 years ago
|
else
|
||
|
rm -f "$TMP_INDEX"
|
||
|
fi || exit
|
||
19 years ago
|
|
||
18 years ago
|
printf '%s\n' "$commit_only" |
|
||
18 years ago
|
GIT_INDEX_FILE="$TMP_INDEX" \
|
||
18 years ago
|
git update-index --add --remove --stdin &&
|
||
19 years ago
|
|
||
18 years ago
|
save_index &&
|
||
18 years ago
|
printf '%s\n' "$commit_only" |
|
||
18 years ago
|
(
|
||
|
GIT_INDEX_FILE="$NEXT_INDEX"
|
||
|
export GIT_INDEX_FILE
|
||
18 years ago
|
git update-index --add --remove --stdin
|
||
18 years ago
|
) || exit
|
||
|
;;
|
||
19 years ago
|
esac
|
||
|
;;
|
||
|
esac
|
||
|
|
||
19 years ago
|
################################################################
|
||
|
# If we do as-is commit, the index file will be THIS_INDEX,
|
||
|
# otherwise NEXT_INDEX after we make this commit. We leave
|
||
|
# the index as is if we abort.
|
||
19 years ago
|
|
||
19 years ago
|
if test -f "$NEXT_INDEX"
|
||
19 years ago
|
then
|
||
19 years ago
|
USE_INDEX="$NEXT_INDEX"
|
||
|
else
|
||
|
USE_INDEX="$THIS_INDEX"
|
||
19 years ago
|
fi
|
||
|
|
||
18 years ago
|
case "$status_only" in
|
||
|
t)
|
||
|
# This will silently fail in a read-only repository, which is
|
||
|
# what we want.
|
||
18 years ago
|
GIT_INDEX_FILE="$USE_INDEX" git update-index -q --unmerged --refresh
|
||
19 years ago
|
run_status
|
||
|
exit $?
|
||
18 years ago
|
;;
|
||
|
'')
|
||
18 years ago
|
GIT_INDEX_FILE="$USE_INDEX" git update-index -q --refresh || exit
|
||
18 years ago
|
;;
|
||
19 years ago
|
esac
|
||
|
|
||
|
################################################################
|
||
|
# Grab commit message, write out tree and make commit.
|
||
|
|
||
19 years ago
|
if test t = "$verify" && test -x "$GIT_DIR"/hooks/pre-commit
|
||
|
then
|
||
18 years ago
|
GIT_INDEX_FILE="${TMP_INDEX:-${USE_INDEX}}" "$GIT_DIR"/hooks/pre-commit \
|
||
|
|| exit
|
||
19 years ago
|
fi
|
||
20 years ago
|
|
||
20 years ago
|
if test "$log_message" != ''
|
||
|
then
|
||
18 years ago
|
printf '%s\n' "$log_message"
|
||
20 years ago
|
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
|
||
18 years ago
|
encoding=$(git config i18n.commitencoding || echo UTF-8)
|
||
18 years ago
|
git show -s --pretty=raw --encoding="$encoding" "$use_commit" |
|
||
|
sed -e '1,/^$/d' -e 's/^ //'
|
||
18 years ago
|
elif test -f "$GIT_DIR/MERGE_MSG"
|
||
19 years ago
|
then
|
||
|
cat "$GIT_DIR/MERGE_MSG"
|
||
19 years ago
|
elif test -f "$GIT_DIR/SQUASH_MSG"
|
||
|
then
|
||
|
cat "$GIT_DIR/SQUASH_MSG"
|
||
18 years ago
|
elif test "$templatefile" != ""
|
||
|
then
|
||
|
cat "$templatefile"
|
||
18 years ago
|
fi | git stripspace >"$GIT_DIR"/COMMIT_EDITMSG
|
||
20 years ago
|
|
||
|
case "$signoff" in
|
||
|
t)
|
||
18 years ago
|
sign=$(git-var GIT_COMMITTER_IDENT | sed -e '
|
||
|
s/>.*/>/
|
||
|
s/^/Signed-off-by: /
|
||
|
')
|
||
|
blank_before_signoff=
|
||
18 years ago
|
tail -n 1 "$GIT_DIR"/COMMIT_EDITMSG |
|
||
18 years ago
|
grep 'Signed-off-by:' >/dev/null || blank_before_signoff='
|
||
|
'
|
||
|
tail -n 1 "$GIT_DIR"/COMMIT_EDITMSG |
|
||
|
grep "$sign"$ >/dev/null ||
|
||
|
printf '%s%s\n' "$blank_before_signoff" "$sign" \
|
||
|
>>"$GIT_DIR"/COMMIT_EDITMSG
|
||
20 years ago
|
;;
|
||
|
esac
|
||
|
|
||
19 years ago
|
if test -f "$GIT_DIR/MERGE_HEAD" && test -z "$no_edit"; then
|
||
20 years ago
|
echo "#"
|
||
19 years ago
|
echo "# It looks like you may be committing a MERGE."
|
||
20 years ago
|
echo "# If this is not correct, please remove the file"
|
||
18 years ago
|
printf '%s\n' "# $GIT_DIR/MERGE_HEAD"
|
||
20 years ago
|
echo "# and try again"
|
||
|
echo "#"
|
||
19 years ago
|
fi >>"$GIT_DIR"/COMMIT_EDITMSG
|
||
20 years ago
|
|
||
19 years ago
|
# Author
|
||
18 years ago
|
if test '' != "$use_commit"
|
||
19 years ago
|
then
|
||
18 years ago
|
eval "$(get_author_ident_from_commit "$use_commit")"
|
||
|
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
|
||
19 years ago
|
fi
|
||
18 years ago
|
if test '' != "$force_author"
|
||
|
then
|
||
|
GIT_AUTHOR_NAME=`expr "z$force_author" : 'z\(.*[^ ]\) *<.*'` &&
|
||
|
GIT_AUTHOR_EMAIL=`expr "z$force_author" : '.*\(<.*\)'` &&
|
||
|
test '' != "$GIT_AUTHOR_NAME" &&
|
||
|
test '' != "$GIT_AUTHOR_EMAIL" ||
|
||
|
die "malformed --author parameter"
|
||
|
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
|
||
|
fi
|
||
19 years ago
|
|
||
20 years ago
|
PARENTS="-p HEAD"
|
||
19 years ago
|
if test -z "$initial_commit"
|
||
20 years ago
|
then
|
||
19 years ago
|
rloga='commit'
|
||
20 years ago
|
if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
|
||
19 years ago
|
rloga='commit (merge)'
|
||
20 years ago
|
PARENTS="-p HEAD "`sed -e 's/^/-p /' "$GIT_DIR/MERGE_HEAD"`
|
||
19 years ago
|
elif test -n "$amend"; then
|
||
19 years ago
|
rloga='commit (amend)'
|
||
18 years ago
|
PARENTS=$(git cat-file commit HEAD |
|
||
19 years ago
|
sed -n -e '/^$/q' -e 's/^parent /-p /p')
|
||
20 years ago
|
fi
|
||
18 years ago
|
current="$(git rev-parse --verify HEAD)"
|
||
20 years ago
|
else
|
||
18 years ago
|
if [ -z "$(git ls-files)" ]; then
|
||
18 years ago
|
echo >&2 'nothing to commit (use "git add file1 file2" to include for commit)'
|
||
20 years ago
|
exit 1
|
||
|
fi
|
||
|
PARENTS=""
|
||
19 years ago
|
rloga='commit (initial)'
|
||
19 years ago
|
current=''
|
||
20 years ago
|
fi
|
||
18 years ago
|
set_reflog_action "$rloga"
|
||
19 years ago
|
|
||
19 years ago
|
if test -z "$no_edit"
|
||
|
then
|
||
|
{
|
||
19 years ago
|
echo ""
|
||
|
echo "# Please enter the commit message for your changes."
|
||
|
echo "# (Comment lines starting with '#' will not be included)"
|
||
19 years ago
|
test -z "$only_include_assumed" || echo "$only_include_assumed"
|
||
|
run_status
|
||
|
} >>"$GIT_DIR"/COMMIT_EDITMSG
|
||
|
else
|
||
|
# we need to check if there is anything to commit
|
||
18 years ago
|
run_status >/dev/null
|
||
19 years ago
|
fi
|
||
17 years ago
|
case "$allow_empty,$?,$PARENTS" in
|
||
|
t,* | ?,0,* | ?,*,-p' '?*-p' '?*)
|
||
|
# an explicit --allow-empty, or a merge commit can record the
|
||
|
# same tree as its parent. Otherwise having commitable paths
|
||
|
# is required.
|
||
17 years ago
|
;;
|
||
|
*)
|
||
19 years ago
|
rm -f "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
|
||
18 years ago
|
use_status_color=t
|
||
19 years ago
|
run_status
|
||
20 years ago
|
exit 1
|
||
17 years ago
|
esac
|
||
19 years ago
|
|
||
20 years ago
|
case "$no_edit" in
|
||
20 years ago
|
'')
|
||
19 years ago
|
git-var GIT_AUTHOR_IDENT > /dev/null || die
|
||
|
git-var GIT_COMMITTER_IDENT > /dev/null || die
|
||
18 years ago
|
git_editor "$GIT_DIR/COMMIT_EDITMSG"
|
||
20 years ago
|
;;
|
||
|
esac
|
||
20 years ago
|
|
||
|
case "$verify" in
|
||
|
t)
|
||
|
if test -x "$GIT_DIR"/hooks/commit-msg
|
||
|
then
|
||
19 years ago
|
"$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/COMMIT_EDITMSG || exit
|
||
20 years ago
|
fi
|
||
|
esac
|
||
|
|
||
19 years ago
|
if test -z "$no_edit"
|
||
|
then
|
||
|
sed -e '
|
||
|
/^diff --git a\/.*/{
|
||
|
s///
|
||
|
q
|
||
|
}
|
||
|
/^#/d
|
||
|
' "$GIT_DIR"/COMMIT_EDITMSG
|
||
|
else
|
||
|
cat "$GIT_DIR"/COMMIT_EDITMSG
|
||
|
fi |
|
||
18 years ago
|
git stripspace >"$GIT_DIR"/COMMIT_MSG
|
||
19 years ago
|
|
||
18 years ago
|
# Test whether the commit message has any content we didn't supply.
|
||
|
have_commitmsg=
|
||
|
grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG |
|
||
|
git stripspace > "$GIT_DIR"/COMMIT_BAREMSG
|
||
|
|
||
|
# Is the commit message totally empty?
|
||
|
if test -s "$GIT_DIR"/COMMIT_BAREMSG
|
||
|
then
|
||
|
if test "$templatefile" != ""
|
||
|
then
|
||
|
# Test whether this is just the unaltered template.
|
||
|
if cnt=`sed -e '/^#/d' < "$templatefile" |
|
||
|
git stripspace |
|
||
|
diff "$GIT_DIR"/COMMIT_BAREMSG - |
|
||
|
wc -l` &&
|
||
|
test 0 -lt $cnt
|
||
|
then
|
||
|
have_commitmsg=t
|
||
|
fi
|
||
|
else
|
||
|
# No template, so the content in the commit message must
|
||
|
# have come from the user.
|
||
|
have_commitmsg=t
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
rm -f "$GIT_DIR"/COMMIT_BAREMSG
|
||
|
|
||
|
if test "$have_commitmsg" = "t"
|
||
20 years ago
|
then
|
||
19 years ago
|
if test -z "$TMP_INDEX"
|
||
|
then
|
||
18 years ago
|
tree=$(GIT_INDEX_FILE="$USE_INDEX" git write-tree)
|
||
19 years ago
|
else
|
||
18 years ago
|
tree=$(GIT_INDEX_FILE="$TMP_INDEX" git write-tree) &&
|
||
19 years ago
|
rm -f "$TMP_INDEX"
|
||
|
fi &&
|
||
18 years ago
|
commit=$(git commit-tree $tree $PARENTS <"$GIT_DIR/COMMIT_MSG") &&
|
||
19 years ago
|
rlogm=$(sed -e 1q "$GIT_DIR"/COMMIT_MSG) &&
|
||
18 years ago
|
git update-ref -m "$GIT_REFLOG_ACTION: $rlogm" HEAD $commit "$current" &&
|
||
18 years ago
|
rm -f -- "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/MERGE_MSG" &&
|
||
19 years ago
|
if test -f "$NEXT_INDEX"
|
||
|
then
|
||
|
mv "$NEXT_INDEX" "$THIS_INDEX"
|
||
|
else
|
||
|
: ;# happy
|
||
|
fi
|
||
20 years ago
|
else
|
||
|
echo >&2 "* no commit message? aborting commit."
|
||
|
false
|
||
|
fi
|
||
20 years ago
|
ret="$?"
|
||
19 years ago
|
rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
|
||
18 years ago
|
|
||
|
cd_to_toplevel
|
||
|
|
||
18 years ago
|
git rerere
|
||
20 years ago
|
|
||
18 years ago
|
if test "$ret" = 0
|
||
20 years ago
|
then
|
||
18 years ago
|
git gc --auto
|
||
18 years ago
|
if test -x "$GIT_DIR"/hooks/post-commit
|
||
|
then
|
||
|
"$GIT_DIR"/hooks/post-commit
|
||
|
fi
|
||
|
if test -z "$quiet"
|
||
|
then
|
||
18 years ago
|
commit=`git diff-tree --always --shortstat --pretty="format:%h: %s"\
|
||
18 years ago
|
--summary --root HEAD --`
|
||
18 years ago
|
echo "Created${initial_commit:+ initial} commit $commit"
|
||
|
fi
|
||
20 years ago
|
fi
|
||
18 years ago
|
|
||
20 years ago
|
exit "$ret"
|