Merge branch 'jc/squash'

* jc/squash:
  git-merge --squash
This commit is contained in:
Junio C Hamano
2006-06-26 14:36:10 -07:00
5 changed files with 72 additions and 24 deletions

View File

@@ -6,6 +6,14 @@
not autocommit, to give the user a chance to inspect and not autocommit, to give the user a chance to inspect and
further tweak the merge result before committing. further tweak the merge result before committing.
--squash::
Produce the working tree and index state as if a real
merge happened, but do not actually make a commit or
move the `HEAD`, nor record `$GIT_DIR/MERGE_HEAD` to
cause the next `git commit` command to create a merge
commit. This allows you to create a single commit on
top of the current branch whose effect is the same as
merging another branch (or more in case of an octopus).
-s <strategy>, \--strategy=<strategy>:: -s <strategy>, \--strategy=<strategy>::
Use the given merge strategy; can be supplied more than Use the given merge strategy; can be supplied more than

View File

@@ -566,6 +566,9 @@ then
elif test -f "$GIT_DIR/MERGE_HEAD" && test -f "$GIT_DIR/MERGE_MSG" elif test -f "$GIT_DIR/MERGE_HEAD" && test -f "$GIT_DIR/MERGE_MSG"
then then
cat "$GIT_DIR/MERGE_MSG" cat "$GIT_DIR/MERGE_MSG"
elif test -f "$GIT_DIR/SQUASH_MSG"
then
cat "$GIT_DIR/SQUASH_MSG"
fi | git-stripspace >"$GIT_DIR"/COMMIT_EDITMSG fi | git-stripspace >"$GIT_DIR"/COMMIT_EDITMSG
case "$signoff" in case "$signoff" in
@@ -663,7 +666,7 @@ else
fi fi
if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" -a -z "$amend" ] if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" -a -z "$amend" ]
then then
rm -f "$GIT_DIR/COMMIT_EDITMSG" rm -f "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
run_status run_status
exit 1 exit 1
fi fi
@@ -734,7 +737,7 @@ else
false false
fi fi
ret="$?" ret="$?"
rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG" rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
if test -d "$GIT_DIR/rr-cache" if test -d "$GIT_DIR/rr-cache"
then then
git-rerere git-rerere

View File

@@ -3,8 +3,7 @@
# Copyright (c) 2005 Junio C Hamano # Copyright (c) 2005 Junio C Hamano
# #
USAGE='[-n] [--no-commit] [--squash] [-s <strategy>]... <merge-message> <head> <remote>+'
USAGE='[-n] [--no-commit] [-s <strategy>]... <merge-message> <head> <remote>+'
. git-sh-setup . git-sh-setup
LF=' LF='
@@ -42,20 +41,49 @@ restorestate() {
fi fi
} }
finish_up_to_date () {
case "$squash" in
t)
echo "$1 (nothing to squash)" ;;
'')
echo "$1" ;;
esac
dropsave
}
squash_message () {
echo Squashed commit of the following:
echo
git-log --no-merges ^"$head" $remote
}
finish () { finish () {
test '' = "$2" || echo "$2" test '' = "$2" || echo "$2"
case "$merge_msg" in case "$squash" in
'') t)
echo "No merge message -- not updating HEAD" echo "Squash commit -- not updating HEAD"
squash_message >"$GIT_DIR/SQUASH_MSG"
;; ;;
*) '')
git-update-ref HEAD "$1" "$head" || exit 1 case "$merge_msg" in
'')
echo "No merge message -- not updating HEAD"
;;
*)
git-update-ref HEAD "$1" "$head" || exit 1
;;
esac
;; ;;
esac esac
case "$1" in
case "$no_summary" in
'') '')
git-diff-tree --stat --summary -M "$head" "$1" ;;
?*)
case "$no_summary" in
'')
git-diff-tree --stat --summary -M "$head" "$1"
;;
esac
;; ;;
esac esac
} }
@@ -66,6 +94,8 @@ do
-n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\ -n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\
--no-summa|--no-summar|--no-summary) --no-summa|--no-summar|--no-summary)
no_summary=t ;; no_summary=t ;;
--sq|--squ|--squa|--squas|--squash)
squash=t no_commit=t ;;
--no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit) --no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
no_commit=t ;; no_commit=t ;;
-s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\ -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
@@ -152,8 +182,7 @@ f,*)
?,1,"$1",*) ?,1,"$1",*)
# If head can reach all the merge then we are up to date. # If head can reach all the merge then we are up to date.
# but first the most common case of merging one remote. # but first the most common case of merging one remote.
echo "Already up-to-date." finish_up_to_date "Already up-to-date."
dropsave
exit 0 exit 0
;; ;;
?,1,"$head",*) ?,1,"$head",*)
@@ -205,8 +234,7 @@ f,*)
done done
if test "$up_to_date" = t if test "$up_to_date" = t
then then
echo "Already up-to-date. Yeeah!" finish_up_to_date "Already up-to-date. Yeeah!"
dropsave
exit 0 exit 0
fi fi
;; ;;
@@ -310,11 +338,17 @@ case "$best_strategy" in
git-merge-$best_strategy $common -- "$head_arg" "$@" git-merge-$best_strategy $common -- "$head_arg" "$@"
;; ;;
esac esac
for remote
do if test "$squash" = t
echo $remote then
done >"$GIT_DIR/MERGE_HEAD" finish
echo "$merge_msg" >"$GIT_DIR/MERGE_MSG" else
for remote
do
echo $remote
done >"$GIT_DIR/MERGE_HEAD"
echo "$merge_msg" >"$GIT_DIR/MERGE_MSG"
fi
if test "$merge_was_ok" = t if test "$merge_was_ok" = t
then then

View File

@@ -8,7 +8,7 @@ USAGE='[-n | --no-summary] [--no-commit] [-s strategy]... [<fetch-options>] <rep
LONG_USAGE='Fetch one or more remote refs and merge it/them into the current HEAD.' LONG_USAGE='Fetch one or more remote refs and merge it/them into the current HEAD.'
. git-sh-setup . git-sh-setup
strategy_args= no_summary= no_commit= strategy_args= no_summary= no_commit= squash=
while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac
do do
case "$1" in case "$1" in
@@ -17,6 +17,8 @@ do
no_summary=-n ;; no_summary=-n ;;
--no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit) --no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
no_commit=--no-commit ;; no_commit=--no-commit ;;
--sq|--squ|--squa|--squas|--squash)
squash=--squash ;;
-s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\ -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
--strateg=*|--strategy=*|\ --strateg=*|--strategy=*|\
-s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy) -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
@@ -100,4 +102,5 @@ case "$strategy_args" in
esac esac
merge_name=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD") || exit merge_name=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD") || exit
git-merge $no_summary $no_commit $strategy_args "$merge_name" HEAD $merge_head git-merge $no_summary $no_commit $squash $strategy_args \
"$merge_name" HEAD $merge_head

View File

@@ -61,4 +61,4 @@ case "$reset_type" in
;; ;;
esac esac
rm -f "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/rr-cache/MERGE_RR" rm -f "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/rr-cache/MERGE_RR" "$GIT_DIR/SQUASH_MSG"