Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

git rev-parse --git-path hooks

When I'm in a submodule, I get an absolute path, but when I'm in the root repository, I get

.git/hooks

like image 532
Scotty H Avatar asked Jun 30 '17 22:06

Scotty H


1 Answers

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 note, --git-path produces a relative result:

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

If you do have Git 2.13, though, you can combine these using the sh/bash environment variable prefix method:

$ 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

(in a certain Linux image on my laptop; this particular Linux image has Git 2.7.4 installed).

like image 141
torek Avatar answered Sep 22 '22 23:09

torek