2005-05-30 21:51:00 +02:00
|
|
|
#!/bin/sh
|
2005-06-25 11:22:05 +02:00
|
|
|
#
|
|
|
|
# Copyright (c) 2005 Linus Torvalds
|
2006-02-05 09:07:44 +01:00
|
|
|
# Copyright (c) 2006 Junio C Hamano
|
|
|
|
|
2006-05-22 23:02:06 +02:00
|
|
|
USAGE='[-a] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit>] [-u] [--amend] [-e] [--author <author>] [[-i | -o] <path>...]'
|
2006-02-05 09:07:44 +01:00
|
|
|
SUBDIRECTORY_OK=Yes
|
2005-11-24 09:12:11 +01:00
|
|
|
. git-sh-setup
|
2005-07-08 19:57:21 +02:00
|
|
|
|
2006-02-10 09:45:59 +01:00
|
|
|
git-rev-parse --verify HEAD >/dev/null 2>&1 || initial_commit=t
|
|
|
|
|
|
|
|
case "$0" in
|
|
|
|
*status)
|
|
|
|
status_only=t
|
|
|
|
unmerged_ok_if_status=--unmerged ;;
|
|
|
|
*commit)
|
|
|
|
status_only=
|
|
|
|
unmerged_ok_if_status= ;;
|
|
|
|
esac
|
2006-02-05 09:07:44 +01:00
|
|
|
|
|
|
|
refuse_partial () {
|
|
|
|
echo >&2 "$1"
|
|
|
|
echo >&2 "You might have meant to say 'git commit -i paths...', perhaps?"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2006-02-10 09:45:59 +01:00
|
|
|
THIS_INDEX="$GIT_DIR/index"
|
|
|
|
NEXT_INDEX="$GIT_DIR/next-index$$"
|
|
|
|
rm -f "$NEXT_INDEX"
|
2006-02-06 01:08:01 +01:00
|
|
|
save_index () {
|
2006-06-29 23:48:22 +02:00
|
|
|
cp -p "$THIS_INDEX" "$NEXT_INDEX"
|
2006-02-10 09:45:59 +01:00
|
|
|
}
|
|
|
|
|
2006-02-06 01:08:01 +01:00
|
|
|
run_status () {
|
2006-02-10 09:45:59 +01: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 21:07:40 +02:00
|
|
|
GIT_INDEX_FILE="$TMP_INDEX"
|
|
|
|
export GIT_INDEX_FILE
|
2006-02-10 09:45:59 +01:00
|
|
|
elif test -f "$NEXT_INDEX"
|
|
|
|
then
|
2006-10-07 21:07:40 +02:00
|
|
|
GIT_INDEX_FILE="$NEXT_INDEX"
|
|
|
|
export GIT_INDEX_FILE
|
2006-02-10 09:45:59 +01:00
|
|
|
fi
|
|
|
|
|
2006-10-07 21:07:40 +02:00
|
|
|
case "$status_only" in
|
|
|
|
t) color= ;;
|
|
|
|
*) color=--nocolor ;;
|
|
|
|
esac
|
|
|
|
git-runstatus ${color} \
|
|
|
|
${verbose:+--verbose} \
|
|
|
|
${amend:+--amend} \
|
2006-09-12 22:45:12 +02:00
|
|
|
${untracked_files:+--untracked}
|
2006-02-06 01:08:01 +01:00
|
|
|
}
|
|
|
|
|
2006-02-10 09:45:59 +01: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 09:07:44 +01:00
|
|
|
all=
|
|
|
|
also=
|
2006-02-06 01:08:01 +01:00
|
|
|
only=
|
2006-02-05 09:07:44 +01:00
|
|
|
logfile=
|
|
|
|
use_commit=
|
2006-03-03 06:04:05 +01:00
|
|
|
amend=
|
2006-06-23 15:43:38 +02:00
|
|
|
edit_flag=
|
2006-02-05 09:07:44 +01:00
|
|
|
no_edit=
|
|
|
|
log_given=
|
|
|
|
log_message=
|
|
|
|
verify=t
|
2006-12-15 05:15:44 +01:00
|
|
|
quiet=
|
2006-02-10 09:45:59 +01:00
|
|
|
verbose=
|
2006-02-05 09:07:44 +01:00
|
|
|
signoff=
|
|
|
|
force_author=
|
2006-02-14 21:40:20 +01:00
|
|
|
only_include_assumed=
|
2006-05-22 23:02:06 +02:00
|
|
|
untracked_files=
|
2005-08-09 02:03:14 +02:00
|
|
|
while case "$#" in 0) break;; esac
|
2005-06-25 11:22:05 +02:00
|
|
|
do
|
2006-10-07 21:07:40 +02: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"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-F*|-f*)
|
|
|
|
no_edit=t
|
|
|
|
log_given=t$log_given
|
|
|
|
logfile=`expr "z$1" : 'z-[Ff]\(.*\)'`
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--F=*|--f=*|--fi=*|--fil=*|--file=*)
|
|
|
|
no_edit=t
|
|
|
|
log_given=t$log_given
|
|
|
|
logfile=`expr "z$1" : 'z-[^=]*=\(.*\)'`
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-a|--a|--al|--all)
|
|
|
|
all=t
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--au=*|--aut=*|--auth=*|--autho=*|--author=*)
|
|
|
|
force_author=`expr "z$1" : 'z-[^=]*=\(.*\)'`
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--au|--aut|--auth|--autho|--author)
|
|
|
|
case "$#" in 1) usage ;; esac
|
|
|
|
shift
|
|
|
|
force_author="$1"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-e|--e|--ed|--edi|--edit)
|
|
|
|
edit_flag=t
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-i|--i|--in|--inc|--incl|--inclu|--includ|--include)
|
|
|
|
also=t
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-o|--o|--on|--onl|--only)
|
|
|
|
only=t
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-m|--m|--me|--mes|--mess|--messa|--messag|--message)
|
|
|
|
case "$#" in 1) usage ;; esac
|
|
|
|
shift
|
|
|
|
log_given=m$log_given
|
|
|
|
if test "$log_message" = ''
|
|
|
|
then
|
|
|
|
log_message="$1"
|
|
|
|
else
|
|
|
|
log_message="$log_message
|
2006-05-29 10:45:49 +02:00
|
|
|
|
|
|
|
$1"
|
2006-10-07 21:07:40 +02:00
|
|
|
fi
|
|
|
|
no_edit=t
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-m*)
|
|
|
|
log_given=m$log_given
|
|
|
|
if test "$log_message" = ''
|
|
|
|
then
|
|
|
|
log_message=`expr "z$1" : 'z-m\(.*\)'`
|
|
|
|
else
|
|
|
|
log_message="$log_message
|
2006-05-29 10:45:49 +02:00
|
|
|
|
2006-06-27 18:54:26 +02:00
|
|
|
`expr "z$1" : 'z-m\(.*\)'`"
|
2006-10-07 21:07:40 +02:00
|
|
|
fi
|
|
|
|
no_edit=t
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*)
|
|
|
|
log_given=m$log_given
|
|
|
|
if test "$log_message" = ''
|
|
|
|
then
|
|
|
|
log_message=`expr "z$1" : 'z-[^=]*=\(.*\)'`
|
|
|
|
else
|
|
|
|
log_message="$log_message
|
2006-05-29 10:45:49 +02:00
|
|
|
|
2006-06-27 18:54:26 +02:00
|
|
|
`expr "z$1" : 'zq-[^=]*=\(.*\)'`"
|
2006-10-07 21:07:40 +02:00
|
|
|
fi
|
|
|
|
no_edit=t
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-n|--n|--no|--no-|--no-v|--no-ve|--no-ver|--no-veri|--no-verif|\
|
|
|
|
--no-verify)
|
|
|
|
verify=
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--a|--am|--ame|--amen|--amend)
|
|
|
|
amend=t
|
|
|
|
log_given=t$log_given
|
|
|
|
use_commit=HEAD
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-c)
|
|
|
|
case "$#" in 1) usage ;; esac
|
|
|
|
shift
|
|
|
|
log_given=t$log_given
|
|
|
|
use_commit="$1"
|
|
|
|
no_edit=
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--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 "z$1" : 'z-[^=]*=\(.*\)'`
|
|
|
|
no_edit=
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--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=
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-C)
|
|
|
|
case "$#" in 1) usage ;; esac
|
|
|
|
shift
|
|
|
|
log_given=t$log_given
|
|
|
|
use_commit="$1"
|
|
|
|
no_edit=t
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--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 "z$1" : 'z-[^=]*=\(.*\)'`
|
|
|
|
no_edit=t
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--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
|
|
|
|
;;
|
|
|
|
-s|--s|--si|--sig|--sign|--signo|--signof|--signoff)
|
|
|
|
signoff=t
|
|
|
|
shift
|
|
|
|
;;
|
2006-12-15 05:15:44 +01:00
|
|
|
-q|--q|--qu|--qui|--quie|--quiet)
|
|
|
|
quiet=t
|
|
|
|
shift
|
|
|
|
;;
|
2006-10-07 21:07:40 +02:00
|
|
|
-v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
|
|
|
|
verbose=t
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-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
|
|
|
|
;;
|
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
-*)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
2005-06-25 11:22:05 +02:00
|
|
|
done
|
2006-06-23 15:43:38 +02:00
|
|
|
case "$edit_flag" in t) no_edit= ;; esac
|
2005-06-25 11:22:05 +02:00
|
|
|
|
2006-02-10 09:45:59 +01:00
|
|
|
################################################################
|
|
|
|
# Sanity check options
|
|
|
|
|
2006-03-03 06:04:05 +01:00
|
|
|
case "$amend,$initial_commit" in
|
|
|
|
t,t)
|
2006-10-07 21:07:40 +02:00
|
|
|
die "You do not have anything to amend." ;;
|
2006-03-03 06:04:05 +01:00
|
|
|
t,)
|
2006-10-07 21:07:40 +02:00
|
|
|
if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
|
|
|
|
die "You are in the middle of a merge -- cannot amend."
|
|
|
|
fi ;;
|
2006-03-03 06:04:05 +01:00
|
|
|
esac
|
|
|
|
|
2005-08-09 02:03:14 +02:00
|
|
|
case "$log_given" in
|
|
|
|
tt*)
|
2006-10-07 21:07:40 +02:00
|
|
|
die "Only one of -c/-C/-F can be used." ;;
|
2006-05-29 10:45:49 +02:00
|
|
|
*tm*|*mt*)
|
2006-10-07 21:07:40 +02:00
|
|
|
die "Option -m cannot be combined with -c/-C/-F." ;;
|
2005-08-09 02:03:14 +02:00
|
|
|
esac
|
|
|
|
|
2006-04-20 10:20:56 +02:00
|
|
|
case "$#,$also,$only,$amend" in
|
|
|
|
*,t,t,*)
|
2006-10-07 21:07:40 +02:00
|
|
|
die "Only one of --include/--only can be used." ;;
|
2006-04-20 10:20:56 +02:00
|
|
|
0,t,,* | 0,,t,)
|
2006-10-07 21:07:40 +02:00
|
|
|
die "No paths with --include/--only does not make sense." ;;
|
2006-04-20 10:20:56 +02:00
|
|
|
0,,t,t)
|
2006-10-07 21:07:40 +02:00
|
|
|
only_include_assumed="# Clever... amending the last one with dirty index." ;;
|
2006-04-20 10:20:56 +02:00
|
|
|
0,,,*)
|
2006-10-07 21:07:40 +02:00
|
|
|
;;
|
2006-04-20 10:20:56 +02:00
|
|
|
*,,,*)
|
2006-10-07 21:07:40 +02:00
|
|
|
only_include_assumed="# Explicit paths specified without -i nor -o; assuming --only paths..."
|
|
|
|
also=
|
|
|
|
;;
|
2006-02-06 01:08:01 +01:00
|
|
|
esac
|
|
|
|
unset only
|
2006-02-10 09:45:59 +01:00
|
|
|
case "$all,$also,$#" in
|
|
|
|
t,t,*)
|
|
|
|
die "Cannot use -a and -i at the same time." ;;
|
|
|
|
t,,[1-9]*)
|
|
|
|
die "Paths with -a does not make sense." ;;
|
|
|
|
,t,0)
|
|
|
|
die "No paths with -i does not make sense." ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
################################################################
|
|
|
|
# Prepare index to have a tree to be committed
|
2006-02-06 01:08:01 +01:00
|
|
|
|
2006-02-05 09:07:44 +01:00
|
|
|
TOP=`git-rev-parse --show-cdup`
|
2006-02-06 01:08:01 +01:00
|
|
|
if test -z "$TOP"
|
|
|
|
then
|
|
|
|
TOP=./
|
|
|
|
fi
|
2006-02-05 09:07:44 +01:00
|
|
|
|
|
|
|
case "$all,$also" in
|
|
|
|
t,)
|
2006-02-06 01:08:01 +01:00
|
|
|
save_index &&
|
2006-02-05 09:07:44 +01:00
|
|
|
(
|
2006-02-06 01:08:01 +01:00
|
|
|
cd "$TOP"
|
2006-02-10 09:45:59 +01:00
|
|
|
GIT_INDEX_FILE="$NEXT_INDEX"
|
|
|
|
export GIT_INDEX_FILE
|
2006-02-05 09:07:44 +01:00
|
|
|
git-diff-files --name-only -z |
|
|
|
|
git-update-index --remove -z --stdin
|
|
|
|
)
|
2005-08-18 00:17:03 +02:00
|
|
|
;;
|
2006-02-05 09:07:44 +01:00
|
|
|
,t)
|
2006-02-06 01:08:01 +01:00
|
|
|
save_index &&
|
2006-02-14 21:40:20 +01:00
|
|
|
git-ls-files --error-unmatch -- "$@" >/dev/null || exit
|
|
|
|
|
2006-02-05 09:07:44 +01:00
|
|
|
git-diff-files --name-only -z -- "$@" |
|
2006-02-10 09:45:59 +01:00
|
|
|
(
|
|
|
|
cd "$TOP"
|
|
|
|
GIT_INDEX_FILE="$NEXT_INDEX"
|
|
|
|
export GIT_INDEX_FILE
|
|
|
|
git-update-index --remove -z --stdin
|
|
|
|
)
|
2005-08-17 03:08:19 +02:00
|
|
|
;;
|
2006-02-05 09:07:44 +01:00
|
|
|
,)
|
|
|
|
case "$#" in
|
|
|
|
0)
|
2006-10-07 21:07:40 +02:00
|
|
|
;; # commit as-is
|
2006-02-05 09:07:44 +01:00
|
|
|
*)
|
2006-10-07 21:07:40 +02:00
|
|
|
if test -f "$GIT_DIR/MERGE_HEAD"
|
|
|
|
then
|
|
|
|
refuse_partial "Cannot do a partial commit during a merge."
|
|
|
|
fi
|
|
|
|
TMP_INDEX="$GIT_DIR/tmp-index$$"
|
|
|
|
commit_only=`git-ls-files --error-unmatch -- "$@"` || exit
|
2006-02-10 09:45:59 +01:00
|
|
|
|
2006-12-10 07:32:43 +01:00
|
|
|
# Build a temporary index and update the real index
|
2006-10-07 21:07:40 +02:00
|
|
|
# the same way.
|
|
|
|
if test -z "$initial_commit"
|
|
|
|
then
|
|
|
|
cp "$THIS_INDEX" "$TMP_INDEX"
|
|
|
|
GIT_INDEX_FILE="$TMP_INDEX" git-read-tree -m HEAD
|
|
|
|
else
|
|
|
|
rm -f "$TMP_INDEX"
|
|
|
|
fi || exit
|
2006-02-10 09:45:59 +01:00
|
|
|
|
2006-10-07 21:07:40 +02:00
|
|
|
echo "$commit_only" |
|
|
|
|
GIT_INDEX_FILE="$TMP_INDEX" \
|
|
|
|
git-update-index --add --remove --stdin &&
|
2006-02-10 09:45:59 +01:00
|
|
|
|
2006-10-07 21:07:40 +02:00
|
|
|
save_index &&
|
|
|
|
echo "$commit_only" |
|
|
|
|
(
|
|
|
|
GIT_INDEX_FILE="$NEXT_INDEX"
|
|
|
|
export GIT_INDEX_FILE
|
|
|
|
git-update-index --remove --stdin
|
|
|
|
) || exit
|
|
|
|
;;
|
2006-02-05 09:07:44 +01:00
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2006-02-10 09:45:59 +01: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 09:07:44 +01:00
|
|
|
|
2006-02-10 09:45:59 +01:00
|
|
|
if test -f "$NEXT_INDEX"
|
2006-02-05 09:07:44 +01:00
|
|
|
then
|
2006-02-10 09:45:59 +01:00
|
|
|
USE_INDEX="$NEXT_INDEX"
|
|
|
|
else
|
|
|
|
USE_INDEX="$THIS_INDEX"
|
2006-02-05 09:07:44 +01:00
|
|
|
fi
|
|
|
|
|
2006-02-10 09:45:59 +01:00
|
|
|
GIT_INDEX_FILE="$USE_INDEX" \
|
2006-10-07 21:07:40 +02:00
|
|
|
git-update-index -q $unmerged_ok_if_status --refresh || exit
|
2006-02-10 09:45:59 +01:00
|
|
|
|
|
|
|
################################################################
|
|
|
|
# If the request is status, just show it and exit.
|
|
|
|
|
|
|
|
case "$0" in
|
|
|
|
*status)
|
|
|
|
run_status
|
|
|
|
exit $?
|
|
|
|
esac
|
|
|
|
|
|
|
|
################################################################
|
|
|
|
# Grab commit message, write out tree and make commit.
|
|
|
|
|
2006-02-05 09:07:44 +01:00
|
|
|
if test t = "$verify" && test -x "$GIT_DIR"/hooks/pre-commit
|
|
|
|
then
|
|
|
|
if test "$TMP_INDEX"
|
|
|
|
then
|
|
|
|
GIT_INDEX_FILE="$TMP_INDEX" "$GIT_DIR"/hooks/pre-commit
|
|
|
|
else
|
2006-02-10 09:45:59 +01:00
|
|
|
GIT_INDEX_FILE="$USE_INDEX" "$GIT_DIR"/hooks/pre-commit
|
2006-02-05 09:07:44 +01:00
|
|
|
fi || exit
|
|
|
|
fi
|
2005-08-13 08:39:15 +02:00
|
|
|
|
2005-08-26 03:57:35 +02:00
|
|
|
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'
|
2006-10-12 23:52:42 +02:00
|
|
|
elif test -f "$GIT_DIR/MERGE_MSG"
|
2005-11-02 07:01:28 +01: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 10:37:02 +02:00
|
|
|
elif test -f "$GIT_DIR/SQUASH_MSG"
|
|
|
|
then
|
|
|
|
cat "$GIT_DIR/SQUASH_MSG"
|
2005-10-10 02:30:19 +02:00
|
|
|
fi | git-stripspace >"$GIT_DIR"/COMMIT_EDITMSG
|
2005-09-01 02:15:25 +02:00
|
|
|
|
|
|
|
case "$signoff" in
|
|
|
|
t)
|
2005-10-04 08:49:46 +02:00
|
|
|
{
|
|
|
|
echo
|
|
|
|
git-var GIT_COMMITTER_IDENT | sed -e '
|
|
|
|
s/>.*/>/
|
|
|
|
s/^/Signed-off-by: /
|
|
|
|
'
|
2005-10-10 02:30:19 +02:00
|
|
|
} >>"$GIT_DIR"/COMMIT_EDITMSG
|
2005-09-01 02:15:25 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2006-04-12 20:45:18 +02:00
|
|
|
if test -f "$GIT_DIR/MERGE_HEAD" && test -z "$no_edit"; then
|
2005-09-01 02:15:25 +02:00
|
|
|
echo "#"
|
2006-01-05 12:44:59 +01:00
|
|
|
echo "# It looks like you may be committing a MERGE."
|
2005-09-01 02:15:25 +02:00
|
|
|
echo "# If this is not correct, please remove the file"
|
|
|
|
echo "# $GIT_DIR/MERGE_HEAD"
|
|
|
|
echo "# and try again"
|
|
|
|
echo "#"
|
2005-10-10 02:30:19 +02:00
|
|
|
fi >>"$GIT_DIR"/COMMIT_EDITMSG
|
2005-08-26 03:57:35 +02:00
|
|
|
|
2006-02-05 09:07:44 +01:00
|
|
|
# Author
|
2006-02-06 01:08:01 +01:00
|
|
|
if test '' != "$force_author"
|
|
|
|
then
|
2006-04-14 00:01:24 +02:00
|
|
|
GIT_AUTHOR_NAME=`expr "z$force_author" : 'z\(.*[^ ]\) *<.*'` &&
|
|
|
|
GIT_AUTHOR_EMAIL=`expr "z$force_author" : '.*\(<.*\)'` &&
|
2006-02-06 01:08:01 +01:00
|
|
|
test '' != "$GIT_AUTHOR_NAME" &&
|
|
|
|
test '' != "$GIT_AUTHOR_EMAIL" ||
|
2006-07-10 07:50:18 +02:00
|
|
|
die "malformed --author parameter"
|
2006-02-06 01:08:01 +01:00
|
|
|
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
|
|
|
|
elif test '' != "$use_commit"
|
2006-02-05 09:07:44 +01:00
|
|
|
then
|
|
|
|
pick_author_script='
|
|
|
|
/^author /{
|
|
|
|
s/'\''/'\''\\'\'\''/g
|
|
|
|
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" |
|
|
|
|
LANG=C LC_ALL=C sed -ne "$pick_author_script"`
|
|
|
|
eval "$set_author_env"
|
|
|
|
export GIT_AUTHOR_NAME
|
|
|
|
export GIT_AUTHOR_EMAIL
|
|
|
|
export GIT_AUTHOR_DATE
|
|
|
|
fi
|
|
|
|
|
2005-06-14 19:20:14 +02:00
|
|
|
PARENTS="-p HEAD"
|
2006-02-05 09:07:44 +01:00
|
|
|
if test -z "$initial_commit"
|
2005-09-30 23:26:57 +02:00
|
|
|
then
|
2006-07-11 04:48:47 +02:00
|
|
|
rloga='commit'
|
2005-06-25 11:22:05 +02:00
|
|
|
if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
|
2006-07-11 04:48:47 +02:00
|
|
|
rloga='commit (merge)'
|
Multi-backend merge driver.
The new command 'git merge' takes the current head and one or more
remote heads, with the commit log message for the automated case.
If the heads being merged are simple fast-forwards, it acts the
same way as the current 'git resolve'. Otherwise, it tries
different merge strategies and takes the result from the one that
succeeded auto-merging, if there is any.
If no merge strategy succeeds auto-merging, their results are
evaluated for number of paths needed for hand resolving, and the
one with the least number of such paths is left in the working
tree. The user is asked to resolve them by hand and make a
commit manually.
The calling convention from the 'git merge' driver to merge
strategy programs is very simple:
- A strategy program is to be called 'git-merge-<strategy>'.
- They take input of this form:
<common1> <common2> ... '--' <head> <remote1> <remote2>...
That is, one or more the common ancestors, double dash, the
current head, and one or more remote heads being merged into
the current branch.
- Before a strategy program is called, the working tree is
matched to the current <head>.
- The strategy program exits with status code 0 when it
successfully auto-merges the given heads. It should do
update-cache for all the merged paths when it does so -- the
index file will be used to record the merge result as a
commit by the driver.
- The strategy program exits with status code 1 when it leaves
conflicts behind. It should do update-cache for all the
merged paths that it successfully auto-merged, and leave the
cache entry in the index file as the same as <head> for paths
it could not auto-merge, and leave its best-effort result
with conflict markers in the working tree when it does so.
- The strategy program exists with status code other than 0 or
1 if it does not handle the given merge at all.
As examples, this commit comes with merge strategies based on
'git resolve' and 'git octopus'.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-09-08 22:47:12 +02:00
|
|
|
PARENTS="-p HEAD "`sed -e 's/^/-p /' "$GIT_DIR/MERGE_HEAD"`
|
2006-03-03 06:04:05 +01:00
|
|
|
elif test -n "$amend"; then
|
2006-07-11 04:48:47 +02:00
|
|
|
rloga='commit (amend)'
|
2006-03-03 06:04:05 +01:00
|
|
|
PARENTS=$(git-cat-file commit HEAD |
|
|
|
|
sed -n -e '/^$/q' -e 's/^parent /-p /p')
|
2005-08-26 03:57:35 +02:00
|
|
|
fi
|
2006-09-27 11:06:31 +02:00
|
|
|
current="$(git-rev-parse --verify HEAD)"
|
2005-09-30 23:26:57 +02:00
|
|
|
else
|
|
|
|
if [ -z "$(git-ls-files)" ]; then
|
2006-12-16 03:53:09 +01:00
|
|
|
echo >&2 'nothing to commit (use "git add file1 file2" to include for commit)'
|
2005-09-30 23:26:57 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
PARENTS=""
|
2006-07-11 04:48:47 +02:00
|
|
|
rloga='commit (initial)'
|
2006-09-27 11:06:31 +02:00
|
|
|
current=''
|
2005-06-14 19:20:14 +02:00
|
|
|
fi
|
2006-02-05 09:07:44 +01:00
|
|
|
|
2006-04-12 20:45:18 +02:00
|
|
|
if test -z "$no_edit"
|
|
|
|
then
|
|
|
|
{
|
2006-05-26 01:42:18 +02:00
|
|
|
echo ""
|
|
|
|
echo "# Please enter the commit message for your changes."
|
|
|
|
echo "# (Comment lines starting with '#' will not be included)"
|
2006-04-12 20:45:18 +02: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
|
|
|
|
run_status >/dev/null
|
|
|
|
fi
|
2006-03-05 05:36:28 +01:00
|
|
|
if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" -a -z "$amend" ]
|
2005-05-30 21:51:00 +02:00
|
|
|
then
|
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 10:37:02 +02:00
|
|
|
rm -f "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
|
2006-02-06 01:08:01 +01:00
|
|
|
run_status
|
2005-05-30 21:51:00 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2006-04-12 20:45:18 +02:00
|
|
|
|
2005-08-09 02:03:14 +02:00
|
|
|
case "$no_edit" in
|
2005-06-25 11:22:05 +02:00
|
|
|
'')
|
2006-02-05 07:10:32 +01:00
|
|
|
case "${VISUAL:-$EDITOR},$TERM" in
|
|
|
|
,dumb)
|
|
|
|
echo >&2 "Terminal is dumb but no VISUAL nor EDITOR defined."
|
|
|
|
echo >&2 "Please supply the commit log message using either"
|
|
|
|
echo >&2 "-m or -F option. A boilerplate log message has"
|
|
|
|
echo >&2 "been prepared in $GIT_DIR/COMMIT_EDITMSG"
|
2006-02-05 09:07:44 +01:00
|
|
|
exit 1
|
|
|
|
;;
|
2006-02-05 07:10:32 +01:00
|
|
|
esac
|
2006-05-14 05:09:32 +02:00
|
|
|
git-var GIT_AUTHOR_IDENT > /dev/null || die
|
|
|
|
git-var GIT_COMMITTER_IDENT > /dev/null || die
|
2005-10-10 02:30:19 +02:00
|
|
|
${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG"
|
2005-06-25 11:22:05 +02:00
|
|
|
;;
|
|
|
|
esac
|
2005-08-19 02:20:08 +02:00
|
|
|
|
|
|
|
case "$verify" in
|
|
|
|
t)
|
|
|
|
if test -x "$GIT_DIR"/hooks/commit-msg
|
|
|
|
then
|
2005-10-10 02:30:19 +02:00
|
|
|
"$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/COMMIT_EDITMSG || exit
|
2005-08-19 02:20:08 +02:00
|
|
|
fi
|
|
|
|
esac
|
|
|
|
|
2006-06-24 00:04:05 +02: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 |
|
2006-02-10 09:45:59 +01:00
|
|
|
git-stripspace >"$GIT_DIR"/COMMIT_MSG
|
2005-10-10 02:30:19 +02:00
|
|
|
|
|
|
|
if cnt=`grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG |
|
|
|
|
git-stripspace |
|
|
|
|
wc -l` &&
|
|
|
|
test 0 -lt $cnt
|
2005-08-09 02:03:14 +02:00
|
|
|
then
|
2006-02-05 09:07:44 +01:00
|
|
|
if test -z "$TMP_INDEX"
|
|
|
|
then
|
2006-02-10 09:45:59 +01:00
|
|
|
tree=$(GIT_INDEX_FILE="$USE_INDEX" git-write-tree)
|
2006-02-05 09:07:44 +01:00
|
|
|
else
|
|
|
|
tree=$(GIT_INDEX_FILE="$TMP_INDEX" git-write-tree) &&
|
|
|
|
rm -f "$TMP_INDEX"
|
|
|
|
fi &&
|
2005-10-10 02:30:19 +02:00
|
|
|
commit=$(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree $tree $PARENTS) &&
|
2006-05-19 11:16:18 +02:00
|
|
|
rlogm=$(sed -e 1q "$GIT_DIR"/COMMIT_MSG) &&
|
2006-09-27 11:06:31 +02:00
|
|
|
git-update-ref -m "$rloga: $rlogm" HEAD $commit "$current" &&
|
2006-10-12 23:52:42 +02:00
|
|
|
rm -f -- "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/MERGE_MSG" &&
|
2006-02-10 09:45:59 +01:00
|
|
|
if test -f "$NEXT_INDEX"
|
|
|
|
then
|
|
|
|
mv "$NEXT_INDEX" "$THIS_INDEX"
|
|
|
|
else
|
|
|
|
: ;# happy
|
|
|
|
fi
|
2005-08-09 02:03:14 +02:00
|
|
|
else
|
|
|
|
echo >&2 "* no commit message? aborting commit."
|
|
|
|
false
|
|
|
|
fi
|
2005-06-20 04:57:01 +02: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 10:37:02 +02:00
|
|
|
rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
|
2006-02-12 03:55:43 +01:00
|
|
|
if test -d "$GIT_DIR/rr-cache"
|
|
|
|
then
|
|
|
|
git-rerere
|
|
|
|
fi
|
2005-08-19 02:20:08 +02:00
|
|
|
|
2006-12-15 05:15:44 +01:00
|
|
|
if test "$ret" = 0
|
2005-08-19 02:20:08 +02:00
|
|
|
then
|
2006-12-15 05:15:44 +01:00
|
|
|
if test -x "$GIT_DIR"/hooks/post-commit
|
|
|
|
then
|
|
|
|
"$GIT_DIR"/hooks/post-commit
|
|
|
|
fi
|
|
|
|
if test -z "$quiet"
|
|
|
|
then
|
|
|
|
echo "Created${initial_commit:+ initial} commit $commit"
|
2007-01-08 20:23:13 +01:00
|
|
|
git-diff-tree --shortstat --summary --root --no-commit-id HEAD --
|
2006-12-15 05:15:44 +01:00
|
|
|
fi
|
2005-08-19 02:20:08 +02:00
|
|
|
fi
|
2006-10-25 06:48:55 +02:00
|
|
|
|
2005-06-20 04:57:01 +02:00
|
|
|
exit "$ret"
|