threads / discuss / 46879

hooks are ignored if there are not marked as executable

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

## tl;dr

2 messages between Oct 2, 2017 and Oct 2, 2017.

replies: 1people: 2as markdown or json

Damien· Oct 2, 2017, 10:06 UTC · lore
Hi,

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.

I think ignoring a hook is misleading and not newbie friendly, an error message to signal an incorrectly configured hook could be better. At least as a warning to be backward-compatible.

Thanks, Damien

Jonathan Nieder· Oct 2, 2017, 22:50 UTC · re: Damien · lore

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

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

← back to recent threads