{"thread":{"id":"45373","subject":"git checkout exit value and post-commit hooks","startedAt":"2017-03-14T02:05:07Z","lastAt":"2017-03-14T10:08:13Z","messageCount":3,"participants":["Andreas Politz","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"314021","messageId":"87y3w8k4ac.fsf@luca","threadId":"45373","inReplyTo":null,"subject":"git checkout exit value and post-commit hooks","fromName":"Andreas Politz","fromEmail":"politza@hochschule-trier.de","sentAt":"2017-03-14T01:58:35Z","receivedAt":"2017-03-14T02:05:07Z","isPatch":false,"sender":{"key":"politza@hochschule-trier.de","avatar":null},"body":"\nHi,\n\nthe exit value of a `git checkout' seems to depend on the exit values of\nthe hooks it runs. This breaks for example `git bisect', as seen in the\nfollowing example.\n\n$ mkdir gitbug\n$ cd gitbug\n$ git init\n$ ln -s /bin/false .git/hooks/post-commit\n$ git bisect start\n$ git bisect reset\nfatal: invalid reference: master\nCould not check out original HEAD 'master'.\nTry 'git bisect reset <commit>'.\n\n-ap\n"},{"id":"314026","messageId":"xmqqshmgjt2j.fsf@gitster.mtv.corp.google.com","threadId":"45373","inReplyTo":"87y3w8k4ac.fsf@luca","subject":"Re: git checkout exit value and post-commit hooks","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-03-14T06:00:52Z","receivedAt":"2017-03-14T06:01:00Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andreas Politz <politza@hochschule-trier.de> writes:\n\n> the exit value of a `git checkout' seems to depend on the exit values of\n> the hooks it runs. This breaks for example `git bisect', as seen in the\n> following example.\n\nI am a bit puzzled why you have \"checkout\" and \"post-commit\" on the\ntitle, though.  Does checkout call a hook for \"commit\"?\n\nAny script that calls \"git checkout\" and sees it fail should not\nblindly continue its usual processing; if \"git bisect\" notices an\nerror from \"git checkout\" it internally runs and stops, it is doing\nthe right thing.\n\nA hook script that tries to do something during the main command\n(e.g. \"git checkout\") and fails to do what it wanted to do needs a\nway to tell the main command that it failed, and the way for it to\ndo so is to exit with non-zero status.  Upon seeing such an error,\nthe main command needs to relay the error to the end user, as the\noperation as the whole (i.e. what the main command does, in addition\nto what the end user wanted to customize by running the hook) failed.\n\nSo if your hook tells \"git checkout\" it failed to do something it\nwanted to do, it is very sensible for that error to percolate up.\nIf that is not wanted, perhaps you should stop exiting with a failure\nstatus from your hook when it did not fail?\n\n\n\n"},{"id":"314030","messageId":"87tw6w9nnq.fsf@luca","threadId":"45373","inReplyTo":"xmqqshmgjt2j.fsf@gitster.mtv.corp.google.com","subject":"Re: git checkout exit value and post-commit hooks","fromName":"Andreas Politz","fromEmail":"politza@hochschule-trier.de","sentAt":"2017-03-14T10:07:53Z","receivedAt":"2017-03-14T10:08:13Z","isPatch":false,"sender":{"key":"politza@hochschule-trier.de","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Andreas Politz <politza@hochschule-trier.de> writes:\n>\n>> the exit value of a `git checkout' seems to depend on the exit values of\n>> the hooks it runs. This breaks for example `git bisect', as seen in the\n>> following example.\n>\n> I am a bit puzzled why you have \"checkout\" and \"post-commit\" on the\n> title, though.  Does checkout call a hook for \"commit\"?\n\nNo, just a typo.\n\n> Any script that calls \"git checkout\" and sees it fail should not\n> blindly continue its usual processing; if \"git bisect\" notices an\n> error from \"git checkout\" it internally runs and stops, it is doing\n> the right thing.\n\nSo its by designed, I should have guessed as much.\n\nI'm sorry, I never used git-hooks before and spend an hour trying to\nfigure out, why I can't reset the bisect operation, while the error\nmessage (something to the effect of \"Unable to checkout master\" seemed\nridiculous.\n\n-ap\n"}]}