Skip to content

Commit

Permalink
Create .git/hooks if doesn't exist (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
luiscoms authored and typicode committed Oct 1, 2018
1 parent 075c644 commit f09ce83
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# CHANGELOG

## Unreleased

* Create .git/hooks if doesn't exist

## 1.0.1

* Various `husky-upgrade` changes ([#362](https://github.com/typicode/husky/pull/362), [#360](https://github.com/typicode/husky/pull/360), [#359](https://github.com/typicode/husky/pull/359))
Expand Down
15 changes: 14 additions & 1 deletion src/installer/__tests__/index.ts
Expand Up @@ -28,7 +28,7 @@ function uninstallFrom(dir: string) {
}

function mkdir(dir: string) {
mkdirp.sync(path.join(tempDir, dir))
return mkdirp.sync(path.join(tempDir, dir))
}

function writeFile(filename: string, data: string) {
Expand Down Expand Up @@ -307,4 +307,17 @@ describe('install', () => {

expect(() => installFrom(huskyDir)).not.toThrow()
})

it("should install even .git/hooks doesn't exist", () => {
const huskyDir = 'node_modules/husky'
const hookFilename = '.git/hooks/pre-commit'

mkdir('.git')
mkdir(huskyDir)
writeFile('package.json', pkg)

installFrom(huskyDir)
expect(exists(hookFilename)).toBeTruthy()
expectHookToExist(hookFilename)
})
})
11 changes: 1 addition & 10 deletions src/installer/index.ts
Expand Up @@ -174,16 +174,7 @@ export function install(
}

if (!fs.existsSync(path.join(resolvedGitDir, 'hooks'))) {
console.log(
`Can't find hooks directory in ${resolvedGitDir}, skipping Git hooks installation.`
)
console.log(
`Please create ${path.join(
resolvedGitDir,
'hooks'
)} directory and reinstall husky.`
)
return
fs.mkdirSync(path.join(resolvedGitDir, 'hooks'))
}

// Create hooks
Expand Down

0 comments on commit f09ce83

Please sign in to comment.