-1

I'm learning about pre-commit hooks and I can't seem to get them to run

I'm running git 2.40.1 on Mac OS Monterey 12.6.5

This is the content of my .git/hooks directory in the root of my demo project

enter image description here

Meanwhile, this is the local .git/config file with hooksPath set correctly

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
    hooksPath = .git/hooks
[remote "origin"]
    url = ssh://git@bitbucket.XXXXXXXX.com/devops/demo.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[branch "develop"]
    remote = origin
    merge = refs/heads/develop

At this point, I'd just like the message-test hook to run, which is a super simple HELLO WORLD

#!/bin/sh

echo "Hello world!"

Permissions on my hooks all look to be executable

mac-me Desktop/demo ‹testing-strings-xml-push› » ls -l .git/hooks
total 136
drwxr-xr-x  17 ME  staff   544 May  4 16:40 .
drwxr-xr-x  14 ME  staff   448 May 11 15:14 ..
-rwxr-xr-x@  1 ME  staff   478 May  4 16:08 applypatch-msg.sample
-rwxr-xr-x   1 ME  staff   154 May  4 16:30 block-string-changes
-rwxr-xr-x   1 ME  staff   896 May  4 16:08 commit-msg
-rwxr-xr-x   1 ME  staff  4726 May  4 16:08 fsmonitor-watchman.sample
-rwxr-xr-x@  1 ME  staff    32 May  4 16:39 message-test
-rwxr-xr-x   1 ME  staff   189 May  4 16:08 post-update.sample
-rwxr-xr-x   1 ME  staff   424 May  4 16:08 pre-applypatch.sample
-rwxr-xr-x   1 ME  staff  1643 May  4 16:08 pre-commit.sample
-rwxr-xr-x   1 ME  staff   416 May  4 16:08 pre-merge-commit.sample
-rwxr-xr-x   1 ME  staff  1374 May  4 16:08 pre-push.sample
-rwxr-xr-x   1 ME  staff  4898 May  4 16:08 pre-rebase.sample
-rwxr-xr-x   1 ME  staff   544 May  4 16:08 pre-receive.sample
-rwxr-xr-x   1 ME  staff  1492 May  4 16:08 prepare-commit-msg.sample
-rwxr-xr-x   1 ME  staff  2783 May  4 16:08 push-to-checkout.sample
-rwxr-xr-x   1 ME  staff  3650 May  4 16:08 update.sample

I am baffled, any help very much appreciated thank you!

LizCiraG
  • 57
  • 4
  • `message-test` is not a name known to git, you will have to call it from one of the actual git hooks. Is your question about `commit-msg` or `pre-commit` ? – LeGEC May 11 '23 at 19:36
  • Please refer to [the documentation](https://git-scm.com/docs/githooks) – LeGEC May 11 '23 at 19:37

1 Answers1

2

Git hooks don't run anything that are in your .git/hooks folder, they run the file named for that hook. For a pre-commit hook, the file should be named pre-commit. If you want multiple pre-commit hooks, there are things such as https://pre-commit.com/ that simplify that. git hooks

eten
  • 803
  • 3
  • 14
  • Thank you!! This is the correct answer--I read a ton of documentation, but still missed that the naming convention was restricted to the .sample files. I am able to change the code in pre-commit, remove .sample, and it runs. Thank you thank you thank you – LizCiraG May 11 '23 at 20:40