Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions simple-git-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,10 @@ function _getPackageJson(projectPath = process.cwd()) {
* @returns {string}
*/
function _getCustomConfigPath(argv=[]) {
const cmdIdx = argv.findIndex(val => val === 'simple-git-hooks')

if (cmdIdx === -1) return ''

return argv[cmdIdx + 1] || ''
// We'll run as one of the following:
// npx simple-git-hooks ./config.js
// node path/to/simple-git-hooks/cli.js ./config.js
return argv[2] || ''
}

/**
Expand Down Expand Up @@ -311,7 +310,9 @@ function _getConfigFromFile(projectRootPath, fileName) {
}

try {
const filePath = path.normalize(projectRootPath + '/' + fileName)
const filePath = path.isAbsolute(fileName)
? fileName
: path.normalize(projectRootPath + '/' + fileName)
if (filePath === __filename) {
return undefined
}
Expand Down
8 changes: 6 additions & 2 deletions simple-git-hooks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,14 @@ test('creates git hooks and removes unused but preserves specific git hooks', ()
removeGitHooksFolder(projectWithUnusedConfigurationInPackageJsonPath)
})

test('creates git hooks and removes unused but preserves specific git hooks', () => {
test.each([
['npx', 'simple-git-hooks', './git-hooks.js'],
['node', require.resolve(`./cli`), './git-hooks.js'],
['node', require.resolve(`./cli`), require.resolve(`${projectWithCustomConfigurationFilePath}/git-hooks.js`)],
])('creates git hooks and removes unused but preserves specific git hooks for command: %s %s %s', (...args) => {
createGitHooksFolder(projectWithCustomConfigurationFilePath)

spc.setHooksFromConfig(projectWithCustomConfigurationFilePath, ['npx', 'simple-git-hooks', './git-hooks.js'])
spc.setHooksFromConfig(projectWithCustomConfigurationFilePath, args)
const installedHooks = getInstalledGitHooks(path.normalize(path.join(projectWithCustomConfigurationFilePath, '.git', 'hooks')))
expect(JSON.stringify(installedHooks)).toBe(JSON.stringify({'pre-commit':`#!/bin/sh\nexit 1`, 'pre-push':`#!/bin/sh\nexit 1`}))

Expand Down