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

BUG. git rebase -i successfully continues (and also skips rewording) when pre-commit hook fails (exits with non-zero code)

From
Alexey Shumkin <alex.crezoff@gmail.com>
Date
Nov 17, 2011, 08:58 UTC
Message-ID
<20111117125847.190e9b25@ashu.dyn.rarus.ru>

For a project I have a pre-commit hook that monitors whether files in a folder (scripts of DB) changed or not and fails if another special file (DB version) did not changed, too.

So, I did some commits and then I decided to change the order of them. Of course, I used a lovely "git rebase -i" command. I changed the order of the commits, then rebasing went ok. But I noticed that my pre-commit hook output failure message (one of the commits did not meet above-mentioned condition). It's not too bad but ugly. But when I decided to correct a message of that specific commit I ran "git rebase -i" again, marked that commit for rewording, rewording did not start (because pre-commit hook failed, obviously) and rebasing went on (commit had an unchanged message) and successfully finished. That is not what I expected. I guess if any of hooks fail (which usually fail the commit), rebasing have to be interrupted (as when there are conflicts)

Here is a sample to reproduce the error git init . echo content > file git add -fv file git commit -a -m 'first commit' echo line 2 >> file git commit -a -m 'secont commit' # note a typo ;) echo '#!/bin/bash echo commit failed exit 1' > .git/hooks/pre-commit chmod +x .git/hooks/pre-commit echo fail >> file git commit -a -m 'failed commit' # to show that pre-commit hook fails # and outputs "commit failed" git reset --hard git rebase -i HEAD^ # mark commit for rewording and exit an editor

note following output after all this:
>commit fail/1)
>Successfully rebased and updated refs/heads/master
Next: Andrew Wong
Message 1 of 6 in “BUG. git rebase -i successfully continues (and also skips rewording) when pre-commit hook fails (exits with non-zero code)”
  1. Alexey ShumkinNov 17, 2011
  2. Andrew WongNov 28, 2011
  3. rebase -i: interrupt rebase when "commit --amend" failed during "reword"Andrew Wong, Nov 28, 2011
  4. Junio C HamanoNov 29, 2011
  5. Andrew WongNov 30, 2011
  6. rebase -i: interrupt rebase when "commit --amend" failed during "reword"Andrew Wong, Nov 30, 2011

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.