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

post-checkout hook aborts rebase

From
Tom Rutherford <tmrutherford@gmail.com>
Date
Aug 26, 2020, 23:10 UTC
Message-ID
<CAHr-Uu_KeAJZrd+GzymNP47iFi+dZkvVYsWQPtzT_FQrVnWTDg@mail.gmail.com>
Hi Git community,

My team encountered an issue today which I believe is a bug, and I'm interested to know if those more familiar with the codebase and documentation agree with me. Here's a bug report. Thanks for your attention.

Tom
===

Thank you for filling out a Git bug report! Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)
1. Have a post-checkout hook that returns a nonzero exit status.
2. `git pull --rebase` where there is at least one local commit to be
rebased onto an incoming commit. (I assume any rebase would exhibit
similar behavior, but this is how I encountered the issue).
What did you expect to happen? (Expected behavior)
The rebase succeeds.

I expect this because the documentation for the post-checkout hook states, "This hook cannot affect the outcome of git switch or git checkout" https://www.git-scm.com/docs/githooks#_post_checkout

What happened instead? (Actual behavior)

`error: could not detach HEAD` is displayed, and I end up in a detached head state.

What's different between what you expected and what actually happened?

I do not expect the post-checkout hook to prevent rebase from succeeding. The documentation suggests this should succeed. It seems either the documentation is wrong, or git's use of the hook is in this case.

Anything else you want to add:

The issue is elegantly explained in this stack overflow answer: https://stackoverflow.com/a/25562688/1286571

It's not clear to me if this is a bug, or an omission from the documentation. I reproduced it on 2.28, but I haven't tried building from source.

Please review the rest of the bug report below. You can delete any lines you don't wish to share.

[System Info] git version: git version 2.28.0 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Linux 5.4.0-42-generic #46~18.04.1-Ubuntu SMP Fri Jul 10 07:21:24 UTC 2020 x86_64 compiler info: gnuc: 7.5 libc info: glibc: 2.27 $SHELL (typically, interactive shell): /usr/bin/fish

[Enabled Hooks] pre-commit post-checkout

Next: Junio C Hamano
Message 1 of 16 in “post-checkout hook aborts rebase”
  1. Tom RutherfordAug 26, 2020
  2. Junio C HamanoAug 27, 2020
  3. Junio C HamanoAug 27, 2020
  4. Tom RutherfordAug 27, 2020
  5. Chris TorekAug 27, 2020
  6. Junio C HamanoAug 27, 2020
  7. Chris TorekAug 27, 2020
  8. Elijah NewrenAug 27, 2020
  9. Chris TorekAug 27, 2020
  10. Phillip WoodSep 9, 2020
  11. Tom RutherfordSep 9, 2020
  12. Philippe BlainSep 11, 2020
  13. Junio C HamanoSep 12, 2020
  14. Elijah NewrenAug 27, 2020
  15. Junio C HamanoAug 27, 2020
  16. Elijah NewrenAug 27, 2020

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.