Skip to content

Commit

Permalink
Fix hook installation when in a git worktree
Browse files Browse the repository at this point in the history
In a git worktree .git is actually a file that points to the location
of the woktree .git directory.  To get the right location for commit
hook installation the --git-common-dir flag needs to be used instead.

commit-id:e3cb2587
  • Loading branch information
mstory21 authored and Eitan Joffe committed Mar 4, 2022
1 parent 0b77af6 commit a8d0e08
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions hook/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
)

const (
hookPath = ".git/hooks/commit-msg"
hookPath = "hooks/commit-msg"
)

func InstallCommitHook(cfg *config.Config, gitcmd git.GitInterface) {
var rootdir string
err := gitcmd.Git("rev-parse --show-toplevel", &rootdir)
err := gitcmd.Git("rev-parse --git-common-dir", &rootdir)
check(err)
rootdir = strings.TrimSpace(rootdir)
err = os.Chdir(rootdir)
Expand Down

0 comments on commit a8d0e08

Please sign in to comment.