git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Brian Craft <bcboy@thecraftstudio.com>
Cc: git@vger.kernel.org
Subject: Re: command return values
Date: Sun, 11 Jul 2010 07:37:33 -0400	[thread overview]
Message-ID: <20100711113733.GA19113@coredump.intra.peff.net> (raw)
In-Reply-To: <AANLkTimQcqhD8FClAXef5dGAWRDbAGdVBmIVXxotzKoa@mail.gmail.com>

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

  parent reply	other threads:[~2010-07-11 11:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-11  4:11 command return values Brian Craft
2010-07-11  4:18 ` Sverre Rabbelier
2010-07-11 11:37 ` Jeff King [this message]
2010-07-11 14:53   ` Brian Craft

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100711113733.GA19113@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=bcboy@thecraftstudio.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).