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

Re: git-check-ref-format returns 1 for valid branch names

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Mar 22, 2007, 21:03 UTC
Message-ID
<Pine.LNX.4.64.0703221358420.6730@woody.linux-foundation.org>
In-Reply-To
<7vejnht3x2.fsf@assigned-by-dhcp.cox.net>
On Thu, 22 Mar 2007, Junio C Hamano wrote:
Show 11 quoted lines
> "Nikolai Weibull" <now@bitwi.se> writes:
> 
> > I'm obviously doing something wrong, but in git 1.5.0.4
> >
> > % git check-ref-format abc
> > % echo $?
> > 1
> >
> > What am I missing here?
> 
> If you are trying to see if abc is a valid branch name, try refs/heads/abc.

.. and before anybody wonders why it wants the "fully qualified" name, it's because "abc" on its own is ambiguous. Is it a _tag_ called "abc", or a branch, or what? That explains why - if you really want to verify a ref-name, you need to give the full name..

On the other hand, if you don't care, and you just want "is this a valid commit name", use

	sha1=$(git rev-parse --verify "$name"^0) || exit

or similar. It won't care if "name" is ambiguous or not, it will just try to parse it as a revision expression (with the "^0" there to force a tag to be converted to a commit-name, or force an error if the SHA1 is not a valid commit).

			Linus
Previous: Nikolai WeibullNext: Nikolai Weibull
Message 4 of 5 in “git-check-ref-format returns 1 for valid branch names”
  1. Nikolai WeibullMar 22, 2007
  2. Junio C HamanoMar 22, 2007
  3. Nikolai WeibullMar 22, 2007
  4. Linus TorvaldsMar 22, 2007
  5. Nikolai WeibullMar 22, 2007

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.