27

Because of its simplicity, we use remote repository placed on shared disk, accessing it using file system path (\server\share). Is is possible, in such case, to run hook scripts defined in remote repository? I have defined one but it seems like it is not launched (tested using non valid edit in hook script, witch should cause an error).

Fanda
  • 3,760
  • 5
  • 37
  • 56
  • 1
    I wouldn't place concurrently-written data on a shared drive. There are just too many failure modes, from blatant to subtle, and while git is more forgiving than most software systems in this respect, you depend on little details like O_EXCL being always honored (even with flaky network connections) that you risk serious damage. Or at least damage you can't easily fix. (Why not install a git server on the machine with the shared repo? It's easy, and instructions are easy to find.) – toolforger Nov 28 '21 at 22:38

3 Answers3

33

Git hook is a script you can run before (pre-commit) or after (post-commit) a commit is made. There can be more than one of such a script.

They are placed in a specified folder. Any git repository has a .git/hooks folder with file(s) containing hook scripts.

You need to answer Do you have the event you are testing bind to a hook present in your's git repository?

Check also this on how git executes hooks in Windows:

Tips for using hooks:

Some more git hooks reading:

Blaise
  • 7,230
  • 6
  • 43
  • 53
  • Yes, i had a script in hooks folder, but named post-receive-sendmail. After renaming it to post-receive now it works. Thank you. – Fanda Apr 30 '14 at 11:15
  • 10
    Please put more of the answer here. To me this is a link only answer. – Jess Aug 14 '16 at 13:29
  • 1
    @AndriiM4n0w4R: I have updated the link, thanks for pointing that. – Blaise Nov 05 '18 at 13:08
4

My advice after few hours of fight, double check value:

git config core.hookspath

It should be empty or point your hooks folder (.git\hooks)

GetoX
  • 4,225
  • 2
  • 33
  • 30
0

If you run the command:

git config core.hooksPath .git-hooks

This will look for the hooks in the folder .git-hooks from your project root, same as where you find .git folder. When the commands are run in this folder, take note that the directory being executed from then is the project root - and not in the .git-hooks folder having the actual hooks. This is why you get the "command not found".

Example contents of .git-hooks/post-merge file

!#!/bin/bash
bower install

The "bower install" command is run from the parent directory.

Kim Steinhaug
  • 478
  • 3
  • 13