diff options
Diffstat (limited to 'git-codereview/hook.go')
| -rw-r--r-- | git-codereview/hook.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/git-codereview/hook.go b/git-codereview/hook.go index 1913666..8bf2a51 100644 --- a/git-codereview/hook.go +++ b/git-codereview/hook.go @@ -76,10 +76,26 @@ func installHook(args []string) { } } +// repoRoot returns the root of the currently selected git repo, or +// worktree root if this is an alternate worktree of a repo. func repoRoot() string { return filepath.Clean(trim(cmdOutput("git", "rev-parse", "--show-toplevel"))) } +// gitPathDir returns the directory used by git to store temporary +// files such as COMMIT_EDITMSG, FETCH_HEAD, and such for the repo. +// For a simple git repo, this will be <root>/.git, and for an +// alternate worktree of a repo it will be in +// <root>/.git/worktrees/<worktreename>. +func gitPathDir() string { + gcd := trim(cmdOutput("git", "rev-parse", "--git-path", ".")) + result, err := filepath.Abs(gcd) + if err != nil { + dief("%v", err) + } + return result +} + // gitPath resolve the $GIT_DIR/path, taking in consideration // all other path relocations, e.g. hooks for linked worktrees // are not kept in their gitdir, but shared in the main one. |
