Skip to content

Commit 4b3b62b

Browse files
committed
fix: custom config via absolute path
1 parent f407cef commit 4b3b62b

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

simple-git-hooks.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,9 @@ function _getConfigFromFile(projectRootPath, fileName) {
310310
}
311311

312312
try {
313-
const filePath = path.normalize(projectRootPath + '/' + fileName)
313+
const filePath = path.isAbsolute(fileName)
314+
? fileName
315+
: path.normalize(projectRootPath + '/' + fileName)
314316
if (filePath === __filename) {
315317
return undefined
316318
}

simple-git-hooks.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,13 @@ test('creates git hooks and removes unused but preserves specific git hooks', ()
263263
})
264264

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

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

0 commit comments

Comments
 (0)