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

Re: check_refname_format allows refs with components that begin with -, even though `git tag` does not

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 10, 2020, 20:09 UTC
Message-ID
<xmqqd00l6kj0.fsf@gitster.c.googlers.com>
In-Reply-To
<c926193b-a328-7562-6d4b-1ab2765c8cca@invisiblethingslab.com>
"Demi M. Obenour" <athena@invisiblethingslab.com> writes:
> If I try to create a Git tag with a name beginning with `-`,
> Git complains.  However, Git does not check that a repository does
> not have tags containing `-`.

This is quite deliberate. The command line parser of "git checkout" and friends long lacked way to say "switch to THAT BRANCH whose name begins with a hyphen" etc., and preventing tags and branches whose name begins with a hyphen from created at the Porcelain level was a way to stop users from hurting themselves.

These funny names are supported at the plumbing level primarily because we have historically allowed them and suddenly forbidding their use would break existing repository. A secondary reason is to have a way to learn the current value of and then remove them, so people with these funnily named branches and tags can "rename" them.

> This almost led to a vulnerability in the QubesOS `verify-git-tag`
> script.
Scripts need to be careful about their inputs, period.
> The best idea I had for a fix is to print names beginning with `-`
> using the fully-qualified form, such as "refs/tags/-a".  Also, `--`
> is used as a delimiter in many commands, and can’t be escaped,
> so disallowing it might be a good idea.
I do not think there is anything to fix.

Command line parsers of some commands may have to learn how to disambiguate such a strangely named tags and branches, though. Some commands do not know --end-of-options convention, for example.

Thanks.
[Further reading]

https://lore.kernel.org/git/7v62pjo4km.fsf@alter.siamese.dyndns.org/ https://lore.kernel.org/git/7vsk262vla.fsf@alter.siamese.dyndns.org/

Previous: Demi M. ObenourNext: Jeff King
Message 2 of 10 in “check_refname_format allows refs with components that begin with -, even though `git tag` does not”
  1. Demi M. ObenourNov 10, 2020
  2. Junio C HamanoNov 10, 2020
  3. Jeff KingNov 10, 2020
  4. 2/3 rev-parse: put all options under the "-" checkJeff King, Nov 10, 2020
  5. 1/3 rev-parse: don't accept options after dashdashJeff King, Nov 10, 2020
  6. 3/3 rev-parse: handle --end-of-optionsJeff King, Nov 10, 2020
  7. Junio C HamanoNov 10, 2020
  8. Demi M. ObenourNov 10, 2020
  9. Jeff KingNov 11, 2020
  10. Ævar Arnfjörð BjarmasonNov 10, 2020

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.