Teach rebase to rebase even if upstream is up to date

Normally, if the current branch is up to date, the rebase is aborted.
However, it may be desirable to allow rebasing even if the current
branch is up to date. When using the '--whitespace=fix' option -f is
implied.

Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Sverre Rabbelier 2009-02-13 23:48:01 +01:00 committed by Junio C Hamano
parent 5cd12b85fe
commit b2f82e05de

View File

@ -3,7 +3,7 @@
# Copyright (c) 2005 Junio C Hamano. # Copyright (c) 2005 Junio C Hamano.
# #
USAGE='[--interactive | -i] [-v] [--onto <newbase>] [<upstream>|--root] [<branch>]' USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--onto <newbase>] [<upstream>|--root] [<branch>]'
LONG_USAGE='git-rebase replaces <branch> with a new branch of the LONG_USAGE='git-rebase replaces <branch> with a new branch of the
same name. When the --onto option is provided the new branch starts same name. When the --onto option is provided the new branch starts
out with a HEAD equal to <newbase>, otherwise it is equal to <upstream> out with a HEAD equal to <newbase>, otherwise it is equal to <upstream>
@ -48,6 +48,7 @@ prec=4
verbose= verbose=
git_am_opt= git_am_opt=
rebase_root= rebase_root=
force_rebase=
continue_merge () { continue_merge () {
test -n "$prev_head" || die "prev_head must be defined" test -n "$prev_head" || die "prev_head must be defined"
@ -294,6 +295,11 @@ do
;; ;;
--whitespace=*) --whitespace=*)
git_am_opt="$git_am_opt $1" git_am_opt="$git_am_opt $1"
case "$1" in
--whitespace=fix|--whitespace=strip)
force_rebase=t
;;
esac
;; ;;
-C*) -C*)
git_am_opt="$git_am_opt $1" git_am_opt="$git_am_opt $1"
@ -301,6 +307,9 @@ do
--root) --root)
rebase_root=t rebase_root=t
;; ;;
-f|--f|--fo|--for|--forc|force|--force-r|--force-re|--force-reb|--force-reba|--force_rebas|--force-rebase)
force_rebase=t
;;
-*) -*)
usage usage
;; ;;
@ -419,10 +428,15 @@ if test "$upstream" = "$onto" && test "$mb" = "$onto" &&
# linear history? # linear history?
! (git rev-list --parents "$onto".."$branch" | grep " .* ") > /dev/null ! (git rev-list --parents "$onto".."$branch" | grep " .* ") > /dev/null
then then
# Lazily switch to the target branch if needed... if test -z "$force_rebase"
test -z "$switch_to" || git checkout "$switch_to" then
echo >&2 "Current branch $branch_name is up to date." # Lazily switch to the target branch if needed...
exit 0 test -z "$switch_to" || git checkout "$switch_to"
echo >&2 "Current branch $branch_name is up to date."
exit 0
else
echo "Current branch $branch_name is up to date, rebase forced."
fi
fi fi
if test -n "$verbose" if test -n "$verbose"