{"thread":{"id":"23696","subject":"Determining if a file exists in a bare repo","startedAt":"2010-05-04T16:11:57Z","lastAt":"2010-05-04T16:57:12Z","messageCount":5,"participants":["Adam Mercer","Jacob Helwig","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"140913","messageId":"w2q799406d61005040911p8fd7c234s5e6382298129985f@mail.gmail.com","threadId":"23696","inReplyTo":null,"subject":"Determining if a file exists in a bare repo","fromName":"Adam Mercer","fromEmail":"ramercer@gmail.com","sentAt":"2010-05-04T16:11:57Z","receivedAt":"2010-05-04T16:11:57Z","isPatch":false,"sender":{"key":"ramercer@gmail.com","avatar":"https://gravatar.com/avatar/16dc719817f62b75075d529ce4ea992ee82bb1a08e45a3029797f39223d6ee64?d=mp&s=160"},"body":"Hi\n\nI'm trying to write a post-receive hook that generates some HTML files\nfrom reStructured text files stored in a repository. Essentially I'm\ndoing this with\n\ngit show master:INSTALL | rst2html --no-raw --no-file-insertion >\n/path/to/INSTALL.html\n\nHowever I would like this script to fail gracefully if the INSTALL\nfile is not available in the repository so would like to check if this\nfile exists. The problem I'm having is that git-show seems to return a\nzero return code even if the file you request doesn't exist, e.g.:\n\n$ git show master:NoneExistantFile\nfatal: ambiguous argument 'master:NoneExistantFile': unknown revision\nor path not in the working tree.\nUse '--' to separate paths from revisions\n$ echo $?\n0\n$\n\nis there another, scriptable, way to determine if a given file exists\nin a given branch of a bare repository?\n\nCheers\n\nAdam\n"},{"id":"140914","messageId":"h2z8c9a061005040918s33bd5020sa89e95aedb7b8cb@mail.gmail.com","threadId":"23696","inReplyTo":"w2q799406d61005040911p8fd7c234s5e6382298129985f@mail.gmail.com","subject":"Re: Determining if a file exists in a bare repo","fromName":"Jacob Helwig","fromEmail":"jacob.helwig@gmail.com","sentAt":"2010-05-04T16:18:09Z","receivedAt":"2010-05-04T16:18:09Z","isPatch":false,"sender":{"key":"jacob.helwig@gmail.com","avatar":"https://avatars.githubusercontent.com/u/14557?v=4"},"body":"On Tue, May 4, 2010 at 09:11, Adam Mercer <ramercer@gmail.com> wrote:\n> Hi\n>\n> I'm trying to write a post-receive hook that generates some HTML files\n> from reStructured text files stored in a repository. Essentially I'm\n> doing this with\n>\n> git show master:INSTALL | rst2html --no-raw --no-file-insertion >\n> /path/to/INSTALL.html\n>\n> However I would like this script to fail gracefully if the INSTALL\n> file is not available in the repository so would like to check if this\n> file exists. The problem I'm having is that git-show seems to return a\n> zero return code even if the file you request doesn't exist, e.g.:\n>\n> $ git show master:NoneExistantFile\n> fatal: ambiguous argument 'master:NoneExistantFile': unknown revision\n> or path not in the working tree.\n> Use '--' to separate paths from revisions\n> $ echo $?\n> 0\n> $\n>\n> is there another, scriptable, way to determine if a given file exists\n> in a given branch of a bare repository?\n>\n> Cheers\n>\n> Adam\n\nWhat about using \"git ls-tree master\" to get a file listing?\n"},{"id":"140915","messageId":"o2k799406d61005040926h6d9b56f5ge48378822ec46280@mail.gmail.com","threadId":"23696","inReplyTo":"h2z8c9a061005040918s33bd5020sa89e95aedb7b8cb@mail.gmail.com","subject":"Re: Determining if a file exists in a bare repo","fromName":"Adam Mercer","fromEmail":"ramercer@gmail.com","sentAt":"2010-05-04T16:26:23Z","receivedAt":"2010-05-04T16:26:23Z","isPatch":false,"sender":{"key":"ramercer@gmail.com","avatar":"https://gravatar.com/avatar/16dc719817f62b75075d529ce4ea992ee82bb1a08e45a3029797f39223d6ee64?d=mp&s=160"},"body":"On Tue, May 4, 2010 at 11:18, Jacob Helwig <jacob.helwig@gmail.com> wrote:\n\n> What about using \"git ls-tree master\" to get a file listing?\n\nGood idea, thanks that seems to do the trick.\n\nCheers\n\nAdam\n"},{"id":"140918","messageId":"7v7hnjoc3i.fsf@alter.siamese.dyndns.org","threadId":"23696","inReplyTo":"w2q799406d61005040911p8fd7c234s5e6382298129985f@mail.gmail.com","subject":"Re: Determining if a file exists in a bare repo","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-05-04T16:39:29Z","receivedAt":"2010-05-04T16:39:29Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Adam Mercer <ramercer@gmail.com> writes:\n\n> Hi\n>\n> I'm trying to write a post-receive hook that generates some HTML files\n> from reStructured text files stored in a repository. Essentially I'm\n> doing this with\n>\n> git show master:INSTALL | rst2html --no-raw --no-file-insertion >\n> /path/to/INSTALL.html\n>\n> However I would like this script to fail gracefully if the INSTALL\n> file is not available in the repository so would like to check if this\n> file exists. The problem I'm having is that git-show seems to return a\n> zero return code even if the file you request doesn't exist\n\nEven if it returned an error status, you are discarding it by placing the\nprocess on the upstream side of the pipe, so your command line above won't\nbe able to catch an error anyway.  I would probably do something like this\nif I were you:\n\n    git rev-parse --verify master:INSTALL >/dev/null 2>&1 &&\n    git cat-file blob master:INSTALL | rst2...\n"},{"id":"140921","messageId":"z2p799406d61005040957j93f8f4a3zfb8a9f38dbe7c72c@mail.gmail.com","threadId":"23696","inReplyTo":"7v7hnjoc3i.fsf@alter.siamese.dyndns.org","subject":"Re: Determining if a file exists in a bare repo","fromName":"Adam Mercer","fromEmail":"ramercer@gmail.com","sentAt":"2010-05-04T16:57:12Z","receivedAt":"2010-05-04T16:57:12Z","isPatch":false,"sender":{"key":"ramercer@gmail.com","avatar":"https://gravatar.com/avatar/16dc719817f62b75075d529ce4ea992ee82bb1a08e45a3029797f39223d6ee64?d=mp&s=160"},"body":"On Tue, May 4, 2010 at 11:39, Junio C Hamano <gitster@pobox.com> wrote:\n\n> Even if it returned an error status, you are discarding it by placing the\n> process on the upstream side of the pipe, so your command line above won't\n> be able to catch an error anyway.\n\nSorry I wasn't very clear, first I trying to use git-show if the file\nexisted and then piping the output to rst2html...\n\n> I would probably do something like this\n> if I were you:\n>\n>    git rev-parse --verify master:INSTALL >/dev/null 2>&1 &&\n>    git cat-file blob master:INSTALL | rst2...\n\nThanks, thats a better approach!\n\nCheers\n\nAdam\n"}]}