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

Re: [PATCH] checkout: fix BUG() case in 9081a421a6

From
Todd Zullinger <tmz@pobox.com>
Date
Jan 21, 2022, 21:58 UTC
Message-ID
<YessbkNZlxLOTzBE@pobox.com>
In-Reply-To
<CABXw6YMztos7UYJn0LxKiWvZ_oy55mu+k__jABdXwAW0H3J0cA@mail.gmail.com>
Petr Šplíchal wrote:
> Thanks for explaining in detail what's wrong about the approach.

Yes, thank you Ævar and Junio for providing context and the thoughtful planning on how to fix this in both the short and long term.

Show 11 quoted lines
> We didn't know about the "HEAD must point at a local branch" rule
> and copying the ref seemed to be the easiest way to create a local
> branch pointing always to the latest content of the remote default
> branch. I described the use case here:
> 
>     https://bugzilla.redhat.com/show_bug.cgi?id=2042920#c2
> 
> Basically we just need to checkout and reset --hard to the default
> remote branch after entering a git repository while HEAD can be
> pointing anywhere. Could you suggest some more straightforward way
> to achieve this from a script? Thanks.

I'm nearly positive that I don't know the best way, but here's _a_ way to do it. It assumes the default remote name is origin, which seems less than ideal.

(Hopefully this isn't egregiously wrong. But if it is, I'm happy to serve as an example of how _not_ to do it for others.)

    git clone https://github.com/psss/fmf /tmp/fmf
    cd /tmp/fmf
    git switch -c custom-branch
    : work work work
    defbranch=$(git symbolic-ref --short refs/remotes/origin/HEAD)
    git switch -f ${defbranch#*/}
    git reset --hard @{u}

Odds are there's a better way to do this or to arrange things in a way that lets you solve an easier problem.

-- 
Todd
Previous: Petr ŠplíchalNext: Junio C Hamano
Message 8 of 16 in “[BUG] builtin/checkout.c:1098: should be able to skip past 'refs/heads/'”
  1. Todd ZullingerJan 20, 2022
  2. Todd ZullingerJan 20, 2022
  3. checkout: fix BUG() case in 9081a421a6Ævar Arnfjörð Bjarmason, Jan 20, 2022
  4. Junio C HamanoJan 20, 2022
  5. Junio C HamanoJan 20, 2022
  6. Ævar Arnfjörð BjarmasonJan 21, 2022
  7. Petr ŠplíchalJan 21, 2022
  8. Todd ZullingerJan 21, 2022
  9. Junio C HamanoJan 21, 2022
  10. Todd ZullingerJan 20, 2022
  11. Junio C HamanoJan 22, 2022
  12. Junio C HamanoJan 22, 2022
  13. checkout: avoid BUG() when hitting a broken repositoryJunio C Hamano, Jan 22, 2022
  14. Johannes SixtJan 22, 2022
  15. Ævar Arnfjörð BjarmasonJan 22, 2022
  16. Johannes SchindelinJan 23, 2022

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.