How to get project path in hook script post-commit? (git)

I want to call Script, which is in the repository.

I could, of course, do the following:

#!/bin/sh ../../myscript.sh 

but I think this is not nice;)

so how do i get the path to my project in a post-commit script?

+7
source share
1 answer

When you are dealing with a non-bare repository, the post-commit 1 hook is launched with the current working directory of the repository working tree. So you do not need ../../ .

If you want the full path to the script, you can always do:

 SCRIPT=$(readlink -nf myscript.sh) 

... or you can use git rev-parse --show-toplevel to get the absolute path to the working directory:

 SCRIPT=$(git rev-parse --show-toplevel)/myscript.sh 

1 ... but note that this does not apply to some other hooks, for example. in a post-receive chain in a non-bare repository, the current working directory is a .git directory.

+15
source

All Articles