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..b8921ad49 100644 --- a/src/installer/gitRevParse.ts +++ b/src/installer/gitRevParse.ts @@ -3,15 +3,16 @@ import execa from 'execa' export default function(): { topLevel: string - absoluteGitDir: string + gitCommonDir: string } { + // https://github.com/typicode/husky/issues/580 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 +21,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 } }