All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leszek Swirski <leszeks@google.com>
To: git@vger.kernel.org
Subject: Bug: git checkout @{u} breaks git branch if the upstream isn't a local branch
Date: Thu, 21 Mar 2019 16:43:01 +0100	[thread overview]
Message-ID: <CAGRskv__Qe-F-grBtq5v-uhHE+BQAcAcOQtX-GKB+MNOrxs0hQ@mail.gmail.com> (raw)

Consider a repository with branch master, with upstream origin/master.
If one is on master, and runs "git checkout @{u}" to get the upstream,
then git branch stops working. The reason is that we end up on a
detached HEAD, and git branch searches recent reflog entries to figure
out where the HEAD was detached from (wt-status.c:
wt_status_get_detached_from). Since @{u} is not a local branch, the
checkout is inserted into the reflog as "moving from master to @{u}"
rather than "moving from master to origin/master". This is because
setup_branch_path (checkout.c) only updates the branch name for local
branches, keeping the input name (here, "@{u}") otherwise. So, git
branch sees "@{u}", decides that we are detached from "@{u}", tries to
lookup "HEAD@{u}" and fails with "fatal: HEAD does not point to a
branch"

I assume that either the reflog entry should be amended to print
something more informative (moving from master to origin/master, or at
least master@{u}, or the SHA...), or the reflog search in
wt_status_get_detached_from should do something cleverer with relative
refs.

- Leszek

             reply	other threads:[~2019-03-21 15:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-21 15:43 Leszek Swirski [this message]
2019-03-22  5:02 ` Bug: git checkout @{u} breaks git branch if the upstream isn't a local branch Junio C Hamano

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=CAGRskv__Qe-F-grBtq5v-uhHE+BQAcAcOQtX-GKB+MNOrxs0hQ@mail.gmail.com \
    --to=leszeks@google.com \
    --cc=git@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.