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

Re: hooks are ignored if there are not marked as executable

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Oct 2, 2017, 22:50 UTC
Message-ID
<20171002225056.GS19555@aiede.mtv.corp.google.com>
In-Reply-To
<CAAQ5yigO8FxhUjwr68OnW0UEYck2AKF5P0Qt_zedhBL_SEiKTw@mail.gmail.com>
Hi Damien,
Damien wrote:
> If you do `echo my_script > .git/hooks/pre-commit` and then `git commit`,
> The hook is just gonna be ignored.
> But if you do `chmod +x .git/hooks/pre-commit`, then it's executed.
This is intentional.
> I think ignoring a hook is misleading and not newbie friendly, an error
> message to signal an incorrectly configured hook could be better.
Adding a warning sounds like a nice change.  Care to propose a patch?

In the early days, sample hooks were installed without .sample in their filename and could be enabled by "chmod +x"-ing them. Because of this, long-time users of Git may find themselves experiencing this warning more often than they'd like. That could be acceptable if the warning shows a command to run to prevent the warning from showing up again, though (see advice.c for some examples of how that can be done).

The main code path to look at is run-command.c::find_hook.

"git grep -e 'rev-parse --git-path hooks' -- . ':!contrib'" finds a few other code paths you may also want to look at.

Thanks and hope that helps, Jonathan

Previous: Damien
Message 2 of 2 in “hooks are ignored if there are not marked as executable”
  1. DamienOct 2, 2017
  2. Jonathan NiederOct 2, 2017

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.