* [PATCH] rebase: use @{upstream} if no upstream specified
@ 2011-02-08 0:37 Martin von Zweigbergk
2011-02-08 17:46 ` Sverre Rabbelier
2011-02-10 1:54 ` Martin von Zweigbergk
0 siblings, 2 replies; 12+ messages in thread
From: Martin von Zweigbergk @ 2011-02-08 0:37 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Yann Dirson, Martin von Zweigbergk
'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}'.
Helped-by: Yann Dirson <ydirson@altern.org>
Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
Applies on top of the rebase refactoring series I sent yesterday, see
http://thread.gmane.org/gmane.comp.version-control.git/166161/
Documentation/config.txt | 2 +-
Documentation/git-rebase.txt | 11 +++++++++--
git-rebase.sh | 35 +++++++++++++++++++++++++++++------
t/t3400-rebase.sh | 25 +++++++++++++++++--------
4 files changed, 56 insertions(+), 17 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index c5e1835..b4e65b8 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -646,7 +646,7 @@ branch.<name>.remote::
branch.<name>.merge::
Defines, together with branch.<name>.remote, the upstream branch
- for the given branch. It tells 'git fetch'/'git pull' which
+ for the given branch. It tells 'git fetch'/'git pull'/'git rebase' which
branch to merge and can also affect 'git push' (see push.default).
When in branch <name>, it tells 'git fetch' the default
refspec to be marked for merging in FETCH_HEAD. The value is
diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 96680c8..d3e998d 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -9,7 +9,7 @@ SYNOPSIS
--------
[verse]
'git rebase' [-i | --interactive] [options] [--onto <newbase>]
- <upstream> [<branch>]
+ [<upstream>] [<branch>]
'git rebase' [-i | --interactive] [options] --onto <newbase>
--root [<branch>]
@@ -21,6 +21,12 @@ If <branch> is specified, 'git rebase' will perform an automatic
`git checkout <branch>` before doing anything else. Otherwise
it remains on the current branch.
+If <upstream> is not specified, the upstream configured in
+branch.<name>.remote and branch.<name>.merge options will be used; see
+linkgit:git-config[1] for details. If you are currently not on any
+branch or if the current branch does not have a configured upstream,
+the rebase will abort.
+
All changes made by commits in the current branch but that are not
in <upstream> are saved to a temporary area. This is the same set
of commits that would be shown by `git log <upstream>..HEAD` (or
@@ -216,7 +222,8 @@ leave out at most one of A and B, in which case it defaults to HEAD.
<upstream>::
Upstream branch to compare against. May be any valid commit,
- not just an existing branch name.
+ not just an existing branch name. Defaults to the configured
+ upstream for the current branch.
<branch>::
Working branch; defaults to HEAD.
diff --git a/git-rebase.sh b/git-rebase.sh
index be9ec2a..5975642 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 <newbase>] (<upstream>|--root) [<branch>] [--quiet | -q]'
+USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--no-ff] [--onto <newbase>] [<upstream>|--root] [<branch>] [--quiet | -q]'
LONG_USAGE='git-rebase replaces <branch> with a new branch of the
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>
@@ -144,6 +144,25 @@ run_pre_rebase_hook () {
fi
}
+error_on_missing_default_upstream () {
+ branch_name=$(git symbolic-ref -q HEAD)
+ if test -z "$branch_name"
+ then
+ die "You are not currently on a branch, so I cannot use any
+'branch.<branchname>.merge' in your configuration file.
+Please specify which upstream branch you want to use on the command
+line and try again (e.g. 'git rebase <upstream branch>').
+See git-rebase(1) for details."
+ else
+ die "You asked me to rebase without telling me which branch you
+want to rebase against, and 'branch.${branch_name#refs/heads/}.merge' in
+your configuration file does not tell me, either. Please
+specify which branch you want to use on the command line and
+try again (e.g. 'git rebase <upstream branch>').
+See git-rebase(1) for details."
+ fi
+}
+
test -f "$apply_dir"/applying &&
die 'It looks like git-am is in progress. Cannot rebase.'
@@ -345,8 +364,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 +379,15 @@ 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)
+ upstream_name=$(git rev-parse --symbolic-full-name --verify -q \
+ @{upstream}) || error_on_missing_default_upstream
+ ;;
+ *) upstream_name="$1"
+ shift
+ ;;
+ esac
upstream=`git rev-parse --verify "${upstream_name}^0"` ||
die "invalid upstream $upstream_name"
upstream_arg="$upstream_name"
diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
index 349eebd..3bd4a84 100755
--- a/t/t3400-rebase.sh
+++ b/t/t3400-rebase.sh
@@ -158,15 +158,24 @@ test_expect_success 'Show verbose error when HEAD could not be detached' '
'
rm -f B
-test_expect_success 'dump usage when upstream arg is missing' '
- git checkout -b usage topic &&
+test_expect_success 'fail when upstream arg is missing and not on branch' '
+ git checkout topic &&
test_must_fail git rebase 2>error1 &&
- grep "[Uu]sage" error1 &&
- test_must_fail git rebase --abort 2>error2 &&
- grep "No rebase in progress" error2 &&
- test_must_fail git rebase --onto master 2>error3 &&
- grep "[Uu]sage" error3 &&
- ! grep "can.t shift" error3
+ grep "You are not currently on a branch" error1
+'
+
+test_expect_success 'fail when upstream arg is missing and not configured' '
+ git checkout -b no-config topic &&
+ test_must_fail git rebase 2>error2 &&
+ grep "branch.no-config.merge" error2
+'
+
+test_expect_success 'default to @{upstream} when upstream arg is missing' '
+ git checkout -b default topic &&
+ git config branch.default.remote .
+ git config branch.default.merge refs/heads/master
+ git rebase &&
+ test "$(git rev-parse default~1)" = "$(git rev-parse master)"
'
test_expect_success 'rebase -q is quiet' '
--
1.7.4.rc2.33.g8a14f
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH] rebase: use @{upstream} if no upstream specified
2011-02-08 0:37 [PATCH] rebase: use @{upstream} if no upstream specified Martin von Zweigbergk
@ 2011-02-08 17:46 ` Sverre Rabbelier
2011-02-08 18:23 ` Martin von Zweigbergk
2011-02-10 1:54 ` Martin von Zweigbergk
1 sibling, 1 reply; 12+ messages in thread
From: Sverre Rabbelier @ 2011-02-08 17:46 UTC (permalink / raw)
To: Martin von Zweigbergk; +Cc: git, Junio C Hamano, Yann Dirson
Heya,
On Tue, Feb 8, 2011 at 01:37, Martin von Zweigbergk
<martin.von.zweigbergk@gmail.com> wrote:
> Defaulting to @{upstream} will make it possible to run e.g. 'git
> rebase -i' without arguments, which is probably a quite common use
> case.
I particularly like that you explain to the user clearly what they
have to do to make this work (e.g., configure the upstream). Nice.
--
Cheers,
Sverre Rabbelier
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] rebase: use @{upstream} if no upstream specified
2011-02-08 17:46 ` Sverre Rabbelier
@ 2011-02-08 18:23 ` Martin von Zweigbergk
2011-02-08 18:27 ` Sverre Rabbelier
2011-02-08 22:05 ` Jonathan Nieder
0 siblings, 2 replies; 12+ messages in thread
From: Martin von Zweigbergk @ 2011-02-08 18:23 UTC (permalink / raw)
To: Sverre Rabbelier; +Cc: Martin von Zweigbergk, git, Junio C Hamano, Yann Dirson
On Tue, 8 Feb 2011, Sverre Rabbelier wrote:
> Heya,
>
> On Tue, Feb 8, 2011 at 01:37, Martin von Zweigbergk
> <martin.von.zweigbergk@gmail.com> wrote:
> > Defaulting to @{upstream} will make it possible to run e.g. 'git
> > rebase -i' without arguments, which is probably a quite common use
> > case.
>
> I particularly like that you explain to the user clearly what they
> have to do to make this work (e.g., configure the upstream). Nice.
Thanks, but that was stolen from git-pull.sh ;-). Federico Mena
Quintero added it there in 8fc293c (Make git-pull complain and give
advice when there is nothing to merge with, 2007-10-02).
/Martin
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] rebase: use @{upstream} if no upstream specified
2011-02-08 18:23 ` Martin von Zweigbergk
@ 2011-02-08 18:27 ` Sverre Rabbelier
2011-02-08 22:05 ` Jonathan Nieder
1 sibling, 0 replies; 12+ messages in thread
From: Sverre Rabbelier @ 2011-02-08 18:27 UTC (permalink / raw)
To: Martin von Zweigbergk; +Cc: git, Junio C Hamano, Yann Dirson
Heya,
On Tue, Feb 8, 2011 at 19:23, Martin von Zweigbergk
<martin.von.zweigbergk@gmail.com> wrote:
> Thanks, but that was stolen from git-pull.sh ;-). Federico Mena
> Quintero added it there in 8fc293c (Make git-pull complain and give
> advice when there is nothing to merge with, 2007-10-02).
Credit where credit is due :), nonetheless, glad to see it here as well.
--
Cheers,
Sverre Rabbelier
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] rebase: use @{upstream} if no upstream specified
2011-02-08 18:23 ` Martin von Zweigbergk
2011-02-08 18:27 ` Sverre Rabbelier
@ 2011-02-08 22:05 ` Jonathan Nieder
2011-02-09 0:28 ` Martin von Zweigbergk
1 sibling, 1 reply; 12+ messages in thread
From: Jonathan Nieder @ 2011-02-08 22:05 UTC (permalink / raw)
To: Martin von Zweigbergk; +Cc: Sverre Rabbelier, git, Junio C Hamano, Yann Dirson
Martin von Zweigbergk wrote:
> On Tue, 8 Feb 2011, Sverre Rabbelier wrote:
>> I particularly like that you explain to the user clearly what they
>> have to do to make this work (e.g., configure the upstream). Nice.
>
> Thanks, but that was stolen from git-pull.sh ;-)
Doesn't that suggest it might belong in some common git-upstream--lib.sh
(or git-sh-setup.sh)?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] rebase: use @{upstream} if no upstream specified
2011-02-08 22:05 ` Jonathan Nieder
@ 2011-02-09 0:28 ` Martin von Zweigbergk
2011-02-09 1:50 ` Martin von Zweigbergk
0 siblings, 1 reply; 12+ messages in thread
From: Martin von Zweigbergk @ 2011-02-09 0:28 UTC (permalink / raw)
To: Jonathan Nieder
Cc: Martin von Zweigbergk, Sverre Rabbelier, git, Junio C Hamano,
Yann Dirson
On Tue, 8 Feb 2011, Jonathan Nieder wrote:
> Martin von Zweigbergk wrote:
> > On Tue, 8 Feb 2011, Sverre Rabbelier wrote:
>
> >> I particularly like that you explain to the user clearly what they
> >> have to do to make this work (e.g., configure the upstream). Nice.
> >
> > Thanks, but that was stolen from git-pull.sh ;-)
>
> Doesn't that suggest it might belong in some common git-upstream--lib.sh
> (or git-sh-setup.sh)?
Maybe it does... For comparison, I pasted the two sections below.
git-rebase.sh (after my patch):
if test -z "$branch_name"
then
die "You are not currently on a branch, so I cannot use any
'branch.<branchname>.merge' in your configuration file.
Please specify which upstream branch you want to use on the command
line and try again (e.g. 'git rebase <upstream branch>').
See git-rebase(1) for details."
else
die "You asked me to rebase without telling me which branch you
want to rebase against, and 'branch.${branch_name#refs/heads/}.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git rebase <upstream branch>').
See git-rebase(1) for details."
fi
git-pull.sh:
elif [ -z "$curr_branch" ]; then
echo "You are not currently on a branch, so I cannot use any"
echo "'branch.<branchname>.merge' in your configuration file."
echo "Please specify which remote branch you want to use on the command"
echo "line and try again (e.g. 'git pull <repository> <refspec>')."
echo "See git-pull(1) for details."
elif [ -z "$upstream" ]; then
echo "You asked me to pull without telling me which branch you"
echo "want to $op_type $op_prep, and 'branch.${curr_branch}.merge' in"
echo "your configuration file does not tell me, either. Please"
echo "specify which branch you want to use on the command line and"
echo "try again (e.g. 'git pull <repository> <refspec>')."
echo "See git-pull(1) for details."
echo
echo "If you often $op_type $op_prep the same branch, you may want to"
echo "use something like the following in your configuration file:"
echo
echo " [branch \"${curr_branch}\"]"
echo " remote = <nickname>"
echo " merge = <remote-ref>"
test rebase = "$op_type" &&
echo " rebase = true"
echo
echo " [remote \"<nickname>\"]"
echo " url = <url>"
echo " fetch = <refspec>"
echo
echo "See git-config(1) for details."
I had forgotten that I trimmed the last part of it. Maybe I should
have also included that? Then it would make even more sense to extract
this piece of code.
/Martin
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] rebase: use @{upstream} if no upstream specified
2011-02-09 0:28 ` Martin von Zweigbergk
@ 2011-02-09 1:50 ` Martin von Zweigbergk
2011-02-09 4:17 ` Jonathan Nieder
0 siblings, 1 reply; 12+ messages in thread
From: Martin von Zweigbergk @ 2011-02-09 1:50 UTC (permalink / raw)
To: Martin von Zweigbergk
Cc: Jonathan Nieder, Sverre Rabbelier, git, Junio C Hamano,
Yann Dirson
On Tue, 8 Feb 2011, Martin von Zweigbergk wrote:
> On Tue, 8 Feb 2011, Jonathan Nieder wrote:
>
> > Martin von Zweigbergk wrote:
> > > On Tue, 8 Feb 2011, Sverre Rabbelier wrote:
> >
> > >> I particularly like that you explain to the user clearly what they
> > >> have to do to make this work (e.g., configure the upstream). Nice.
> > >
> > > Thanks, but that was stolen from git-pull.sh ;-)
> >
> > Doesn't that suggest it might belong in some common git-upstream--lib.sh
> > (or git-sh-setup.sh)?
>
> Maybe it does...
Maybe something like this on top? I put it in git-parse-remote.sh for
now. There were some related functions there, so maybe it's not so
bad. Should I put it there (and rename to git-upstream--lib.sh?), in
new git-upstream--lib.sh or in git-sh-setup.sh.
Changes to the text compared to before:
* "remote branch" became "upstream branch", even for git pull
* "You asked me to pull" became "You asked me to merge" or "You asked
me to rebase", even for git pull
* Now printed to stderr, because I simply didn't think about it. Good
or bad?
What do you think?
-- 8< --
diff --git a/git-parse-remote.sh b/git-parse-remote.sh
index 1cc2ba6..ff58d5b 100644
--- a/git-parse-remote.sh
+++ b/git-parse-remote.sh
@@ -99,3 +99,40 @@ get_remote_merge_branch () {
esac
esac
}
+
+error_on_missing_default_upstream () {
+ op_type="$1"
+ op_prep="$2"
+ example="$3"
+ documentation="$4"
+ branch_name=$(git symbolic-ref -q HEAD)
+ if test -z "$branch_name"
+ then
+ die "You are not currently on a branch, so I cannot use any
+'branch.<branchname>.merge' in your configuration file.
+Please specify which upstream branch you want to use on the command
+line and try again (e.g. '$example').
+See $documentation for details."
+ else
+ echo &2> "You asked me to $op_type without telling me which branch you
+want to $op_type $op_prep, and 'branch.${branch_name#refs/heads/}.merge' in
+your configuration file does not tell me, either. Please
+specify which branch you want to use on the command line and
+try again (e.g. '$example').
+See $documentation for details.
+
+If you often $op_type $op_prep the same branch, you may want to
+use something like the following in your configuration file:
+ [branch \"${branch_name#refs/heads/}\"]
+ remote = <nickname>
+ merge = <remote-ref>"
+ test rebase = "$op_type" &&
+ echo &2> " rebase = true"
+ die "
+ [remote \"<nickname>\"]
+ url = <url>
+ fetch = <refspec>
+
+See git-config(1) for details."
+ fi
+}
diff --git a/git-pull.sh b/git-pull.sh
index eb87f49..8ec1d3d 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -163,34 +163,10 @@ error_on_no_merge_candidates () {
echo "You asked to pull from the remote '$1', but did not specify"
echo "a branch. Because this is not the default configured remote"
echo "for your current branch, you must specify a branch on the command line."
- elif [ -z "$curr_branch" ]; then
- echo "You are not currently on a branch, so I cannot use any"
- echo "'branch.<branchname>.merge' in your configuration file."
- echo "Please specify which remote branch you want to use on the command"
- echo "line and try again (e.g. 'git pull <repository> <refspec>')."
- echo "See git-pull(1) for details."
- elif [ -z "$upstream" ]; then
- echo "You asked me to pull without telling me which branch you"
- echo "want to $op_type $op_prep, and 'branch.${curr_branch}.merge' in"
- echo "your configuration file does not tell me, either. Please"
- echo "specify which branch you want to use on the command line and"
- echo "try again (e.g. 'git pull <repository> <refspec>')."
- echo "See git-pull(1) for details."
- echo
- echo "If you often $op_type $op_prep the same branch, you may want to"
- echo "use something like the following in your configuration file:"
- echo
- echo " [branch \"${curr_branch}\"]"
- echo " remote = <nickname>"
- echo " merge = <remote-ref>"
- test rebase = "$op_type" &&
- echo " rebase = true"
- echo
- echo " [remote \"<nickname>\"]"
- echo " url = <url>"
- echo " fetch = <refspec>"
- echo
- echo "See git-config(1) for details."
+ elif [ -z "$curr_branch" -o -z "$upstream" ]; then
+ . git-parse-remote
+ error_on_missing_default_upstream $op_type $op_prep \
+ "git pull <repository> <refspec>" "git-pull(1)"
else
echo "Your configuration specifies to $op_type $op_prep the ref '${upstream#refs/heads/}'"
echo "from the remote, but no such ref was fetched."
diff --git a/git-rebase.sh b/git-rebase.sh
index 5975642..8b39cab 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -144,25 +144,6 @@ run_pre_rebase_hook () {
fi
}
-error_on_missing_default_upstream () {
- branch_name=$(git symbolic-ref -q HEAD)
- if test -z "$branch_name"
- then
- die "You are not currently on a branch, so I cannot use any
-'branch.<branchname>.merge' in your configuration file.
-Please specify which upstream branch you want to use on the command
-line and try again (e.g. 'git rebase <upstream branch>').
-See git-rebase(1) for details."
- else
- die "You asked me to rebase without telling me which branch you
-want to rebase against, and 'branch.${branch_name#refs/heads/}.merge' in
-your configuration file does not tell me, either. Please
-specify which branch you want to use on the command line and
-try again (e.g. 'git rebase <upstream branch>').
-See git-rebase(1) for details."
- fi
-}
-
test -f "$apply_dir"/applying &&
die 'It looks like git-am is in progress. Cannot rebase.'
@@ -381,8 +362,13 @@ if test -z "$rebase_root"
then
case "$#" in
0)
- upstream_name=$(git rev-parse --symbolic-full-name --verify -q \
- @{upstream}) || error_on_missing_default_upstream
+ if ! upstream_name=$(git rev-parse --symbolic-full-name \
+ --verify -q @{upstream})
+ then
+ . git-parse-remote
+ error_on_missing_default_upstream "rebase" "against" \
+ "git rebase <upstream branch>" "git-rebase(1)"
+ fi
;;
*) upstream_name="$1"
shift
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH] rebase: use @{upstream} if no upstream specified
2011-02-09 1:50 ` Martin von Zweigbergk
@ 2011-02-09 4:17 ` Jonathan Nieder
2011-02-10 1:15 ` Martin von Zweigbergk
0 siblings, 1 reply; 12+ messages in thread
From: Jonathan Nieder @ 2011-02-09 4:17 UTC (permalink / raw)
To: Martin von Zweigbergk; +Cc: Sverre Rabbelier, git, Junio C Hamano, Yann Dirson
Martin von Zweigbergk wrote:
> Maybe something like this on top? I put it in git-parse-remote.sh for
> now.
Thanks. That sounds like a good place.
> Changes to the text compared to before:
>
> * "remote branch" became "upstream branch", even for git pull
Sensible for pull --rebase. I'm not so sure about plain pull --- what
if I am upstream and pulling from downstream?
> * "You asked me to pull" became "You asked me to merge" or "You asked
> me to rebase", even for git pull
"To pull" would be clearer if the reader is new and unfamiliar with
the details.
> * Now printed to stderr, because I simply didn't think about it. Good
> or bad?
If this were a new message, I'd say stderr is better.
As is, the change to stderr seems relatively harmless, though I haven't
thought about it deeply. But a part of me likes to see functional
changes isolated in separate commits to make tracking down bugs a
little easier.
Hope that helps,
Jonathan
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] rebase: use @{upstream} if no upstream specified
2011-02-09 4:17 ` Jonathan Nieder
@ 2011-02-10 1:15 ` Martin von Zweigbergk
0 siblings, 0 replies; 12+ messages in thread
From: Martin von Zweigbergk @ 2011-02-10 1:15 UTC (permalink / raw)
To: Jonathan Nieder
Cc: Martin von Zweigbergk, Sverre Rabbelier, git, Junio C Hamano,
Yann Dirson
On Tue, 8 Feb 2011, Jonathan Nieder wrote:
> Martin von Zweigbergk wrote:
>
> > Changes to the text compared to before:
> >
> > * "remote branch" became "upstream branch", even for git pull
>
> Sensible for pull --rebase. I'm not so sure about plain pull --- what
> if I am upstream and pulling from downstream?
>
> > * "You asked me to pull" became "You asked me to merge" or "You asked
> > me to rebase", even for git pull
>
> "To pull" would be clearer if the reader is new and unfamiliar with
> the details.
>
> > * Now printed to stderr, because I simply didn't think about it. Good
> > or bad?
>
> If this were a new message, I'd say stderr is better.
>
> As is, the change to stderr seems relatively harmless, though I haven't
> thought about it deeply. But a part of me likes to see functional
> changes isolated in separate commits to make tracking down bugs a
> little easier.
The patch below should address all of the above. See how you like the
new wording. The patch applies on top of the previous one to make the
changes clear. I will send a re-roll with all three patches squashed
soon as well.
Note that this patch makes the test cases introduced in the original
patch fail because of the error messages from 'git rebase' are now
written to stdout. I will of course fix that in the re-roll.
Thanks for reviewing.
/Martin
-- 8< --
diff --git a/git-parse-remote.sh b/git-parse-remote.sh
index ff58d5b..be17ecb 100644
--- a/git-parse-remote.sh
+++ b/git-parse-remote.sh
@@ -101,25 +101,25 @@ get_remote_merge_branch () {
}
error_on_missing_default_upstream () {
- op_type="$1"
- op_prep="$2"
- example="$3"
- documentation="$4"
+ cmd="$1"
+ op_type="$2"
+ op_prep="$3"
+ example="$4"
branch_name=$(git symbolic-ref -q HEAD)
if test -z "$branch_name"
then
- die "You are not currently on a branch, so I cannot use any
+ echo "You are not currently on a branch, so I cannot use any
'branch.<branchname>.merge' in your configuration file.
-Please specify which upstream branch you want to use on the command
+Please specify which branch you want to $op_type $op_prep on the command
line and try again (e.g. '$example').
-See $documentation for details."
+See git-${cmd}(1) for details."
else
- echo &2> "You asked me to $op_type without telling me which branch you
+ echo "You asked me to $cmd without telling me which branch you
want to $op_type $op_prep, and 'branch.${branch_name#refs/heads/}.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. '$example').
-See $documentation for details.
+See git-${cmd}(1) for details.
If you often $op_type $op_prep the same branch, you may want to
use something like the following in your configuration file:
@@ -127,12 +127,13 @@ use something like the following in your configuration file:
remote = <nickname>
merge = <remote-ref>"
test rebase = "$op_type" &&
- echo &2> " rebase = true"
- die "
+ echo " rebase = true"
+ echo "
[remote \"<nickname>\"]
url = <url>
fetch = <refspec>
See git-config(1) for details."
fi
+ exit 1
}
diff --git a/git-pull.sh b/git-pull.sh
index 8ec1d3d..2cdea26 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -165,8 +165,8 @@ error_on_no_merge_candidates () {
echo "for your current branch, you must specify a branch on the command line."
elif [ -z "$curr_branch" -o -z "$upstream" ]; then
. git-parse-remote
- error_on_missing_default_upstream $op_type $op_prep \
- "git pull <repository> <refspec>" "git-pull(1)"
+ error_on_missing_default_upstream "pull" $op_type $op_prep \
+ "git pull <repository> <refspec>"
else
echo "Your configuration specifies to $op_type $op_prep the ref '${upstream#refs/heads/}'"
echo "from the remote, but no such ref was fetched."
diff --git a/git-rebase.sh b/git-rebase.sh
index 8b39cab..cff7aaa 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -366,8 +366,8 @@ then
--verify -q @{upstream})
then
. git-parse-remote
- error_on_missing_default_upstream "rebase" "against" \
- "git rebase <upstream branch>" "git-rebase(1)"
+ error_on_missing_default_upstream "rebase" "rebase" \
+ "against" "git rebase <upstream branch>"
fi
;;
*) upstream_name="$1"
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH] rebase: use @{upstream} if no upstream specified
2011-02-08 0:37 [PATCH] rebase: use @{upstream} if no upstream specified Martin von Zweigbergk
2011-02-08 17:46 ` Sverre Rabbelier
@ 2011-02-10 1:54 ` Martin von Zweigbergk
2011-02-10 2:25 ` Junio C Hamano
1 sibling, 1 reply; 12+ messages in thread
From: Martin von Zweigbergk @ 2011-02-10 1:54 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Yann Dirson, Jonathan Nieder, Sverre Rabbelier,
Martin von Zweigbergk
'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 <ydirson@altern.org>
Helped-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
Changes since v1:
* Extracted error reporting shared with git-pull.sh as suggested by
Jonathan.
* Now discards stderr from "git rev-parse -q @{upstream}", since it's
not quite quiet when there is no upstream.
Documentation/config.txt | 2 +-
Documentation/git-rebase.txt | 11 +++++++++--
git-parse-remote.sh | 38 ++++++++++++++++++++++++++++++++++++++
git-pull.sh | 32 ++++----------------------------
git-rebase.sh | 21 +++++++++++++++------
t/t3400-rebase.sh | 27 ++++++++++++++++++---------
6 files changed, 85 insertions(+), 46 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index c5e1835..b4e65b8 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -646,7 +646,7 @@ branch.<name>.remote::
branch.<name>.merge::
Defines, together with branch.<name>.remote, the upstream branch
- for the given branch. It tells 'git fetch'/'git pull' which
+ for the given branch. It tells 'git fetch'/'git pull'/'git rebase' which
branch to merge and can also affect 'git push' (see push.default).
When in branch <name>, it tells 'git fetch' the default
refspec to be marked for merging in FETCH_HEAD. The value is
diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 96680c8..d3e998d 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -9,7 +9,7 @@ SYNOPSIS
--------
[verse]
'git rebase' [-i | --interactive] [options] [--onto <newbase>]
- <upstream> [<branch>]
+ [<upstream>] [<branch>]
'git rebase' [-i | --interactive] [options] --onto <newbase>
--root [<branch>]
@@ -21,6 +21,12 @@ If <branch> is specified, 'git rebase' will perform an automatic
`git checkout <branch>` before doing anything else. Otherwise
it remains on the current branch.
+If <upstream> is not specified, the upstream configured in
+branch.<name>.remote and branch.<name>.merge options will be used; see
+linkgit:git-config[1] for details. If you are currently not on any
+branch or if the current branch does not have a configured upstream,
+the rebase will abort.
+
All changes made by commits in the current branch but that are not
in <upstream> are saved to a temporary area. This is the same set
of commits that would be shown by `git log <upstream>..HEAD` (or
@@ -216,7 +222,8 @@ leave out at most one of A and B, in which case it defaults to HEAD.
<upstream>::
Upstream branch to compare against. May be any valid commit,
- not just an existing branch name.
+ not just an existing branch name. Defaults to the configured
+ upstream for the current branch.
<branch>::
Working branch; defaults to HEAD.
diff --git a/git-parse-remote.sh b/git-parse-remote.sh
index 1cc2ba6..be17ecb 100644
--- a/git-parse-remote.sh
+++ b/git-parse-remote.sh
@@ -99,3 +99,41 @@ get_remote_merge_branch () {
esac
esac
}
+
+error_on_missing_default_upstream () {
+ cmd="$1"
+ op_type="$2"
+ op_prep="$3"
+ example="$4"
+ branch_name=$(git symbolic-ref -q HEAD)
+ if test -z "$branch_name"
+ then
+ echo "You are not currently on a branch, so I cannot use any
+'branch.<branchname>.merge' in your configuration file.
+Please specify which branch you want to $op_type $op_prep on the command
+line and try again (e.g. '$example').
+See git-${cmd}(1) for details."
+ else
+ echo "You asked me to $cmd without telling me which branch you
+want to $op_type $op_prep, and 'branch.${branch_name#refs/heads/}.merge' in
+your configuration file does not tell me, either. Please
+specify which branch you want to use on the command line and
+try again (e.g. '$example').
+See git-${cmd}(1) for details.
+
+If you often $op_type $op_prep the same branch, you may want to
+use something like the following in your configuration file:
+ [branch \"${branch_name#refs/heads/}\"]
+ remote = <nickname>
+ merge = <remote-ref>"
+ test rebase = "$op_type" &&
+ echo " rebase = true"
+ echo "
+ [remote \"<nickname>\"]
+ url = <url>
+ fetch = <refspec>
+
+See git-config(1) for details."
+ fi
+ exit 1
+}
diff --git a/git-pull.sh b/git-pull.sh
index eb87f49..2cdea26 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -163,34 +163,10 @@ error_on_no_merge_candidates () {
echo "You asked to pull from the remote '$1', but did not specify"
echo "a branch. Because this is not the default configured remote"
echo "for your current branch, you must specify a branch on the command line."
- elif [ -z "$curr_branch" ]; then
- echo "You are not currently on a branch, so I cannot use any"
- echo "'branch.<branchname>.merge' in your configuration file."
- echo "Please specify which remote branch you want to use on the command"
- echo "line and try again (e.g. 'git pull <repository> <refspec>')."
- echo "See git-pull(1) for details."
- elif [ -z "$upstream" ]; then
- echo "You asked me to pull without telling me which branch you"
- echo "want to $op_type $op_prep, and 'branch.${curr_branch}.merge' in"
- echo "your configuration file does not tell me, either. Please"
- echo "specify which branch you want to use on the command line and"
- echo "try again (e.g. 'git pull <repository> <refspec>')."
- echo "See git-pull(1) for details."
- echo
- echo "If you often $op_type $op_prep the same branch, you may want to"
- echo "use something like the following in your configuration file:"
- echo
- echo " [branch \"${curr_branch}\"]"
- echo " remote = <nickname>"
- echo " merge = <remote-ref>"
- test rebase = "$op_type" &&
- echo " rebase = true"
- echo
- echo " [remote \"<nickname>\"]"
- echo " url = <url>"
- echo " fetch = <refspec>"
- echo
- echo "See git-config(1) for details."
+ elif [ -z "$curr_branch" -o -z "$upstream" ]; then
+ . git-parse-remote
+ error_on_missing_default_upstream "pull" $op_type $op_prep \
+ "git pull <repository> <refspec>"
else
echo "Your configuration specifies to $op_type $op_prep the ref '${upstream#refs/heads/}'"
echo "from the remote, but no such ref was fetched."
diff --git a/git-rebase.sh b/git-rebase.sh
index be9ec2a..a040ab5 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 <newbase>] (<upstream>|--root) [<branch>] [--quiet | -q]'
+USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--no-ff] [--onto <newbase>] [<upstream>|--root] [<branch>] [--quiet | -q]'
LONG_USAGE='git-rebase replaces <branch> with a new branch of the
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>
@@ -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 <upstream branch>"
+ fi
+ ;;
+ *) upstream_name="$1"
+ shift
+ ;;
+ esac
upstream=`git rev-parse --verify "${upstream_name}^0"` ||
die "invalid upstream $upstream_name"
upstream_arg="$upstream_name"
diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
index 349eebd..6eaecec 100755
--- a/t/t3400-rebase.sh
+++ b/t/t3400-rebase.sh
@@ -158,15 +158,24 @@ test_expect_success 'Show verbose error when HEAD could not be detached' '
'
rm -f B
-test_expect_success 'dump usage when upstream arg is missing' '
- git checkout -b usage topic &&
- test_must_fail git rebase 2>error1 &&
- grep "[Uu]sage" error1 &&
- test_must_fail git rebase --abort 2>error2 &&
- grep "No rebase in progress" error2 &&
- test_must_fail git rebase --onto master 2>error3 &&
- grep "[Uu]sage" error3 &&
- ! grep "can.t shift" error3
+test_expect_success 'fail when upstream arg is missing and not on branch' '
+ git checkout topic &&
+ test_must_fail git rebase >output.out &&
+ grep "You are not currently on a branch" output.out
+'
+
+test_expect_success 'fail when upstream arg is missing and not configured' '
+ git checkout -b no-config topic &&
+ test_must_fail git rebase >output.out &&
+ grep "branch.no-config.merge" output.out
+'
+
+test_expect_success 'default to @{upstream} when upstream arg is missing' '
+ git checkout -b default topic &&
+ git config branch.default.remote .
+ git config branch.default.merge refs/heads/master
+ git rebase &&
+ test "$(git rev-parse default~1)" = "$(git rev-parse master)"
'
test_expect_success 'rebase -q is quiet' '
--
1.7.4.rc2.33.g8a14f
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH] rebase: use @{upstream} if no upstream specified
2011-02-10 1:54 ` Martin von Zweigbergk
@ 2011-02-10 2:25 ` Junio C Hamano
2011-02-10 2:46 ` Martin von Zweigbergk
0 siblings, 1 reply; 12+ messages in thread
From: Junio C Hamano @ 2011-02-10 2:25 UTC (permalink / raw)
To: Martin von Zweigbergk; +Cc: git, Yann Dirson, Jonathan Nieder, Sverre Rabbelier
Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> writes:
> '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.
Not that I am fundamentally opposed to the proposed change, but the above is
not a very convincing argument, when the corresponding change to "git merge"
is just started getting discussed.
On top of what commit does this patch apply, by the way?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] rebase: use @{upstream} if no upstream specified
2011-02-10 2:25 ` Junio C Hamano
@ 2011-02-10 2:46 ` Martin von Zweigbergk
0 siblings, 0 replies; 12+ messages in thread
From: Martin von Zweigbergk @ 2011-02-10 2:46 UTC (permalink / raw)
To: Junio C Hamano
Cc: Martin von Zweigbergk, git, Yann Dirson, Jonathan Nieder,
Sverre Rabbelier
On Wed, 9 Feb 2011, Junio C Hamano wrote:
> Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> writes:
>
> > '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.
>
> Not that I am fundamentally opposed to the proposed change, but the above is
> not a very convincing argument, when the corresponding change to "git merge"
> is just started getting discussed.
There was a little more motivation later in the commit message, like
using it with 'git rebase -i'. I have been using it for a few months
now, and I also find it quite useful e.g. when rebasing all my
branches on top of your master.
>
> On top of what commit does this patch apply, by the way?
On top of the rebase refactoring series I posted a few days ago. See
http://thread.gmane.org/gmane.comp.version-control.git/166161/.
/Martin
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2011-02-10 2:46 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-08 0:37 [PATCH] rebase: use @{upstream} if no upstream specified Martin von Zweigbergk
2011-02-08 17:46 ` Sverre Rabbelier
2011-02-08 18:23 ` Martin von Zweigbergk
2011-02-08 18:27 ` Sverre Rabbelier
2011-02-08 22:05 ` Jonathan Nieder
2011-02-09 0:28 ` Martin von Zweigbergk
2011-02-09 1:50 ` Martin von Zweigbergk
2011-02-09 4:17 ` Jonathan Nieder
2011-02-10 1:15 ` Martin von Zweigbergk
2011-02-10 1:54 ` Martin von Zweigbergk
2011-02-10 2:25 ` Junio C Hamano
2011-02-10 2:46 ` Martin von Zweigbergk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).