git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: demerphq <demerphq@gmail.com>
To: Git <git@vger.kernel.org>
Subject: should git rev-parse -q --verify on a range produce output?
Date: Sun, 8 Jan 2023 00:03:55 +0100	[thread overview]
Message-ID: <CANgJU+Vo3B=YuqgWVgiRMMiBwTFEh98O0LSJJ+ES6EM=MP4Cew@mail.gmail.com> (raw)

Hi all,

I was curious if it is a bug that `rev-parse -q --verify` produces
output for a commit range, and only reveals it is supposed to be used
with a single commit as an error message? When combined with -q it
make it seem like it has silently worked if you aren't careful to
check $? afterwards. (Which obviously some script wasn't or I wouldn't
be posting this. :-)

For example:

git rev-parse --verify -q HEAD^..HEAD; echo $?
869400a03fff1b3dcff82f3357d37ab506af2788
^13073008cfc15016d862c630d56323bb7c9d775e
1

"looks" like it has worked, producing two output refs, but as it shows
the exit code is 1. We have also seen it output a single line from a
range, when the entire range wasn't cloned.

It seems weird that it produces output at all in this case. Shouldn't
it see that it is a range and exit with a nonzero exit code
immediately? The docs say:

       --verify
           Verify that exactly one parameter is provided, and that it
can be turned into a raw 20-byte SHA-1 that
           can be used to access the object database. If so, emit it
to the standard output; otherwise, error out.
           ...
       -q, --quiet
           Only meaningful in --verify mode. Do not output an error
message if the first argument is not a valid
           object name; instead exit with non-zero status silently.
SHA-1s for valid object names are printed to
           stdout on success.

It seems to me that the second sentence from --verify indicates that
it should not produce output from a range at all, although I guess the
exact meaning of "error out" is ambiguous, and the last sentence of
the --quiet documentation is not incompatible with it also producing
output when it fails,  but it seems like if this is expected behavior
it should be documented more explicitly. Which makes me think it is a
bug. :-)

I am testing with git version 2.25.1 but this was encountered on
GitHub with whatever git they used as well. (We noticed this in a CI
pipeline using a shallow clone.)

cheers
Yves


-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

             reply	other threads:[~2023-01-07 23:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-07 23:03 demerphq [this message]
2023-01-08  2:34 ` should git rev-parse -q --verify on a range produce output? Junio C Hamano
2023-01-08 10:45   ` demerphq
2023-01-09  3:51     ` Junio C Hamano
2023-01-09  9:04       ` demerphq

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to='CANgJU+Vo3B=YuqgWVgiRMMiBwTFEh98O0LSJJ+ES6EM=MP4Cew@mail.gmail.com' \
    --to=demerphq@gmail.com \
    --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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).