From: Yann Dirson <ydirson@free.fr>
To: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [RFC] rebase: use @{upstream} if no upstream specified
Date: Sat, 13 Nov 2010 10:51:40 +0100 [thread overview]
Message-ID: <20101113095140.GH8911@home.lan> (raw)
In-Reply-To: <1289595349-12589-1-git-send-email-martin.von.zweigbergk@gmail.com>
On Fri, Nov 12, 2010 at 09:55:49PM +0100, Martin von Zweigbergk wrote:
> With 'git pull --rebase', the user can configure the upstream repository
> to fetch from and reference to rebase against if none is specified on
> the command line.
>
> However, if, instead of 'git pull --rebase', the user were to do 'git
> fetch' followed by 'git rebase', the upstream branch would need to be
> specified on the command line. This patch teaches 'git rebase' to
> default to the same configured upstream ref as 'git pull --rebase'
> uses.
It is something I've meant to take a stake at since ages, cool!
Note that the same holds for "merge".
> The obvious extension would be to make @{u} the default for 'git merge'
> as well. Any opinions?
Hell, yes :)
> @@ -21,6 +21,10 @@ 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.
> +
Maybe make explicit that it will abort when no upstream is configured.
> @@ -416,9 +409,31 @@ esac
>
> if test -z "$rebase_root"
> then
> - # The upstream head must be given. Make sure it is valid.
> - upstream_name="$1"
> - shift
> + case "$#" in
> + 0) branch_name=$(git symbolic-ref -q HEAD) &&
> + upstream_name=$(git for-each-ref \
> + --format='%(upstream)' ${branch_name})
> + 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."
> + elif test -z $upstream_name
> + then
> + 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
> + ;;
> + *) upstream_name="$1"
> + shift
> + ;;
> + esac
> upstream=`git rev-parse --verify "${upstream_name}^0"` ||
> die "invalid upstream $upstream_name"
> unset root_flag
What about simply checking if "rev-parse @{u}" succeeds, in which case
we can use upstream_name=@{u} ? If it fails, then we can do the work
of finding where the config flaw is (and delegate this to a func).
That would help keep the nominal code path short.
--
Yann
next prev parent reply other threads:[~2010-11-13 9:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-12 20:55 [RFC] rebase: use @{upstream} if no upstream specified Martin von Zweigbergk
2010-11-13 9:51 ` Yann Dirson [this message]
2010-11-17 2:29 ` Martin von Zweigbergk
2010-11-19 21:15 ` Jeff King
2010-11-20 0:26 ` Martin von Zweigbergk
2010-11-20 4:10 ` Jeff King
2010-11-20 13:14 ` Martin von Zweigbergk
2010-11-15 22:48 ` Kevin Ballard
2010-11-15 23:06 ` Martin von Zweigbergk
2010-11-15 23:12 ` Jay Soffian
2010-11-15 23:16 ` Kevin Ballard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101113095140.GH8911@home.lan \
--to=ydirson@free.fr \
--cc=git@vger.kernel.org \
--cc=martin.von.zweigbergk@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).