# [PATCH] Documentation/githooks: Clarify the behavior of post-checkout hook

2 messages from 2018-03-13 to 2018-03-14. Participants: Magne Land, Jonathan Nieder.
Thread: https://gitlist.dev/t/48035

## Magne Land, 2018-03-13 19:59

Subject: [PATCH] Documentation/githooks: Clarify the behavior of post-checkout hook
Message-ID: <0102016220f23987-d4661c81-cf6e-4c96-8487-acce6bb365c8-000000@eu-west-1.amazonses.com>
URL: https://gitlist.dev/e/0102016220f23987-d4661c81-cf6e-4c96-8487-acce6bb365c8-000000%40eu-west-1.amazonses.com

```
From: Magne Land <magne.land@appfolio.com>

This can happen when using 'git rebase -i’:
could not detach HEAD

Based on discovering this Stack Overflow discussion:
https://stackoverflow.com/questions/25561485/git-rebase-i-with-squash-cannot-detach-head
---
 Documentation/githooks.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt
index f877f7b7cd19c..3a4e027d0d175 100644
--- a/Documentation/githooks.txt
+++ b/Documentation/githooks.txt
@@ -166,7 +166,9 @@ worktree.  The hook is given three parameters: the ref of the previous HEAD,
 the ref of the new HEAD (which may or may not have changed), and a flag
 indicating whether the checkout was a branch checkout (changing branches,
 flag=1) or a file checkout (retrieving a file from the index, flag=0).
-This hook cannot affect the outcome of 'git checkout'.
+
+If this hook exits with a non-zero status, 'git checkout' will exit with the
+same status.
 
 It is also run after 'git clone', unless the --no-checkout (-n) option is
 used. The first parameter given to the hook is the null-ref, the second the

--
https://github.com/git/git/pull/470

```

## Jonathan Nieder, 2018-03-14 00:38

Subject: Re: [PATCH] Documentation/githooks: Clarify the behavior of post-checkout hook
Message-ID: <20180314003816.GE147135@aiede.svl.corp.google.com>
URL: https://gitlist.dev/e/20180314003816.GE147135%40aiede.svl.corp.google.com
In-Reply-To: <0102016220f23987-d4661c81-cf6e-4c96-8487-acce6bb365c8-000000@eu-west-1.amazonses.com>

```
Hi,

Magne Land wrote:

> From: Magne Land <magne.land@appfolio.com>
>
> This can happen when using 'git rebase -i’:
> could not detach HEAD
>
> Based on discovering this Stack Overflow discussion:
> https://stackoverflow.com/questions/25561485/git-rebase-i-with-squash-cannot-detach-head
> ---
>  Documentation/githooks.txt | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Thanks for investigating and writing this.

May we forge your sign-off?  See Documentation/SubmittingPatches
section [[sign-off] 'Certify your work' for more about what this
means.

The above leaves one question unanswered: 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?

Not a rhetorical question: I'm asking because I don't know the answer.
What do you think?

Thanks,
Jonathan

> --- a/Documentation/githooks.txt
> +++ b/Documentation/githooks.txt
> @@ -166,7 +166,9 @@ worktree.  The hook is given three parameters: the ref of the previous HEAD,
>  the ref of the new HEAD (which may or may not have changed), and a flag
>  indicating whether the checkout was a branch checkout (changing branches,
>  flag=1) or a file checkout (retrieving a file from the index, flag=0).
> -This hook cannot affect the outcome of 'git checkout'.
> +
> +If this hook exits with a non-zero status, 'git checkout' will exit with the
> +same status.
>  
>  It is also run after 'git clone', unless the --no-checkout (-n) option is
>  used. The first parameter given to the hook is the null-ref, the second the

```
