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

Re: Bug: Git sees branch as valid commit ref and works; should fail

From
MTMatt Thompson <fortran@gmail.com>
Date
Aug 5, 2024, 16:58 UTC
Message-ID
<CAFb48S8+X0=Zqi8oisB0fAgx7HoyQrahF-RGQdagXTX3RdfSNQ@mail.gmail.com>
In-Reply-To
<xmqqy15b2aiz.fsf@gitster.g>
Well, I tried the "for-each-ref" command and:

$ git for-each-ref | grep /bugfix/mathomp4/trivial-ci-commit-gcc14 $ echo $? 1

Indeed, if I try a few other greps, there are no "trivial" or "gcc14":

$ git for-each-ref | grep -i gcc14 $ echo $? 1 $ git for-each-ref | grep -i trivial $ echo $? 1

But, I did some experimenting and I found that "ci-gcc14" does trigger...something:

$ git for-each-ref | grep -i ci-gcc14 mathomp4@gslwl2023080107 ~/GitBugReport/fvdycore geos/main $ echo $? 0

But I'm confused as to how the grep returned a status of 0 but didn't print anything? So it said "Yes I see this string" but it actually didn't? And it can switch to it:

$ git switch ci-gcc14 fatal: a branch is expected, got commit 'ci-gcc14' hint: If you want to detach HEAD at the commit, try again with the --detach option. mathomp4@gslwl2023080107 ~/GitBugReport/fvdycore geos/main $ git switch --detach ci-gcc14 HEAD is now at cc14d30 removed an unused module use in fv_sg

On Mon, Aug 5, 2024 at 12:35 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 39 quoted lines
>
> Matt Thompson <fortran@gmail.com> writes:
>
> > Thank you for filling out a Git bug report!
> > Please answer the following questions to help us understand your issue.
> >
> > What did you do before the bug happened? (Steps to reproduce your issue)
> >
> > $ git clone https://github.com/GEOS-ESM/GFDL_atmos_cubed_sphere.git fvdycore
> > $ cd fvdycore
> > $ git checkout bugfix/mathomp4/trivial-ci-commit-gcc14
> >
> > What did you expect to happen? (Expected behavior)
> >
> > I expected a failure as there is no branch named
> > 'bugfix/mathomp4/trivial-ci-commit-gcc14' in the repository.
>
> If you run
>
>   $ git for-each-ref | grep /bugfix/mathomp4/trivial-ci-commit-gcc14
>
> I suspect you have a remote-tracking branch that matches the
> pattern.  In such a case, "bugfix/mathomp4/trivial-ci-commit-gcc14"
> is a very valid way to refer to a commit to any Git command.  It is
> handy to say "git show bugfix/mathomp4/trivial-ci-commit-gcc14", for
> example.
>
> And when "git checkout" is given a commit that is not a local
> branch, what it did below (by the way, thanks for giving a very
> accurate "Actual behavior" description in your report) is very much
> expected behaviour, including the part that it gave a message to
> advise how to work on a detached HEAD.
>
> > What happened instead? (Actual behavior)
> >
> > $ git checkout bugfix/mathomp4/trivial-ci-commit-gcc14
> > Note: switching to 'bugfix/mathomp4/trivial-ci-commit-gcc14'.
> > ...
>
-- 
Matt Thompson
   “The fact is, this is about us identifying what we do best and
   finding more ways of doing less of it better” -- Director of Better
Anna Rampton
Previous: Junio C HamanoNext: Jeff King
Message 3 of 7 in “Bug: Git sees branch as valid commit ref and works; should fail”
  1. Matt ThompsonAug 5, 2024
  2. Junio C HamanoAug 5, 2024
  3. Matt ThompsonAug 5, 2024
  4. Jeff KingAug 13, 2024
  5. get_oid(): enforce minimum length for "-g<hex>" namesJeff King, Aug 13, 2024
  6. Jeff KingAug 13, 2024
  7. Junio C HamanoAug 13, 2024

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.