This is all on OS X Mojave.
I’m trying to block myself from mistakenly making commits to the master branch, because that is a thing I do a little too often, using the pre-commit Git hook from this SO answer, changed slightly because I use bash instead of sh. Every time I tried to run it, though, I got the following:
fatal: cannot exec '.git/hooks/pre-commit': Operation not permitted
I checked the permissions of the .git and .git/hooks directories. Both are drwxrwxrwx. The permissions on pre-commit itself are:
-rwxr-xr-x@ 1 emeyer staff 25 Feb 5 11:50 pre-commit
…which is the same as the pre-commit.sample file I copied over to pre-commit and then replaced the contents. I tried chmod +w but that didn’t fix it.
I decided to simplify my testing and replaced the contents of pre-commit with the following:
#!/bin/bash
echo "Test"
I still got the above-referenced Operation not permitted error. I also tried it with #!/bin/sh like in the SO answer’s example; same result.
If I try running the script directly, by typing ./pre-commit from the command line, I get a slightly different error: -bash: ./pre-commit: /bin/bash: bad interpreter: Operation not permitted. The error is consistent whether I use /bin/bash, /bin/sh, /usr/local/bin/bash, or /usr/local/bin/sh.
Googling, Binging, and SO-searching didn’t get me an answer that worked, so I’m asking here how to allow the operation, or whatever is needed.
noexecoption?@suggests that you are.) You're probably hitting the System Integrity Protection feature in Mojave.pre-commitdirectly and got-bash: ./pre-commit: /bin/bash: bad interpreter: Operation not permitted(and the same basic result withsh),