I am writing a Git post-receive hook, and within the hook script, I need the absolute path of the project directory (i.e. the directory of the repository). What is a reliable way to do this that works for both non-bare and bare repositories?
From my understanding, if the repository is bare (which I can check using git rev-parse --is-bare-repository
), the absolute path can be obtained using pwd
. If the repository is not bare, how can I reliably obtain the absolute path of the repository? Is it dirname "$(pwd)"
? Is this method reliable?