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

[PATCH 0/1] Pass through the exit code of post-checkout

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Oct 10, 2019, 12:01 UTC
Message-ID
<pull.385.git.gitgitgadget@gmail.com>

This is my attempt to revive an old discussion [https://public-inbox.org/git/20180314003816.GE147135@aiede.svl.corp.google.com/] (related to this StackOverflow thread [https://stackoverflow.com/questions/25561485/git-rebase-i-with-squash-cannot-detach-head] ).

> [...] is this the right behavior for "git checkout" to have? I.e. is it

useful for "git checkout" to fail when the post-checkout hook fails, or would it be better for it to e.g. simply print a message and exit with status 0?

To answer Jonathan's question, at long last, yes, it is useful. A hook is not only an opportunity to run code at given points in Git's life cycle, but also an opportunity to stop Git in its tracks. Further, if you script the operation, it may very well be useful to discern between an exit code from Git's operation from an exit code produced by your hook.

If you don't want your git checkout/git switch/git restore to fail due to a post-checkout failure, just make sure that that hook does not fail ;-) (This could easily be achieved by trap EXIT { exit 0; }, I believe.

I discovered, however, that the original patch contribution missed that a git checkout -b <branch> will not pass through the exit code, but instead return exit code 1. As part of my contribution, I fix this, and also introduce a regression test to document the now-consistent behavior.

Johannes Schindelin (1):
  switch/restore: consistently pass through exit code of `post-checkout`
 Documentation/githooks.txt    | 3 ++-
 builtin/checkout.c            | 8 +++++---
 t/t5403-post-checkout-hook.sh | 9 +++++++++
 3 files changed, 16 insertions(+), 4 deletions(-)
base-commit: 70bf0b755af4d1e66da25b7805cac0e481a082e4
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-385%2Fdscho%2Fpost-checkout-hook-exit-code-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-385/dscho/post-checkout-hook-exit-code-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/385
-- 
gitgitgadget
Next: Johannes Schindelin via GitGitGadget
Message 1 of 3 in “Pass through the exit code of post-checkout”
  1. 0/1 Pass through the exit code of post-checkoutJohannes Schindelin via GitGitGadget, Oct 10, 2019
  2. 1/1 switch/restore: consistently pass through exit code of `post-checkout`Johannes Schindelin via GitGitGadget, Oct 10, 2019
  3. Junio C HamanoOct 11, 2019

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.