git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Kacper Kornet <draenog@pld-linux.org>
Cc: git@vger.kernel.org
Subject: Re: Exit code of git-ls-remote
Date: Thu, 12 May 2011 09:21:30 -0700	[thread overview]
Message-ID: <7voc37dh4l.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <20110512120536.GA22033@camk.edu.pl> (Kacper Kornet's message of "Thu, 12 May 2011 14:05:36 +0200")

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.

  reply	other threads:[~2011-05-12 16:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-12 12:05 Exit code of git-ls-remote Kacper Kornet
2011-05-12 16:21 ` Junio C Hamano [this message]
2011-05-12 16:41   ` Junio C Hamano
2011-05-18 14:15     ` [RFC/PATCH] ls-remote: optionally return non-zero on non-existing refs Michael Schubert
2011-05-18 16:59       ` Thiago Farina
2011-05-18 18:28       ` Junio C Hamano
2011-05-18 20:06         ` [PATCH v2] " Michael Schubert
2011-05-18 21:19           ` Andreas Schwab
2011-05-18 21:38             ` Junio C Hamano
2011-05-18 21:53               ` Michael Schubert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7voc37dh4l.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=draenog@pld-linux.org \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).