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>
Sverre Rabbelier committed
Feb 13, 2009 at 23:48 UTC
b2f82e05de2512ae4adb63b669f6c1fe6cba3148
1 file changed
+19
-5
git-rebase.sh
+19
-5
@@ -3,7 +3,7 @@
3
# Copyright (c) 2005 Junio C Hamano.
4
#
5
6
-USAGE='[--interactive | -i] [-v] [--onto <newbase>] [<upstream>|--root] [<branch>]'
6
+USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--onto <newbase>] [<upstream>|--root] [<branch>]'
7
LONG_USAGE='git-rebase replaces <branch> with a new branch of the
8
same name. When the --onto option is provided the new branch starts
9
out with a HEAD equal to <newbase>, otherwise it is equal to <upstream>
@@ -48,6 +48,7 @@ prec=4
48
verbose=
49
git_am_opt=
50
rebase_root=
51
+force_rebase=
52
53
continue_merge () {
54
test -n "$prev_head" || die "prev_head must be defined"
@@ -294,6 +295,11 @@ do
295
;;
296
--whitespace=*)
297
git_am_opt="$git_am_opt $1"
298
+ case "$1" in
299
+ --whitespace=fix|--whitespace=strip)
300
+ force_rebase=t
301
+ ;;
302
+ esac
303
;;
304
-C*)
305
git_am_opt="$git_am_opt $1"
@@ -301,6 +307,9 @@ do
307
--root)
308
rebase_root=t
309
;;
310
+ -f|--f|--fo|--for|--forc|force|--force-r|--force-re|--force-reb|--force-reba|--force_rebas|--force-rebase)
311
+ force_rebase=t
312
+ ;;
313
-*)
314
usage
315
;;
@@ -419,10 +428,15 @@ if test "$upstream" = "$onto" && test "$mb" = "$onto" &&
428
# linear history?
429
! (git rev-list --parents "$onto".."$branch" | grep " .* ") > /dev/null
430
then
422
- # Lazily switch to the target branch if needed...
423
- test -z "$switch_to" || git checkout "$switch_to"
424
- echo >&2 "Current branch $branch_name is up to date."
425
- exit 0
431
+ if test -z "$force_rebase"
432
+ then
433
+ # Lazily switch to the target branch if needed...
434
+ test -z "$switch_to" || git checkout "$switch_to"
435
+ echo >&2 "Current branch $branch_name is up to date."
436
+ exit 0
437
+ else
438
+ echo "Current branch $branch_name is up to date, rebase forced."
439
+ fi
440
fi
441
442
if test -n "$verbose"