All of lore.kernel.org
 help / color / mirror / Atom feed
* git checkout exit value and post-commit hooks
@ 2017-03-14  1:58 Andreas Politz
  2017-03-14  6:00 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Politz @ 2017-03-14  1:58 UTC (permalink / raw)
  To: git


Hi,

the exit value of a `git checkout' seems to depend on the exit values of
the hooks it runs. This breaks for example `git bisect', as seen in the
following example.

$ mkdir gitbug
$ cd gitbug
$ git init
$ ln -s /bin/false .git/hooks/post-commit
$ git bisect start
$ git bisect reset
fatal: invalid reference: master
Could not check out original HEAD 'master'.
Try 'git bisect reset <commit>'.

-ap

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: git checkout exit value and post-commit hooks
  2017-03-14  1:58 git checkout exit value and post-commit hooks Andreas Politz
@ 2017-03-14  6:00 ` Junio C Hamano
  2017-03-14 10:07   ` Andreas Politz
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2017-03-14  6:00 UTC (permalink / raw)
  To: Andreas Politz; +Cc: git

Andreas Politz <politza@hochschule-trier.de> writes:

> the exit value of a `git checkout' seems to depend on the exit values of
> the hooks it runs. This breaks for example `git bisect', as seen in the
> following example.

I am a bit puzzled why you have "checkout" and "post-commit" on the
title, though.  Does checkout call a hook for "commit"?

Any script that calls "git checkout" and sees it fail should not
blindly continue its usual processing; if "git bisect" notices an
error from "git checkout" it internally runs and stops, it is doing
the right thing.

A hook script that tries to do something during the main command
(e.g. "git checkout") and fails to do what it wanted to do needs a
way to tell the main command that it failed, and the way for it to
do so is to exit with non-zero status.  Upon seeing such an error,
the main command needs to relay the error to the end user, as the
operation as the whole (i.e. what the main command does, in addition
to what the end user wanted to customize by running the hook) failed.

So if your hook tells "git checkout" it failed to do something it
wanted to do, it is very sensible for that error to percolate up.
If that is not wanted, perhaps you should stop exiting with a failure
status from your hook when it did not fail?




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: git checkout exit value and post-commit hooks
  2017-03-14  6:00 ` Junio C Hamano
@ 2017-03-14 10:07   ` Andreas Politz
  0 siblings, 0 replies; 3+ messages in thread
From: Andreas Politz @ 2017-03-14 10:07 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Junio C Hamano <gitster@pobox.com> writes:

> Andreas Politz <politza@hochschule-trier.de> writes:
>
>> the exit value of a `git checkout' seems to depend on the exit values of
>> the hooks it runs. This breaks for example `git bisect', as seen in the
>> following example.
>
> I am a bit puzzled why you have "checkout" and "post-commit" on the
> title, though.  Does checkout call a hook for "commit"?

No, just a typo.

> Any script that calls "git checkout" and sees it fail should not
> blindly continue its usual processing; if "git bisect" notices an
> error from "git checkout" it internally runs and stops, it is doing
> the right thing.

So its by designed, I should have guessed as much.

I'm sorry, I never used git-hooks before and spend an hour trying to
figure out, why I can't reset the bisect operation, while the error
message (something to the effect of "Unable to checkout master" seemed
ridiculous.

-ap

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-03-14 10:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-14  1:58 git checkout exit value and post-commit hooks Andreas Politz
2017-03-14  6:00 ` Junio C Hamano
2017-03-14 10:07   ` Andreas Politz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.