git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC] rebase: use @{upstream} if no upstream specified

From
Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
Date
Nov 17, 2010, 02:29 UTC
Message-ID
<AANLkTin+3FuuX_pavZQMrbi4qxjTRvM7nHk1PXcFbeiZ@mail.gmail.com>
In-Reply-To
<20101113095140.GH8911@home.lan>
On Sat, Nov 13, 2010 at 4:51 AM, Yann Dirson <ydirson@free.fr> wrote:
Show 12 quoted lines
> On Fri, Nov 12, 2010 at 09:55:49PM +0100, Martin von Zweigbergk wrote:
>
>> @@ -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.
Will do.
Show 41 quoted lines
>
>> @@ -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.
Will make sure to find out the error only when needed as you suggest.

I thought I would need the ref name to be able to walk the reflog if my other propasal would be accepted (see http://thread.gmane.org/gmane.comp.version-control.git/161381), but it seems to work with @{u} as well. I just adapted the call from 'git pull' (git-parse-remote.sh), but I guess I could use 'git rev-parse @{upstream}' instead. It does seem more natural to me.

Maybe one of the guys on the CC list can advise?
Previous: Yann DirsonNext: Jeff King
Message 3 of 11 in “[RFC] rebase: use @{upstream} if no upstream specified”
  1. Martin von ZweigbergkNov 12, 2010
  2. Yann DirsonNov 13, 2010
  3. Martin von ZweigbergkNov 17, 2010
  4. Jeff KingNov 19, 2010
  5. Martin von ZweigbergkNov 20, 2010
  6. Jeff KingNov 20, 2010
  7. Martin von ZweigbergkNov 20, 2010
  8. Kevin BallardNov 15, 2010
  9. Martin von ZweigbergkNov 15, 2010
  10. Jay SoffianNov 15, 2010
  11. Kevin BallardNov 15, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.