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

Re: Exit code of git-ls-remote

From
Junio C Hamano <gitster@pobox.com>
Date
May 12, 2011, 16:21 UTC
Message-ID
<7voc37dh4l.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20110512120536.GA22033@camk.edu.pl>
Kacper Kornet <draenog@pld-linux.org> writes:
> git-ls-remote behaves differently then git-show-ref when it cannot find
> any matching refs. While the latter returns non zero exit code in this
> case, the former always returns 0. Is there any specific reason for this
> behaviour?

There is no specific reason other than "they happened to be implemented like so". These commands have always behaved that way and people are relying on their exit status, so unless there is a compelling reason, they will not change.

It is just a matter of opinion to consider that it is an error condition or just a normal case to see an empty set for a "List 'em and filter with these criteria" request. Outside git, "find /there -name no-such-file" exits with zero status, while "grep no-such-pattern file" exits with non-zero status.

You can rely on your knowledge of the commands and write your tests like this:

	test $(git ls-remote $there $pattern | wc -l) != 0 || die "none"
	git show-ref -q $pattern || die "none"

Alternatively, you can defend yourself against the next person who asks the same question by writing the last one as:

	test $(git show-ref $pattern | wc -l) != 0 || die "none"
Either would work.
Previous: Kacper KornetNext: Junio C Hamano
Message 2 of 10 in “Exit code of git-ls-remote”
  1. Kacper KornetMay 12, 2011
  2. Junio C HamanoMay 12, 2011
  3. Junio C HamanoMay 12, 2011
  4. ls-remote: optionally return non-zero on non-existing refsMichael Schubert, May 18, 2011
  5. Thiago FarinaMay 18, 2011
  6. Junio C HamanoMay 18, 2011
  7. ls-remote: optionally return non-zero on non-existing refsMichael Schubert, May 18, 2011
  8. Andreas SchwabMay 18, 2011
  9. Junio C HamanoMay 18, 2011
  10. Michael SchubertMay 18, 2011

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.