git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Bug: git checkout @{u} breaks git branch if the upstream isn't a local branch
@ 2019-03-21 15:43 Leszek Swirski
  2019-03-22  5:02 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Leszek Swirski @ 2019-03-21 15:43 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Bug: git checkout @{u} breaks git branch if the upstream isn't a local branch
  2019-03-21 15:43 Bug: git checkout @{u} breaks git branch if the upstream isn't a local branch Leszek Swirski
@ 2019-03-22  5:02 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2019-03-22  5:02 UTC (permalink / raw)
  To: Leszek Swirski; +Cc: git

Leszek Swirski <leszeks@google.com> writes:

> 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.

Nicely analyzed. A record "moving to @{u}" in the reflog may not
leave sufficient information for a later operation to tell what
branch was refered to with the @{u} reference back when "checkout"
was run.  I suspect that checking out @{4}, @{1.day.ago}, etc. may
share the same issue.

"git checkout @{-1}" aka "git checkout -" may not have any problem
after such a checkout, as it only uses "moving from" side of the
reflog entry.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-03-22  5:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-21 15:43 Bug: git checkout @{u} breaks git branch if the upstream isn't a local branch Leszek Swirski
2019-03-22  5:02 ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).