git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: command return values

From
BCBrian Craft <bcboy@thecraftstudio.com>
Date
Jul 11, 2010, 14:53 UTC
Message-ID
<AANLkTikLjU4GjFdgKht2VgUkFS1xNQPpNyjCb_tDlomF@mail.gmail.com>
In-Reply-To
<20100711113733.GA19113@coredump.intra.peff.net>

Ah, you're right about the return value. I was losing it in a scripting error. And breaking down "clone -b" is a good work-around for the non-existent branch.

Thanks! b.c.

On Sun, Jul 11, 2010 at 4:37 AM, Jeff King <peff@peff.net> wrote:
Show 70 quoted lines
> On Sat, Jul 10, 2010 at 09:11:18PM -0700, Brian Craft wrote:
>
>> I'm finding that "git clone" doesn't return useful error codes, e.g.
>> trying to clone from a bad repository.  Also, it doesn't abort if you
>> try to clone a branch that doesn't exist. The command succeeds,
>> leaving you with the wrong result. I haven't found a way to tell when
>> the command really succeeds, except for scraping the output.
>
> It should give useful error codes. I see:
>
>  $ git clone parent child; echo $?
>  Cloning into child...
>  done.
>  0
>
>  $ git clone bogus child; echo $?
>  Cloning into child...
>  fatal: '/home/peff/foo/bogus' does not appear to be a git repository
>  fatal: The remote end hung up unexpectedly
>  128
>
>  $ find parent -depth | xargs chmod ogu-r
>  $ git clone parent child; echo $?
>  Cloning into child...
>  fatal: failed to open '/home/peff/foo/parent/.git/objects': Permission
>  denied
>  128
>
> So those all seem reasonable. Is there some other case of a "bad
> repository" that fails but gets you a zero exit code?
>
> For the case of a non-existent branch, I see:
>
>  $ git clone -b bogus parent child; echo $?
>  Cloning into child...
>  done.
>  warning: Remote branch bogus not found in upstream origin, using HEAD
>  instead
>  0
>
> So yes, it completes with a warning. I agree that is not ideal, as a
> script that clones has no idea that it did not actually get the data it
> was looking for.
>
> I think the rationale for not aborting totally is that we have done
> significant work (including network traffic) during the clone, and the
> warning can generally be remedied with "git checkout the-right-branch".
> We could perhaps keep the repository but signal with a non-zero exit
> code.
>
> The other option for a script is not to use "-b", which only impacts
> checkout. Instead, you could do:
>
>  $ git clone -n parent child &&
>    cd child &&
>    git checkout -b interesting-branch origin/interesting-branch
>
> which is just as efficient, but lets you react differently to failure of
> each part. You can also break it down further into:
>
>  $ git init &&
>    git remote add origin parent &&
>    git fetch origin &&
>    git branch interesting-branch origin/interesting-branch &&
>    git checkout interesting-branch
>
> but I don't think there is much point in doing so.
>
> -Peff
>
Previous: Jeff King
Message 4 of 4 in “command return values”
  1. Brian CraftJul 11, 2010
  2. Sverre RabbelierJul 11, 2010
  3. Jeff KingJul 11, 2010
  4. Brian CraftJul 11, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.