Re: git cat-file -e behavior

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

 



On Mon, Feb 29, 2016 at 01:16:34PM +0100, Michal Čihař wrote:

> Dne 29.2.2016 v 12:44 Jeff King napsal(a):
> > 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 found this as best way to check whether file exists in branch.
> Checking git ls-tree output seems less error prone than checking return
> value of git cat-file -e...

I think the usual way to do that would be:

  git rev-parse --verify $branch:$path >/dev/null

which just resolves the name (not that what you are doing is wrong, I
just think rev-parse is the way we usually do it in our scripts).

That _will_ write a message to stderr when the name doesn't resolve.

-Peff
--
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]