Skip to content

Commit 6ca30db

Browse files
Allow absolute core.hooksPath config setting
1 parent 1e2f0ab commit 6ca30db

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

git/repository.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,27 @@ func (r *Repository) HookExists(hook string) bool {
4949
func (r *Repository) HooksDir() string {
5050
if r.hooksDir == "" {
5151
r.hooksDir = r.gitDir + "/hooks"
52-
var hooksPath = r.ConfigValue("core.hooksPath", "")
52+
var hooksPath = r.hooksPath()
5353
if hooksPath != "" {
54-
r.hooksDir = r.root + "/" + hooksPath
54+
r.hooksDir = hooksPath
5555
}
5656
}
5757
return r.hooksDir
5858
}
5959

60+
// hooksPath returns the core.hooksPath configured path
61+
// If the path is relative it will be prefixed with the repository root
62+
func (r *Repository) hooksPath() string {
63+
hooksPath := r.ConfigValue("core.hooksPath", "")
64+
if hooksPath == "" {
65+
return ""
66+
}
67+
if path.IsAbs(hooksPath) {
68+
return hooksPath
69+
}
70+
return r.root + "/" + hooksPath
71+
}
72+
6073
func (r *Repository) CommitMessage(path string) (*types.CommitMessage, error) {
6174
if path == "" {
6275
return nil, errors.New("invalid file path")

0 commit comments

Comments
 (0)