From 744fb6f07ccd3568c5f984020d0ded8d3d494572 Mon Sep 17 00:00:00 2001 From: losadaem Date: Thu, 1 Jun 2023 13:22:12 -0400 Subject: [PATCH] feat: support git worktrees structure Support git repository structure using commondir file. For reference: https://git-scm.com/docs/gitrepository-layout#Documentation/gitrepository-layout.txt-commondir https://git-scm.com/docs/git-worktree#_details --- simple-git-hooks.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/simple-git-hooks.js b/simple-git-hooks.js index f909846..3b5271f 100644 --- a/simple-git-hooks.js +++ b/simple-git-hooks.js @@ -61,7 +61,13 @@ function getGitProjectRoot(directory=process.cwd()) { let content = fs.readFileSync(fullPath, { encoding: 'utf-8' }) let match = /^gitdir: (.*)\s*$/.exec(content) if (match) { - return path.normalize(match[1]) + let gitDir = match[1] + let commonDir = path.join(gitDir, 'commondir'); + if (fs.existsSync(commonDir)) { + commonDir = fs.readFileSync(commonDir, 'utf8').trim(); + return path.resolve(gitDir, commonDir) + } + return path.normalize(gitDir) } } return path.normalize(fullPath)