Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use --git-common-dir #585

Merged
merged 2 commits into from Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/installer/__tests__/gitRevParse.ts
Expand Up @@ -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'
})
})
})
10 changes: 5 additions & 5 deletions src/installer/bin.ts
Expand Up @@ -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`)
Expand Down
13 changes: 7 additions & 6 deletions src/installer/gitRevParse.ts
Expand Up @@ -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
Expand All @@ -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 }
}