Git rev-parse - git -path-hooks always return absolute path

Is there an equivalent command for this that always returns the absolute path?

git rev-parse --git-path hooks

      

When I am in a submodule I get the absolute path, but when I am in the root repository I get

.git / Hooks

+3


source to share


1 answer


Git v2.13.0 has --absolute-git-dir

:

$ git rev-parse --absolute-git-dir
/Users/torek/...snip.../.git

      

but not --absolute-git-path

, and, as you noticed, --git-path

produces a relative result:

$ git rev-parse --git-path hooks
.git/hooks

      

If you have Git 2.13, you can combine them by prefixing the sh / bash environment variable:



$ GIT_DIR=$(git rev-parse --absolute-git-dir) git rev-parse --git-path hooks
/Users/torek/...[snip].../.git/hooks

      

If not - if your Git is older than 2.13, you can use readlink -f

:

$ GIT_DIR=$(readlink -f $(git rev-parse --git-dir)) git rev-parse --git-path hooks
/home/vagrant/...snip.../.git/hooks

      

(on a specific Linux image on my laptop, this Linux image has Git 2.7.4 installed).

+2


source







All Articles