Re: git cat-file -e behavior

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Feb 29, 2016 at 10:58:29AM +0100, Michal Čihař wrote:

> the documentation for "git cat-file -e" says:
> 
> > Suppress all output; instead exit with zero status if <object> exists
> and is a valid object.
> 
> However running it on non existing object will complain "fatal: Not a
> valid object name".
> 
> $ git cat-file -e master:README.rst
> $ echo $?
> 0
> $ git cat-file -e master:foo
> fatal: Not a valid object name master:foo
> $ echo $?
> 128
> 
> Is the output in this case expected?
> 
> I'm currently running 2.7.0.

It looks like it has been this way forever. The first thing we do with
the object is resolve its name to a sha1, and that's where the error you
see comes from. And then we actually check whether we have the object.

I think the intended use was to feed it a sha1 to see if it exists. Then
the name-resolution step is a noop.

I'm not sure if the behavior you are seeing is all that bad (the
documentation could be read as suppressing the normal stdout output, but
error messages remain), but it would be easy to change:

diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 54db118..afde169 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -35,6 +35,9 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
 	if (unknown_type)
 		flags |= LOOKUP_UNKNOWN_OBJECT;
 
+	if (opt == 'e')
+		return !has_sha1_file(sha1);
+
 	if (get_sha1_with_context(obj_name, 0, sha1, &obj_context))
 		die("Not a valid object name %s", obj_name);
 
@@ -58,9 +61,6 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
 		printf("%lu\n", size);
 		return 0;
 
-	case 'e':
-		return !has_sha1_file(sha1);
-
 	case 'c':
 		if (!obj_context.path[0])
 			die("git cat-file --textconv %s: <object> must be <sha1:path>",
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]