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

Re: specifying revision - how to enforce matching a tag/branch-name or revision only

From
Duy Nguyen <pclouds@gmail.com>
Date
Jun 25, 2019, 11:43 UTC
Message-ID
<CACsJy8CBQhF2=nZ4tZj_h6Gr8PjK3amANjT38uhnurS0dehyiQ@mail.gmail.com>
In-Reply-To
<xmqq8stvklzd.fsf@gitster-ct.c.googlers.com>
On Fri, Jun 21, 2019 at 10:16 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 7 quoted lines
>
> Kyle Meyer <kyle@kyleam.com> writes:
>
> >> git rev-parse "${BRANCH_NAME}"  || git rev-parse "refs/remotes/${UPSTREAM}/${BRANCH_NAME}"
> >>
> >> Unfortunately somebody used the branch name "add-gcc10" and `git rev-parse` which didn't exist on one repository. However `git rev-parse`
> >> also supports to parse the `git-describe` format which resulted in checkout a commit starting with "cc10".

I wonder if something like refs/heads/foo-g<hash> could trip the parser and mistake it as a `git-describe` output. Staring at get_describe_name() alone the answer might be an unfortunate "yes". But maybe something will kick in earlier and reject it.

> >
> > Can't you prepend "refs/heads/" to BRANCH_NAME to disambiguate?
>
> Yes, that is the kosher way for most commands.

Some commands always prepend refs/heads/ to the <branch> argument you give it if I remember correctly. Or I think I accidentally made refs/heads/refs/heads/something once with some command (then hell ensued). If true, prepending refs/heads/ is not really foolproof.

Show 6 quoted lines
> It gets a bit tricky for "checkout <branch-or-committish>" that
> changes its behaviour (a local branch is checked out and the next
> commit extends it, other committishes like tags and remote-tracking
> branch tips are checked out on a detached HEAD), and has special
> rules for a "${BRANCH_NAME}" that is both the name of a local branch
> and something else.

I think "git checkout --no-guess --no-detach <branch>" should only accept a branch (i.e. ref: refs/heads/<branch>). Dropping --no-detach should allow any ref, which interprets refs/heads/foo as an absolute ref, not as refs/heads/refs/heads/foo.

> Hopefully (Duy Cc'ed) "git switch" would improve the situation.

"git switch" has slightly saner defaults, but with --guess being default to be friendlier to interactive usage, it's still not that much friendlier to scripts, unfortunately.

-- 
Duy
Previous: Junio C HamanoNext: Boettger, Heiko
Message 4 of 11 in “specifying revision - how to enforce matching a tag/branch-name or revision only”
  1. Boettger, HeikoJun 20, 2019
  2. Kyle MeyerJun 20, 2019
  3. Junio C HamanoJun 21, 2019
  4. Duy NguyenJun 25, 2019
  5. AW: specifying revision - how to enforce matching a tag/branch-name or revision onlyBoettger, Heiko, Jun 25, 2019
  6. get_oid: new extended SHA-1 syntax to control resolution processNguyễn Thái Ngọc Duy, Jun 26, 2019
  7. Junio C HamanoJun 26, 2019
  8. Duy NguyenJun 27, 2019
  9. Junio C HamanoJun 27, 2019
  10. Jakub NarebskiJun 30, 2019
  11. Duy NguyenJul 1, 2019

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.