{"thread":{"id":"24362","subject":"command return values","startedAt":"2010-07-11T04:11:18Z","lastAt":"2010-07-11T14:53:30Z","messageCount":4,"participants":["Brian Craft","Sverre Rabbelier","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"145290","messageId":"AANLkTimQcqhD8FClAXef5dGAWRDbAGdVBmIVXxotzKoa@mail.gmail.com","threadId":"24362","inReplyTo":null,"subject":"command return values","fromName":"Brian Craft","fromEmail":"bcboy@thecraftstudio.com","sentAt":"2010-07-11T04:11:18Z","receivedAt":"2010-07-11T04:11:18Z","isPatch":false,"sender":{"key":"bcboy@thecraftstudio.com","avatar":null},"body":"btw, the \"faq\" link on http://git-scm.com/ is broken.\n\nI'm finding that \"git clone\" doesn't return useful error codes, e.g.\ntrying to clone from a bad repository.  Also, it doesn't abort if you\ntry to clone a branch that doesn't exist. The command succeeds,\nleaving you with the wrong result. I haven't found a way to tell when\nthe command really succeeds, except for scraping the output.\n\nWhat's the deal?\n\nb.c.\n"},{"id":"145291","messageId":"AANLkTilJigJ1YjRrZBwLyfpF4iTFCI8wKzANpL3yf00D@mail.gmail.com","threadId":"24362","inReplyTo":"AANLkTimQcqhD8FClAXef5dGAWRDbAGdVBmIVXxotzKoa@mail.gmail.com","subject":"Re: command return values","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2010-07-11T04:18:55Z","receivedAt":"2010-07-11T04:18:55Z","isPatch":false,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Sat, Jul 10, 2010 at 23:11, Brian Craft <bcboy@thecraftstudio.com> wrote:\n> btw, the \"faq\" link on http://git-scm.com/ is broken.\n\nIt seems that the git wiki is down?\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"145323","messageId":"20100711113733.GA19113@coredump.intra.peff.net","threadId":"24362","inReplyTo":"AANLkTimQcqhD8FClAXef5dGAWRDbAGdVBmIVXxotzKoa@mail.gmail.com","subject":"Re: command return values","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-07-11T11:37:33Z","receivedAt":"2010-07-11T11:37:33Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Jul 10, 2010 at 09:11:18PM -0700, Brian Craft wrote:\n\n> I'm finding that \"git clone\" doesn't return useful error codes, e.g.\n> trying to clone from a bad repository.  Also, it doesn't abort if you\n> try to clone a branch that doesn't exist. The command succeeds,\n> leaving you with the wrong result. I haven't found a way to tell when\n> the command really succeeds, except for scraping the output.\n\nIt should give useful error codes. I see:\n\n  $ git clone parent child; echo $?\n  Cloning into child...\n  done.\n  0\n\n  $ git clone bogus child; echo $?\n  Cloning into child...\n  fatal: '/home/peff/foo/bogus' does not appear to be a git repository\n  fatal: The remote end hung up unexpectedly\n  128\n\n  $ find parent -depth | xargs chmod ogu-r\n  $ git clone parent child; echo $?\n  Cloning into child...\n  fatal: failed to open '/home/peff/foo/parent/.git/objects': Permission\n  denied\n  128\n\nSo those all seem reasonable. Is there some other case of a \"bad\nrepository\" that fails but gets you a zero exit code?\n\nFor the case of a non-existent branch, I see:\n\n  $ git clone -b bogus parent child; echo $?\n  Cloning into child...\n  done.\n  warning: Remote branch bogus not found in upstream origin, using HEAD\n  instead\n  0\n\nSo yes, it completes with a warning. I agree that is not ideal, as a\nscript that clones has no idea that it did not actually get the data it\nwas looking for.\n\nI think the rationale for not aborting totally is that we have done\nsignificant work (including network traffic) during the clone, and the\nwarning can generally be remedied with \"git checkout the-right-branch\".\nWe could perhaps keep the repository but signal with a non-zero exit\ncode.\n\nThe other option for a script is not to use \"-b\", which only impacts\ncheckout. Instead, you could do:\n\n  $ git clone -n parent child &&\n    cd child &&\n    git checkout -b interesting-branch origin/interesting-branch\n\nwhich is just as efficient, but lets you react differently to failure of\neach part. You can also break it down further into:\n\n  $ git init &&\n    git remote add origin parent &&\n    git fetch origin &&\n    git branch interesting-branch origin/interesting-branch &&\n    git checkout interesting-branch\n\nbut I don't think there is much point in doing so.\n\n-Peff\n"},{"id":"145329","messageId":"AANLkTikLjU4GjFdgKht2VgUkFS1xNQPpNyjCb_tDlomF@mail.gmail.com","threadId":"24362","inReplyTo":"20100711113733.GA19113@coredump.intra.peff.net","subject":"Re: command return values","fromName":"Brian Craft","fromEmail":"bcboy@thecraftstudio.com","sentAt":"2010-07-11T14:53:30Z","receivedAt":"2010-07-11T14:53:30Z","isPatch":false,"sender":{"key":"bcboy@thecraftstudio.com","avatar":null},"body":"Ah, you're right about the return value. I was losing it in a\nscripting error. And breaking down \"clone -b\" is a good work-around\nfor the non-existent branch.\n\nThanks!\nb.c.\n\nOn Sun, Jul 11, 2010 at 4:37 AM, Jeff King <peff@peff.net> wrote:\n> On Sat, Jul 10, 2010 at 09:11:18PM -0700, Brian Craft wrote:\n>\n>> I'm finding that \"git clone\" doesn't return useful error codes, e.g.\n>> trying to clone from a bad repository.  Also, it doesn't abort if you\n>> try to clone a branch that doesn't exist. The command succeeds,\n>> leaving you with the wrong result. I haven't found a way to tell when\n>> the command really succeeds, except for scraping the output.\n>\n> It should give useful error codes. I see:\n>\n>  $ git clone parent child; echo $?\n>  Cloning into child...\n>  done.\n>  0\n>\n>  $ git clone bogus child; echo $?\n>  Cloning into child...\n>  fatal: '/home/peff/foo/bogus' does not appear to be a git repository\n>  fatal: The remote end hung up unexpectedly\n>  128\n>\n>  $ find parent -depth | xargs chmod ogu-r\n>  $ git clone parent child; echo $?\n>  Cloning into child...\n>  fatal: failed to open '/home/peff/foo/parent/.git/objects': Permission\n>  denied\n>  128\n>\n> So those all seem reasonable. Is there some other case of a \"bad\n> repository\" that fails but gets you a zero exit code?\n>\n> For the case of a non-existent branch, I see:\n>\n>  $ git clone -b bogus parent child; echo $?\n>  Cloning into child...\n>  done.\n>  warning: Remote branch bogus not found in upstream origin, using HEAD\n>  instead\n>  0\n>\n> So yes, it completes with a warning. I agree that is not ideal, as a\n> script that clones has no idea that it did not actually get the data it\n> was looking for.\n>\n> I think the rationale for not aborting totally is that we have done\n> significant work (including network traffic) during the clone, and the\n> warning can generally be remedied with \"git checkout the-right-branch\".\n> We could perhaps keep the repository but signal with a non-zero exit\n> code.\n>\n> The other option for a script is not to use \"-b\", which only impacts\n> checkout. Instead, you could do:\n>\n>  $ git clone -n parent child &&\n>    cd child &&\n>    git checkout -b interesting-branch origin/interesting-branch\n>\n> which is just as efficient, but lets you react differently to failure of\n> each part. You can also break it down further into:\n>\n>  $ git init &&\n>    git remote add origin parent &&\n>    git fetch origin &&\n>    git branch interesting-branch origin/interesting-branch &&\n>    git checkout interesting-branch\n>\n> but I don't think there is much point in doing so.\n>\n> -Peff\n>\n"}]}