git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Jonathan Nieder <jrnieder@gmail.com>,
	Magne Land <magne.land@gmail.com>,
	Johannes Schindelin <johannes.schindelin@gmx.de>,
	Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 0/1] Pass through the exit code of post-checkout
Date: Thu, 10 Oct 2019 05:01:38 -0700 (PDT)	[thread overview]
Message-ID: <pull.385.git.gitgitgadget@gmail.com> (raw)

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

             reply	other threads:[~2019-10-10 12:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-10 12:01 Johannes Schindelin via GitGitGadget [this message]
2019-10-10 12:01 ` [PATCH 1/1] switch/restore: consistently pass through exit code of `post-checkout` Johannes Schindelin via GitGitGadget
2019-10-11  4:22 ` [PATCH 0/1] Pass through the exit code of post-checkout Junio C Hamano

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=pull.385.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=johannes.schindelin@gmx.de \
    --cc=jrnieder@gmail.com \
    --cc=magne.land@gmail.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).