2005-05-30 19:51:00 +00:00
|
|
|
#!/bin/sh
|
2005-06-25 09:22:05 +00:00
|
|
|
#
|
|
|
|
# Copyright (c) 2005 Linus Torvalds
|
2006-02-05 08:07:44 +00:00
|
|
|
# Copyright (c) 2006 Junio C Hamano
|
|
|
|
|
2007-07-23 04:17:42 +00:00
|
|
|
USAGE='[-a | --interactive] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit> | --amend] [-u] [-e] [--author <author>] [--template <file>] [[-i | -o] <path>...]'
|
2006-02-05 08:07:44 +00:00
|
|
|
SUBDIRECTORY_OK=Yes
|
2007-11-06 09:50:02 +00:00
|
|
|
OPTIONS_SPEC=
|
2005-11-24 08:12:11 +00:00
|
|
|
. git-sh-setup
|
2006-12-31 04:32:38 +00:00
|
|
|
require_work_tree
|
2005-07-08 17:57:21 +00:00
|
|
|
|
2007-07-03 05:52:14 +00:00
|
|
|
git rev-parse --verify HEAD >/dev/null 2>&1 || initial_commit=t
|
2006-02-10 08:45:59 +00:00
|
|
|
|
|
|
|
case "$0" in
|
|
|
|
*status)
|
|
|
|
status_only=t
|
2007-02-22 08:28:49 +00:00
|
|
|
;;
|
2006-02-10 08:45:59 +00:00
|
|
|
*commit)
|
|
|
|
status_only=
|
2007-02-22 08:28:49 +00:00
|
|
|
;;
|
2006-02-10 08:45:59 +00:00
|
|
|
esac
|
2006-02-05 08:07:44 +00:00
|
|
|
|
|
|
|
refuse_partial () {
|
|
|
|
echo >&2 "$1"
|
|
|
|
echo >&2 "You might have meant to say 'git commit -i paths...', perhaps?"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2007-10-02 18:47:58 +00:00
|
|
|
TMP_INDEX=
|
2007-11-11 12:28:08 +00:00
|
|
|
THIS_INDEX="${GIT_INDEX_FILE:-$GIT_DIR/index}"
|
2006-02-10 08:45:59 +00:00
|
|
|
NEXT_INDEX="$GIT_DIR/next-index$$"
|
|
|
|
rm -f "$NEXT_INDEX"
|
2006-02-06 00:08:01 +00:00
|
|
|
save_index () {
|
2006-06-29 21:48:22 +00:00
|
|
|
cp -p "$THIS_INDEX" "$NEXT_INDEX"
|
2006-02-10 08:45:59 +00:00
|
|
|
}
|
|
|
|
|
2006-02-06 00:08:01 +00:00
|
|
|
run_status () {
|
2006-02-10 08:45:59 +00:00
|
|
|
# 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
|
2006-10-07 19:07:40 +00:00
|
|
|
GIT_INDEX_FILE="$TMP_INDEX"
|
|
|
|
export GIT_INDEX_FILE
|
2006-02-10 08:45:59 +00:00
|
|
|
elif test -f "$NEXT_INDEX"
|
|
|
|
then
|
2006-10-07 19:07:40 +00:00
|
|
|
GIT_INDEX_FILE="$NEXT_INDEX"
|
|
|
|
export GIT_INDEX_FILE
|
2006-02-10 08:45:59 +00:00
|
|
|
fi
|
|
|
|
|
2014-06-06 14:55:46 +00:00
|
|
|
if test "$status_only" = "t" || test "$use_status_color" = "t"; then
|
2007-08-26 18:35:26 +00:00
|
|
|
color=
|
|
|
|
else
|
|
|
|
color=--nocolor
|
|
|
|
fi
|
2007-07-03 05:52:14 +00:00
|
|
|
git runstatus ${color} \
|
2006-10-07 19:07:40 +00:00
|
|
|
${verbose:+--verbose} \
|
|
|
|
${amend:+--amend} \
|
2006-09-12 20:45:12 +00:00
|
|
|
${untracked_files:+--untracked}
|
2006-02-06 00:08:01 +00:00
|
|
|
}
|
|
|
|
|
2006-02-10 08:45:59 +00:00
|
|
|
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
|
|
|
|
|
2006-02-05 08:07:44 +00:00
|
|
|
all=
|
|
|
|
also=
|
2007-12-03 08:03:10 +00:00
|
|
|
allow_empty=f
|
2007-03-05 07:57:53 +00:00
|
|
|
interactive=
|
2006-02-06 00:08:01 +00:00
|
|
|
only=
|
2006-02-05 08:07:44 +00:00
|
|
|
logfile=
|
|
|
|
use_commit=
|
2006-03-03 05:04:05 +00:00
|
|
|
amend=
|
2006-06-23 13:43:38 +00:00
|
|
|
edit_flag=
|
2006-02-05 08:07:44 +00:00
|
|
|
no_edit=
|
|
|
|
log_given=
|
|
|
|
log_message=
|
|
|
|
verify=t
|
2006-12-15 04:15:44 +00:00
|
|
|
quiet=
|
2006-02-10 08:45:59 +00:00
|
|
|
verbose=
|
2006-02-05 08:07:44 +00:00
|
|
|
signoff=
|
|
|
|
force_author=
|
2006-02-14 20:40:20 +00:00
|
|
|
only_include_assumed=
|
2006-05-22 21:02:06 +00:00
|
|
|
untracked_files=
|
2014-04-16 17:29:49 +00:00
|
|
|
templatefile="$(git config commit.template)"
|
2007-09-23 20:42:08 +00:00
|
|
|
while test $# != 0
|
2005-06-25 09:22:05 +00:00
|
|
|
do
|
2006-10-07 19:07:40 +00:00
|
|
|
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
|
2007-09-17 20:56:44 +00:00
|
|
|
logfile="${1#-[Ff]}"
|
2006-10-07 19:07:40 +00:00
|
|
|
;;
|
|
|
|
--F=*|--f=*|--fi=*|--fil=*|--file=*)
|
|
|
|
no_edit=t
|
|
|
|
log_given=t$log_given
|
2007-09-17 20:56:44 +00:00
|
|
|
logfile="${1#*=}"
|
2006-10-07 19:07:40 +00:00
|
|
|
;;
|
|
|
|
-a|--a|--al|--all)
|
|
|
|
all=t
|
|
|
|
;;
|
2007-12-03 08:03:10 +00:00
|
|
|
--allo|--allow|--allow-|--allow-e|--allow-em|--allow-emp|\
|
|
|
|
--allow-empt|--allow-empty)
|
|
|
|
allow_empty=t
|
|
|
|
;;
|
2006-10-07 19:07:40 +00:00
|
|
|
--au=*|--aut=*|--auth=*|--autho=*|--author=*)
|
2007-09-17 20:56:44 +00:00
|
|
|
force_author="${1#*=}"
|
2006-10-07 19:07:40 +00:00
|
|
|
;;
|
|
|
|
--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
|
|
|
|
;;
|
2007-03-05 07:57:53 +00:00
|
|
|
--int|--inte|--inter|--intera|--interac|--interact|--interacti|\
|
|
|
|
--interactiv|--interactive)
|
|
|
|
interactive=t
|
|
|
|
;;
|
2006-10-07 19:07:40 +00:00
|
|
|
-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
|
2007-09-17 20:56:44 +00:00
|
|
|
log_message="${log_message:+${log_message}
|
2006-05-29 08:45:49 +00:00
|
|
|
|
2007-09-17 20:56:44 +00:00
|
|
|
}$1"
|
2006-10-07 19:07:40 +00:00
|
|
|
no_edit=t
|
|
|
|
;;
|
|
|
|
-m*)
|
|
|
|
log_given=m$log_given
|
2007-09-17 20:56:44 +00:00
|
|
|
log_message="${log_message:+${log_message}
|
2006-05-29 08:45:49 +00:00
|
|
|
|
2007-09-17 20:56:44 +00:00
|
|
|
}${1#-m}"
|
2006-10-07 19:07:40 +00:00
|
|
|
no_edit=t
|
|
|
|
;;
|
|
|
|
--m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*)
|
|
|
|
log_given=m$log_given
|
2007-09-17 20:56:44 +00:00
|
|
|
log_message="${log_message:+${log_message}
|
2006-05-29 08:45:49 +00:00
|
|
|
|
2007-09-17 20:56:44 +00:00
|
|
|
}${1#*=}"
|
2006-10-07 19:07:40 +00:00
|
|
|
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
|
2007-09-17 20:56:44 +00:00
|
|
|
use_commit="${1#*=}"
|
2006-10-07 19:07:40 +00:00
|
|
|
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
|
2007-09-17 20:56:44 +00:00
|
|
|
use_commit="${1#*=}"
|
2006-10-07 19:07:40 +00:00
|
|
|
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
|
|
|
|
;;
|
2007-07-23 04:17:42 +00:00
|
|
|
-t|--t|--te|--tem|--temp|--templ|--templa|--templat|--template)
|
|
|
|
case "$#" in 1) usage ;; esac
|
|
|
|
shift
|
|
|
|
templatefile="$1"
|
|
|
|
no_edit=
|
|
|
|
;;
|
2006-12-15 04:15:44 +00:00
|
|
|
-q|--q|--qu|--qui|--quie|--quiet)
|
|
|
|
quiet=t
|
|
|
|
;;
|
2006-10-07 19:07:40 +00:00
|
|
|
-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
|
2007-09-17 20:56:44 +00:00
|
|
|
shift
|
2005-06-25 09:22:05 +00:00
|
|
|
done
|
2006-06-23 13:43:38 +00:00
|
|
|
case "$edit_flag" in t) no_edit= ;; esac
|
2005-06-25 09:22:05 +00:00
|
|
|
|
2006-02-10 08:45:59 +00:00
|
|
|
################################################################
|
|
|
|
# Sanity check options
|
|
|
|
|
2006-03-03 05:04:05 +00:00
|
|
|
case "$amend,$initial_commit" in
|
|
|
|
t,t)
|
2006-10-07 19:07:40 +00:00
|
|
|
die "You do not have anything to amend." ;;
|
2006-03-03 05:04:05 +00:00
|
|
|
t,)
|
2006-10-07 19:07:40 +00:00
|
|
|
if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
|
|
|
|
die "You are in the middle of a merge -- cannot amend."
|
|
|
|
fi ;;
|
2006-03-03 05:04:05 +00:00
|
|
|
esac
|
|
|
|
|
2005-08-09 00:03:14 +00:00
|
|
|
case "$log_given" in
|
|
|
|
tt*)
|
2007-08-02 01:14:41 +00:00
|
|
|
die "Only one of -c/-C/-F can be used." ;;
|
2006-05-29 08:45:49 +00:00
|
|
|
*tm*|*mt*)
|
2007-08-02 01:14:41 +00:00
|
|
|
die "Option -m cannot be combined with -c/-C/-F." ;;
|
2005-08-09 00:03:14 +00:00
|
|
|
esac
|
|
|
|
|
2006-04-20 08:20:56 +00:00
|
|
|
case "$#,$also,$only,$amend" in
|
|
|
|
*,t,t,*)
|
2006-10-07 19:07:40 +00:00
|
|
|
die "Only one of --include/--only can be used." ;;
|
2006-04-20 08:20:56 +00:00
|
|
|
0,t,,* | 0,,t,)
|
2006-10-07 19:07:40 +00:00
|
|
|
die "No paths with --include/--only does not make sense." ;;
|
2006-04-20 08:20:56 +00:00
|
|
|
0,,t,t)
|
2006-10-07 19:07:40 +00:00
|
|
|
only_include_assumed="# Clever... amending the last one with dirty index." ;;
|
2006-04-20 08:20:56 +00:00
|
|
|
0,,,*)
|
2006-10-07 19:07:40 +00:00
|
|
|
;;
|
2006-04-20 08:20:56 +00:00
|
|
|
*,,,*)
|
2014-03-31 22:11:45 +00:00
|
|
|
only_include_assumed="# Explicit paths specified without -i or -o; assuming --only paths..."
|
2006-10-07 19:07:40 +00:00
|
|
|
also=
|
|
|
|
;;
|
2006-02-06 00:08:01 +00:00
|
|
|
esac
|
|
|
|
unset only
|
2007-03-05 07:57:53 +00:00
|
|
|
case "$all,$interactive,$also,$#" in
|
|
|
|
*t,*t,*)
|
|
|
|
die "Cannot use -a, --interactive or -i at the same time." ;;
|
2007-11-05 19:36:33 +00:00
|
|
|
t,,,[1-9]*)
|
2006-02-10 08:45:59 +00:00
|
|
|
die "Paths with -a does not make sense." ;;
|
2007-11-05 19:36:33 +00:00
|
|
|
,t,,[1-9]*)
|
2007-03-05 07:57:53 +00:00
|
|
|
die "Paths with --interactive does not make sense." ;;
|
|
|
|
,,t,0)
|
2006-02-10 08:45:59 +00:00
|
|
|
die "No paths with -i does not make sense." ;;
|
|
|
|
esac
|
|
|
|
|
2014-06-06 14:55:46 +00:00
|
|
|
if test ! -z "$templatefile" && test -z "$log_given"
|
2007-07-23 04:17:42 +00:00
|
|
|
then
|
|
|
|
if test ! -f "$templatefile"
|
|
|
|
then
|
|
|
|
die "Commit template file does not exist."
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2006-02-10 08:45:59 +00:00
|
|
|
################################################################
|
|
|
|
# Prepare index to have a tree to be committed
|
2006-02-06 00:08:01 +00:00
|
|
|
|
2006-02-05 08:07:44 +00:00
|
|
|
case "$all,$also" in
|
|
|
|
t,)
|
2007-02-22 20:28:12 +00:00
|
|
|
if test ! -f "$THIS_INDEX"
|
|
|
|
then
|
|
|
|
die 'nothing to commit (use "git add file1 file2" to include for commit)'
|
|
|
|
fi
|
2006-02-06 00:08:01 +00:00
|
|
|
save_index &&
|
2006-02-05 08:07:44 +00:00
|
|
|
(
|
2007-01-12 20:49:05 +00:00
|
|
|
cd_to_toplevel &&
|
|
|
|
GIT_INDEX_FILE="$NEXT_INDEX" &&
|
|
|
|
export GIT_INDEX_FILE &&
|
2007-07-03 05:52:14 +00:00
|
|
|
git diff-files --name-only -z |
|
|
|
|
git update-index --remove -z --stdin
|
2007-01-12 20:49:05 +00:00
|
|
|
) || exit
|
2005-08-17 22:17:03 +00:00
|
|
|
;;
|
2006-02-05 08:07:44 +00:00
|
|
|
,t)
|
2006-02-06 00:08:01 +00:00
|
|
|
save_index &&
|
2007-07-03 05:52:14 +00:00
|
|
|
git ls-files --error-unmatch -- "$@" >/dev/null || exit
|
2006-02-14 20:40:20 +00:00
|
|
|
|
2007-07-03 05:52:14 +00:00
|
|
|
git diff-files --name-only -z -- "$@" |
|
2006-02-10 08:45:59 +00:00
|
|
|
(
|
2007-01-12 20:49:05 +00:00
|
|
|
cd_to_toplevel &&
|
|
|
|
GIT_INDEX_FILE="$NEXT_INDEX" &&
|
|
|
|
export GIT_INDEX_FILE &&
|
2007-07-03 05:52:14 +00:00
|
|
|
git update-index --remove -z --stdin
|
2007-01-12 20:49:05 +00:00
|
|
|
) || exit
|
2005-08-17 01:08:19 +00:00
|
|
|
;;
|
2006-02-05 08:07:44 +00:00
|
|
|
,)
|
2007-03-05 07:57:53 +00:00
|
|
|
if test "$interactive" = t; then
|
|
|
|
git add --interactive || exit
|
|
|
|
fi
|
2006-02-05 08:07:44 +00:00
|
|
|
case "$#" in
|
|
|
|
0)
|
2006-10-07 19:07:40 +00:00
|
|
|
;; # commit as-is
|
2006-02-05 08:07:44 +00:00
|
|
|
*)
|
2006-10-07 19:07:40 +00:00
|
|
|
if test -f "$GIT_DIR/MERGE_HEAD"
|
|
|
|
then
|
|
|
|
refuse_partial "Cannot do a partial commit during a merge."
|
|
|
|
fi
|
2007-09-12 23:04:22 +00:00
|
|
|
|
2006-10-07 19:07:40 +00:00
|
|
|
TMP_INDEX="$GIT_DIR/tmp-index$$"
|
2007-09-12 23:04:22 +00:00
|
|
|
W=
|
|
|
|
test -z "$initial_commit" && W=--with-tree=HEAD
|
2014-04-16 17:29:49 +00:00
|
|
|
commit_only=$(git ls-files --error-unmatch $W -- "$@") || exit
|
2006-02-10 08:45:59 +00:00
|
|
|
|
2006-12-10 06:32:43 +00:00
|
|
|
# Build a temporary index and update the real index
|
2006-10-07 19:07:40 +00:00
|
|
|
# the same way.
|
|
|
|
if test -z "$initial_commit"
|
|
|
|
then
|
2007-04-01 06:27:41 +00:00
|
|
|
GIT_INDEX_FILE="$THIS_INDEX" \
|
2007-07-03 05:52:14 +00:00
|
|
|
git read-tree --index-output="$TMP_INDEX" -i -m HEAD
|
2006-10-07 19:07:40 +00:00
|
|
|
else
|
|
|
|
rm -f "$TMP_INDEX"
|
|
|
|
fi || exit
|
2006-02-10 08:45:59 +00:00
|
|
|
|
2007-05-26 05:00:54 +00:00
|
|
|
printf '%s\n' "$commit_only" |
|
2006-10-07 19:07:40 +00:00
|
|
|
GIT_INDEX_FILE="$TMP_INDEX" \
|
2007-07-03 05:52:14 +00:00
|
|
|
git update-index --add --remove --stdin &&
|
2006-02-10 08:45:59 +00:00
|
|
|
|
2006-10-07 19:07:40 +00:00
|
|
|
save_index &&
|
2007-05-26 05:00:54 +00:00
|
|
|
printf '%s\n' "$commit_only" |
|
2006-10-07 19:07:40 +00:00
|
|
|
(
|
|
|
|
GIT_INDEX_FILE="$NEXT_INDEX"
|
|
|
|
export GIT_INDEX_FILE
|
2007-09-14 23:53:58 +00:00
|
|
|
git update-index --add --remove --stdin
|
2006-10-07 19:07:40 +00:00
|
|
|
) || exit
|
|
|
|
;;
|
2006-02-05 08:07:44 +00:00
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2006-02-10 08:45:59 +00:00
|
|
|
################################################################
|
|
|
|
# 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.
|
2006-02-05 08:07:44 +00:00
|
|
|
|
2006-02-10 08:45:59 +00:00
|
|
|
if test -f "$NEXT_INDEX"
|
2006-02-05 08:07:44 +00:00
|
|
|
then
|
2006-02-10 08:45:59 +00:00
|
|
|
USE_INDEX="$NEXT_INDEX"
|
|
|
|
else
|
|
|
|
USE_INDEX="$THIS_INDEX"
|
2006-02-05 08:07:44 +00:00
|
|
|
fi
|
|
|
|
|
2007-02-22 08:28:49 +00:00
|
|
|
case "$status_only" in
|
|
|
|
t)
|
|
|
|
# This will silently fail in a read-only repository, which is
|
|
|
|
# what we want.
|
2007-07-03 05:52:14 +00:00
|
|
|
GIT_INDEX_FILE="$USE_INDEX" git update-index -q --unmerged --refresh
|
2006-02-10 08:45:59 +00:00
|
|
|
run_status
|
|
|
|
exit $?
|
2007-02-22 08:28:49 +00:00
|
|
|
;;
|
|
|
|
'')
|
2007-07-03 05:52:14 +00:00
|
|
|
GIT_INDEX_FILE="$USE_INDEX" git update-index -q --refresh || exit
|
2007-02-22 08:28:49 +00:00
|
|
|
;;
|
2006-02-10 08:45:59 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
################################################################
|
|
|
|
# Grab commit message, write out tree and make commit.
|
|
|
|
|
2006-02-05 08:07:44 +00:00
|
|
|
if test t = "$verify" && test -x "$GIT_DIR"/hooks/pre-commit
|
|
|
|
then
|
2007-09-17 20:56:44 +00:00
|
|
|
GIT_INDEX_FILE="${TMP_INDEX:-${USE_INDEX}}" "$GIT_DIR"/hooks/pre-commit \
|
|
|
|
|| exit
|
2006-02-05 08:07:44 +00:00
|
|
|
fi
|
2005-08-13 06:39:15 +00:00
|
|
|
|
2005-08-26 01:57:35 +00:00
|
|
|
if test "$log_message" != ''
|
|
|
|
then
|
2007-05-26 05:00:54 +00:00
|
|
|
printf '%s\n' "$log_message"
|
2005-08-26 01:57:35 +00:00
|
|
|
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
|
2007-01-29 00:16:53 +00:00
|
|
|
encoding=$(git config i18n.commitencoding || echo UTF-8)
|
2007-01-13 21:33:07 +00:00
|
|
|
git show -s --pretty=raw --encoding="$encoding" "$use_commit" |
|
|
|
|
sed -e '1,/^$/d' -e 's/^ //'
|
2006-10-12 21:52:42 +00:00
|
|
|
elif test -f "$GIT_DIR/MERGE_MSG"
|
2005-11-02 06:01:28 +00:00
|
|
|
then
|
|
|
|
cat "$GIT_DIR/MERGE_MSG"
|
git-merge --squash
Some people tend to do many little commits on a topic branch,
recording all the trials and errors, and when the topic is
reasonably cooked well, would want to record the net effect of
the series as one commit on top of the mainline, removing the
cruft from the history. The topic is then abandoned or forked
off again from that point at the mainline.
The barebone porcelainish that comes with core git tools does
not officially support such operation, but you can fake it by
using "git pull --no-merge" when such a topic branch is not a
strict superset of the mainline, like this:
git checkout mainline
git pull --no-commit . that-topic-branch
: fix conflicts if any
rm -f .git/MERGE_HEAD
git commit -a -m 'consolidated commit log message'
git branch -f that-topic-branch ;# now fully merged
This however does not work when the topic branch is a fast
forward of the mainline, because normal "git pull" will never
create a merge commit in such a case, and there is nothing
special --no-commit could do to begin with.
This patch introduces a new option, --squash, to support such a
workflow officially in both fast-forward case and true merge
case. The user-level operation would be the same in both cases:
git checkout mainline
git pull --squash . that-topic-branch
: fix conflicts if any -- naturally, there would be
: no conflict if fast forward.
git commit -a -m 'consolidated commit log message'
git branch -f that-topic-branch ;# now fully merged
When the current branch is already up-to-date with respect to
the other branch, there truly is nothing to do, so the new
option does not have any effect.
This was brought up in #git IRC channel recently.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-06-23 08:37:02 +00:00
|
|
|
elif test -f "$GIT_DIR/SQUASH_MSG"
|
|
|
|
then
|
|
|
|
cat "$GIT_DIR/SQUASH_MSG"
|
2007-07-23 04:17:42 +00:00
|
|
|
elif test "$templatefile" != ""
|
|
|
|
then
|
|
|
|
cat "$templatefile"
|
2007-07-03 05:52:14 +00:00
|
|
|
fi | git stripspace >"$GIT_DIR"/COMMIT_EDITMSG
|
2005-09-01 00:15:25 +00:00
|
|
|
|
|
|
|
case "$signoff" in
|
|
|
|
t)
|
2008-07-30 17:48:33 +00:00
|
|
|
sign=$(git var GIT_COMMITTER_IDENT | sed -e '
|
2007-07-06 14:42:27 +00:00
|
|
|
s/>.*/>/
|
|
|
|
s/^/Signed-off-by: /
|
|
|
|
')
|
|
|
|
blank_before_signoff=
|
2007-01-29 09:06:27 +00:00
|
|
|
tail -n 1 "$GIT_DIR"/COMMIT_EDITMSG |
|
2007-07-06 14:42:27 +00:00
|
|
|
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
|
2005-09-01 00:15:25 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2006-04-12 18:45:18 +00:00
|
|
|
if test -f "$GIT_DIR/MERGE_HEAD" && test -z "$no_edit"; then
|
2005-09-01 00:15:25 +00:00
|
|
|
echo "#"
|
2006-01-05 11:44:59 +00:00
|
|
|
echo "# It looks like you may be committing a MERGE."
|
2005-09-01 00:15:25 +00:00
|
|
|
echo "# If this is not correct, please remove the file"
|
2007-05-26 05:00:54 +00:00
|
|
|
printf '%s\n' "# $GIT_DIR/MERGE_HEAD"
|
2005-09-01 00:15:25 +00:00
|
|
|
echo "# and try again"
|
|
|
|
echo "#"
|
2005-10-10 00:30:19 +00:00
|
|
|
fi >>"$GIT_DIR"/COMMIT_EDITMSG
|
2005-08-26 01:57:35 +00:00
|
|
|
|
2006-02-05 08:07:44 +00:00
|
|
|
# Author
|
2007-01-22 21:03:31 +00:00
|
|
|
if test '' != "$use_commit"
|
2006-02-05 08:07:44 +00:00
|
|
|
then
|
2007-06-25 00:04:11 +00:00
|
|
|
eval "$(get_author_ident_from_commit "$use_commit")"
|
|
|
|
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
|
2006-02-05 08:07:44 +00:00
|
|
|
fi
|
2007-01-22 21:03:31 +00:00
|
|
|
if test '' != "$force_author"
|
|
|
|
then
|
2014-04-16 17:29:49 +00:00
|
|
|
GIT_AUTHOR_NAME=$(expr "z$force_author" : 'z\(.*[^ ]\) *<.*') &&
|
|
|
|
GIT_AUTHOR_EMAIL=$(expr "z$force_author" : '.*\(<.*\)') &&
|
2007-01-22 21:03:31 +00:00
|
|
|
test '' != "$GIT_AUTHOR_NAME" &&
|
|
|
|
test '' != "$GIT_AUTHOR_EMAIL" ||
|
|
|
|
die "malformed --author parameter"
|
|
|
|
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
|
|
|
|
fi
|
2006-02-05 08:07:44 +00:00
|
|
|
|
2005-06-14 17:20:14 +00:00
|
|
|
PARENTS="-p HEAD"
|
2006-02-05 08:07:44 +00:00
|
|
|
if test -z "$initial_commit"
|
2005-09-30 21:26:57 +00:00
|
|
|
then
|
2006-07-11 02:48:47 +00:00
|
|
|
rloga='commit'
|
2005-06-25 09:22:05 +00:00
|
|
|
if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
|
2006-07-11 02:48:47 +00:00
|
|
|
rloga='commit (merge)'
|
2014-04-16 17:29:49 +00:00
|
|
|
PARENTS="-p HEAD "$(sed -e 's/^/-p /' "$GIT_DIR/MERGE_HEAD")
|
2006-03-03 05:04:05 +00:00
|
|
|
elif test -n "$amend"; then
|
2006-07-11 02:48:47 +00:00
|
|
|
rloga='commit (amend)'
|
2007-07-03 05:52:14 +00:00
|
|
|
PARENTS=$(git cat-file commit HEAD |
|
2006-03-03 05:04:05 +00:00
|
|
|
sed -n -e '/^$/q' -e 's/^parent /-p /p')
|
2005-08-26 01:57:35 +00:00
|
|
|
fi
|
2007-07-03 05:52:14 +00:00
|
|
|
current="$(git rev-parse --verify HEAD)"
|
2005-09-30 21:26:57 +00:00
|
|
|
else
|
2007-07-03 05:52:14 +00:00
|
|
|
if [ -z "$(git ls-files)" ]; then
|
2006-12-16 02:53:09 +00:00
|
|
|
echo >&2 'nothing to commit (use "git add file1 file2" to include for commit)'
|
2005-09-30 21:26:57 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
PARENTS=""
|
2006-07-11 02:48:47 +00:00
|
|
|
rloga='commit (initial)'
|
2006-09-27 09:06:31 +00:00
|
|
|
current=''
|
2005-06-14 17:20:14 +00:00
|
|
|
fi
|
2007-01-20 01:12:11 +00:00
|
|
|
set_reflog_action "$rloga"
|
2006-02-05 08:07:44 +00:00
|
|
|
|
2006-04-12 18:45:18 +00:00
|
|
|
if test -z "$no_edit"
|
|
|
|
then
|
|
|
|
{
|
2006-05-25 23:42:18 +00:00
|
|
|
echo ""
|
|
|
|
echo "# Please enter the commit message for your changes."
|
|
|
|
echo "# (Comment lines starting with '#' will not be included)"
|
2006-04-12 18:45:18 +00:00
|
|
|
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
|
2007-06-07 07:04:01 +00:00
|
|
|
run_status >/dev/null
|
2006-04-12 18:45:18 +00:00
|
|
|
fi
|
2007-12-03 08:03:10 +00:00
|
|
|
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.
|
2007-12-03 07:24:50 +00:00
|
|
|
;;
|
|
|
|
*)
|
git-merge --squash
Some people tend to do many little commits on a topic branch,
recording all the trials and errors, and when the topic is
reasonably cooked well, would want to record the net effect of
the series as one commit on top of the mainline, removing the
cruft from the history. The topic is then abandoned or forked
off again from that point at the mainline.
The barebone porcelainish that comes with core git tools does
not officially support such operation, but you can fake it by
using "git pull --no-merge" when such a topic branch is not a
strict superset of the mainline, like this:
git checkout mainline
git pull --no-commit . that-topic-branch
: fix conflicts if any
rm -f .git/MERGE_HEAD
git commit -a -m 'consolidated commit log message'
git branch -f that-topic-branch ;# now fully merged
This however does not work when the topic branch is a fast
forward of the mainline, because normal "git pull" will never
create a merge commit in such a case, and there is nothing
special --no-commit could do to begin with.
This patch introduces a new option, --squash, to support such a
workflow officially in both fast-forward case and true merge
case. The user-level operation would be the same in both cases:
git checkout mainline
git pull --squash . that-topic-branch
: fix conflicts if any -- naturally, there would be
: no conflict if fast forward.
git commit -a -m 'consolidated commit log message'
git branch -f that-topic-branch ;# now fully merged
When the current branch is already up-to-date with respect to
the other branch, there truly is nothing to do, so the new
option does not have any effect.
This was brought up in #git IRC channel recently.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-06-23 08:37:02 +00:00
|
|
|
rm -f "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
|
2007-08-26 18:35:26 +00:00
|
|
|
use_status_color=t
|
2006-02-06 00:08:01 +00:00
|
|
|
run_status
|
2005-05-30 19:51:00 +00:00
|
|
|
exit 1
|
2007-12-03 07:24:50 +00:00
|
|
|
esac
|
2006-04-12 18:45:18 +00:00
|
|
|
|
2005-08-09 00:03:14 +00:00
|
|
|
case "$no_edit" in
|
2005-06-25 09:22:05 +00:00
|
|
|
'')
|
2008-07-30 17:48:33 +00:00
|
|
|
git var GIT_AUTHOR_IDENT > /dev/null || die
|
|
|
|
git var GIT_COMMITTER_IDENT > /dev/null || die
|
2007-07-20 05:09:35 +00:00
|
|
|
git_editor "$GIT_DIR/COMMIT_EDITMSG"
|
2005-06-25 09:22:05 +00:00
|
|
|
;;
|
|
|
|
esac
|
2005-08-19 00:20:08 +00:00
|
|
|
|
|
|
|
case "$verify" in
|
|
|
|
t)
|
|
|
|
if test -x "$GIT_DIR"/hooks/commit-msg
|
|
|
|
then
|
2005-10-10 00:30:19 +00:00
|
|
|
"$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/COMMIT_EDITMSG || exit
|
2005-08-19 00:20:08 +00:00
|
|
|
fi
|
|
|
|
esac
|
|
|
|
|
2006-06-23 22:04:05 +00:00
|
|
|
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 |
|
2007-07-03 05:52:14 +00:00
|
|
|
git stripspace >"$GIT_DIR"/COMMIT_MSG
|
2005-10-10 00:30:19 +00:00
|
|
|
|
2007-07-23 04:17:42 +00:00
|
|
|
# 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.
|
2015-12-22 14:10:23 +00:00
|
|
|
if cnt=$(sed -e '/^#/d' < "$templatefile" |
|
2007-07-23 04:17:42 +00:00
|
|
|
git stripspace |
|
|
|
|
diff "$GIT_DIR"/COMMIT_BAREMSG - |
|
2015-12-22 14:10:23 +00:00
|
|
|
wc -l) &&
|
2007-07-23 04:17:42 +00:00
|
|
|
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"
|
2005-08-09 00:03:14 +00:00
|
|
|
then
|
2006-02-05 08:07:44 +00:00
|
|
|
if test -z "$TMP_INDEX"
|
|
|
|
then
|
2007-07-03 05:52:14 +00:00
|
|
|
tree=$(GIT_INDEX_FILE="$USE_INDEX" git write-tree)
|
2006-02-05 08:07:44 +00:00
|
|
|
else
|
2007-07-03 05:52:14 +00:00
|
|
|
tree=$(GIT_INDEX_FILE="$TMP_INDEX" git write-tree) &&
|
2006-02-05 08:07:44 +00:00
|
|
|
rm -f "$TMP_INDEX"
|
|
|
|
fi &&
|
2007-07-14 08:05:43 +00:00
|
|
|
commit=$(git commit-tree $tree $PARENTS <"$GIT_DIR/COMMIT_MSG") &&
|
2006-05-19 09:16:18 +00:00
|
|
|
rlogm=$(sed -e 1q "$GIT_DIR"/COMMIT_MSG) &&
|
2007-07-03 05:52:14 +00:00
|
|
|
git update-ref -m "$GIT_REFLOG_ACTION: $rlogm" HEAD $commit "$current" &&
|
2006-10-12 21:52:42 +00:00
|
|
|
rm -f -- "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/MERGE_MSG" &&
|
2006-02-10 08:45:59 +00:00
|
|
|
if test -f "$NEXT_INDEX"
|
|
|
|
then
|
|
|
|
mv "$NEXT_INDEX" "$THIS_INDEX"
|
|
|
|
else
|
|
|
|
: ;# happy
|
|
|
|
fi
|
2005-08-09 00:03:14 +00:00
|
|
|
else
|
|
|
|
echo >&2 "* no commit message? aborting commit."
|
|
|
|
false
|
|
|
|
fi
|
2005-06-20 02:57:01 +00:00
|
|
|
ret="$?"
|
git-merge --squash
Some people tend to do many little commits on a topic branch,
recording all the trials and errors, and when the topic is
reasonably cooked well, would want to record the net effect of
the series as one commit on top of the mainline, removing the
cruft from the history. The topic is then abandoned or forked
off again from that point at the mainline.
The barebone porcelainish that comes with core git tools does
not officially support such operation, but you can fake it by
using "git pull --no-merge" when such a topic branch is not a
strict superset of the mainline, like this:
git checkout mainline
git pull --no-commit . that-topic-branch
: fix conflicts if any
rm -f .git/MERGE_HEAD
git commit -a -m 'consolidated commit log message'
git branch -f that-topic-branch ;# now fully merged
This however does not work when the topic branch is a fast
forward of the mainline, because normal "git pull" will never
create a merge commit in such a case, and there is nothing
special --no-commit could do to begin with.
This patch introduces a new option, --squash, to support such a
workflow officially in both fast-forward case and true merge
case. The user-level operation would be the same in both cases:
git checkout mainline
git pull --squash . that-topic-branch
: fix conflicts if any -- naturally, there would be
: no conflict if fast forward.
git commit -a -m 'consolidated commit log message'
git branch -f that-topic-branch ;# now fully merged
When the current branch is already up-to-date with respect to
the other branch, there truly is nothing to do, so the new
option does not have any effect.
This was brought up in #git IRC channel recently.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-06-23 08:37:02 +00:00
|
|
|
rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
|
2007-03-05 20:35:41 +00:00
|
|
|
|
|
|
|
cd_to_toplevel
|
|
|
|
|
2007-07-06 12:05:59 +00:00
|
|
|
git rerere
|
2005-08-19 00:20:08 +00:00
|
|
|
|
2006-12-15 04:15:44 +00:00
|
|
|
if test "$ret" = 0
|
2005-08-19 00:20:08 +00:00
|
|
|
then
|
2007-09-05 21:59:59 +00:00
|
|
|
git gc --auto
|
2006-12-15 04:15:44 +00:00
|
|
|
if test -x "$GIT_DIR"/hooks/post-commit
|
|
|
|
then
|
|
|
|
"$GIT_DIR"/hooks/post-commit
|
|
|
|
fi
|
|
|
|
if test -z "$quiet"
|
|
|
|
then
|
2015-12-22 14:10:23 +00:00
|
|
|
commit=$(git diff-tree --always --shortstat --pretty="format:%h: %s"\
|
|
|
|
--abbrev --summary --root HEAD --)
|
2006-12-15 04:15:44 +00:00
|
|
|
echo "Created${initial_commit:+ initial} commit $commit"
|
|
|
|
fi
|
2005-08-19 00:20:08 +00:00
|
|
|
fi
|
2006-10-25 04:48:55 +00:00
|
|
|
|
2005-06-20 02:57:01 +00:00
|
|
|
exit "$ret"
|