From: Todd Zullinger <tmz@pobox.com>
To: "Petr Šplíchal" <psplicha@redhat.com>
Cc: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Junio C Hamano" <gitster@pobox.com>,
git@vger.kernel.org
Subject: Re: [PATCH] checkout: fix BUG() case in 9081a421a6
Date: Fri, 21 Jan 2022 16:58:06 -0500 [thread overview]
Message-ID: <YessbkNZlxLOTzBE@pobox.com> (raw)
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.
> 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
next prev parent reply other threads:[~2022-01-21 21:58 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-20 16:51 [BUG] builtin/checkout.c:1098: should be able to skip past 'refs/heads/' Todd Zullinger
2022-01-20 17:04 ` Todd Zullinger
2022-01-20 21:26 ` [PATCH] checkout: fix BUG() case in 9081a421a6 Ævar Arnfjörð Bjarmason
2022-01-20 22:29 ` Junio C Hamano
2022-01-20 22:33 ` Junio C Hamano
2022-01-21 11:14 ` Ævar Arnfjörð Bjarmason
2022-01-21 14:29 ` Petr Šplíchal
2022-01-21 21:58 ` Todd Zullinger [this message]
2022-01-21 21:19 ` Junio C Hamano
2022-01-20 22:33 ` Todd Zullinger
2022-01-22 0:33 ` Junio C Hamano
2022-01-22 0:45 ` Junio C Hamano
2022-01-22 0:58 ` [PATCH] checkout: avoid BUG() when hitting a broken repository Junio C Hamano
2022-01-22 8:10 ` Johannes Sixt
2022-01-22 11:55 ` Ævar Arnfjörð Bjarmason
2022-01-23 16:38 ` Johannes Schindelin
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=YessbkNZlxLOTzBE@pobox.com \
--to=tmz@pobox.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=psplicha@redhat.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).