Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my Git pre-commit hook not executable by default?

Tags:

git

githooks

If you see the accepted answer in: Aggregating and uglifying JavaScript in a Git pre-commit hook, you'll see that I had to do a chmod +x on my pre-commit hook to get it to work.

Why is this not executable by Git by default?

like image 768
Josh Smith Avatar asked Dec 22 '11 01:12

Josh Smith


People also ask

How do I make a git hook executable?

Open a terminal window by using option + T in GitKraken Client. Once the terminal windows is open, change directory to . git/hooks . Then use the command chmod +x pre-commit to make the pre-commit file executable.

How do I run pre-commit automatically?

If you want to manually run all pre-commit hooks on a repository, run pre-commit run --all-files . To run individual hooks use pre-commit run <hook_id> . The first time pre-commit runs on a file it will automatically download, install, and run the hook.

How do you enforce a pre-commit hook?

If you want enforcement, use an update hook in the central repo. If the hook is doing per-commit verification, you can still provide a pre-commit hook; developers will likely adopt it voluntarily, so that they can find out right away when they've done something wrong, rather than waiting until they try to push.

Do git hooks need EXE?

It turns out all you need to make a Git hook is an executable script in the Git hooks directory. By default (assuming you are in a Git repo) this is . git/hooks .


1 Answers

Because files are not executable by default; they must be set to be executable.

The sample files from a git init are all executable; if it's copied or renamed to a non-sample file, it will retain the original file's x flag.

New files will be created with current defaults. In your case, view those defaults with umask:

$ umask 0022 

By default, new files won't be u+x unless explicitly set to be.

like image 58
Dave Newton Avatar answered Sep 18 '22 19:09

Dave Newton