Skip to content

Commit

Permalink
Don't throw error during uninstall if file doesn't exist (#708)
Browse files Browse the repository at this point in the history
  • Loading branch information
typicode authored Apr 9, 2020
1 parent 4e1d440 commit b1d4c32
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/installer/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,5 +236,14 @@ describe('install', (): void => {
expectHookToExist('.git/hooks/pre-commit')
})

it('should not throw error during uninstall if some files do not exist', (): void => {
writeFile('package.json', pkg)

install()
fs.unlinkSync(path.join(tempDir, '.git/hooks/pre-commit'))
fs.unlinkSync(path.join(tempDir, '.git/hooks/husky.sh'))

expect(uninstall).not.toThrow()
})
hooksManagers.forEach(testMigration)
})
5 changes: 4 additions & 1 deletion src/installer/localScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ export function createLocalScript(
}

export function removeLocalScript(gitHooksDir: string): void {
fs.unlinkSync(path.join(gitHooksDir, 'husky.local.sh'))
const filename = path.join(gitHooksDir, 'husky.local.sh')
if (fs.existsSync(filename)) {
fs.unlinkSync(filename)
}
}
5 changes: 4 additions & 1 deletion src/installer/mainScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ export function createMainScript(gitHooksDir: string): void {
}

export function removeMainScript(gitHooksDir: string): void {
fs.unlinkSync(path.join(gitHooksDir, 'husky.sh'))
const filename = path.join(gitHooksDir, 'husky.sh')
if (fs.existsSync(filename)) {
fs.unlinkSync(filename)
}
}

0 comments on commit b1d4c32

Please sign in to comment.