From 15a147e61898d25ec8b539190e87f3a09592c9c8 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Wed, 9 Feb 2011 20:54:02 -0500 Subject: rebase: use @{upstream} if no upstream specified 'git rebase' without arguments is currently not supported. Make it default to 'git rebase @{upstream}'. That is also what 'git pull [--rebase]' defaults to, so it only makes sense that 'git rebase' defaults to the same thing. Defaulting to @{upstream} will make it possible to run e.g. 'git rebase -i' without arguments, which is probably a quite common use case. It also improves the scenario where you have multiple branches that rebase against a remote-tracking branch, where you currently have to choose between the extra network delay of 'git pull' or the slightly awkward keys to enter 'git rebase @{u}'. The error reporting when no upstream is configured for the current branch or when no branch is checked out is reused from git-pull.sh. A function is extracted into git-parse-remote.sh for this purpose. Helped-by: Yann Dirson Helped-by: Jonathan Nieder Signed-off-by: Martin von Zweigbergk Signed-off-by: Junio C Hamano --- git-rebase.sh | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'git-rebase.sh') diff --git a/git-rebase.sh b/git-rebase.sh index be9ec2a1f..a040ab51c 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -3,7 +3,7 @@ # Copyright (c) 2005 Junio C Hamano. # -USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--no-ff] [--onto ] (|--root) [] [--quiet | -q]' +USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--no-ff] [--onto ] [|--root] [] [--quiet | -q]' LONG_USAGE='git-rebase replaces with a new branch of the same name. When the --onto option is provided the new branch starts out with a HEAD equal to , otherwise it is equal to @@ -345,8 +345,6 @@ and run me again. I am stopping in case you still have something valuable there.' fi -test $# -eq 0 && test -z "$rebase_root" && usage - if test -n "$interactive_rebase" then type=interactive @@ -362,9 +360,20 @@ fi if test -z "$rebase_root" then - # The upstream head must be given. Make sure it is valid. - upstream_name="$1" - shift + case "$#" in + 0) + if ! upstream_name=$(git rev-parse --symbolic-full-name \ + --verify -q @{upstream} 2>/dev/null) + then + . git-parse-remote + error_on_missing_default_upstream "rebase" "rebase" \ + "against" "git rebase " + fi + ;; + *) upstream_name="$1" + shift + ;; + esac upstream=`git rev-parse --verify "${upstream_name}^0"` || die "invalid upstream $upstream_name" upstream_arg="$upstream_name" -- cgit v1.2.1