From 904aeb81623a493947ce55f95ac486756720dbd9 Mon Sep 17 00:00:00 2001 From: typicode Date: Sat, 28 Sep 2019 04:41:12 +0200 Subject: [PATCH 1/2] Use git-common-dir --- src/installer/__tests__/gitRevParse.ts | 4 ++-- src/installer/bin.ts | 10 +++++----- src/installer/gitRevParse.ts | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/installer/__tests__/gitRevParse.ts b/src/installer/__tests__/gitRevParse.ts index 794f42eb7..e7c703036 100644 --- a/src/installer/__tests__/gitRevParse.ts +++ b/src/installer/__tests__/gitRevParse.ts @@ -5,12 +5,12 @@ import gitRevParse from '../gitRevParse' const root = path.join(__dirname, '../../..') describe('gitRevParse', (): void => { - it('should return topLevel and absoluteGitDir', (): void => { + it('should return topLevel and gitCommonDir', (): void => { expect(gitRevParse()).toStrictEqual({ // Git rev-parse uses a different separator on Linux/MacOS and Windows // slash is used to normalized the returned value for tests topLevel: slash(root), - absoluteGitDir: slash(path.join(root, '.git')) + gitCommonDir: '.git' }) }) }) diff --git a/src/installer/bin.ts b/src/installer/bin.ts index e95887f68..a603d741a 100644 --- a/src/installer/bin.ts +++ b/src/installer/bin.ts @@ -41,17 +41,17 @@ try { } // Get top level and git dir - const { topLevel, absoluteGitDir } = gitRevParse() + const { topLevel, gitCommonDir } = gitRevParse() debug('Git rev-parse command returned:') - debug(` topLevel: ${topLevel}`) - debug(` absoluteGitDir: ${absoluteGitDir}`) + debug(` --show-top-level: ${topLevel}`) + debug(` --git-common-dir: ${gitCommonDir}`) // Install or uninstall if (action === 'install') { - install(topLevel, absoluteGitDir, huskyDir, isCI) + install(topLevel, gitCommonDir, huskyDir, isCI) } else { - uninstall(absoluteGitDir, huskyDir) + uninstall(gitCommonDir, huskyDir) } console.log(`husky > Done`) diff --git a/src/installer/gitRevParse.ts b/src/installer/gitRevParse.ts index 91689620c..8a0503200 100644 --- a/src/installer/gitRevParse.ts +++ b/src/installer/gitRevParse.ts @@ -3,15 +3,15 @@ import execa from 'execa' export default function(): { topLevel: string - absoluteGitDir: string + gitCommonDir: string } { const result = execa.sync('git', [ 'rev-parse', '--show-toplevel', - '--absolute-git-dir' + '--git-common-dir' ]) - const [topLevel, absoluteGitDir] = result.stdout + const [topLevel, gitCommonDir] = result.stdout .trim() .split('\n') // Normalize for Windows @@ -20,9 +20,9 @@ export default function(): { // Git rev-parse returns unknown options as is. // If we get --absolute-git-dir in the output, // it probably means that an older version of Git has been used. - if (absoluteGitDir === '--absolute-git-dir') { - throw new Error('Husky requires Git >= 2.13.2, please update Git') + if (gitCommonDir === '--git-common-dir') { + throw new Error('Husky requires Git >= 2.5.1, please update Git') } - return { topLevel, absoluteGitDir } + return { topLevel, gitCommonDir } } From 583df6badf452ee46f379028a2a9d5bbe196fc25 Mon Sep 17 00:00:00 2001 From: typicode Date: Tue, 1 Oct 2019 04:33:22 +0200 Subject: [PATCH 2/2] Ref GitHub issue --- src/installer/gitRevParse.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/installer/gitRevParse.ts b/src/installer/gitRevParse.ts index 8a0503200..b8921ad49 100644 --- a/src/installer/gitRevParse.ts +++ b/src/installer/gitRevParse.ts @@ -5,6 +5,7 @@ export default function(): { topLevel: string gitCommonDir: string } { + // https://github.com/typicode/husky/issues/580 const result = execa.sync('git', [ 'rev-parse', '--show-toplevel',