Skip to content

Commit 35b983d

Browse files
author
amazingandyyy
committed
fix path issues
1 parent 0421715 commit 35b983d

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

install.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ function isCI (env) {
1515

1616
function installHook (hook) {
1717
const source = path.join(__dirname, 'hook')
18-
const target = path.join('.git', 'hooks', hook)
19-
if (fs.existsSync(source) && fs.existsSync('.git')) {
18+
19+
// in the postinstall stage
20+
// process.cwd() === __dirname
21+
// so we need to jump up three level here
22+
const root = path.join(__dirname, '../../..');
23+
const target = path.join(root, '.git', 'hooks', hook)
24+
25+
if (fs.existsSync(source) && fs.existsSync(path.join(root, '.git'))) {
2026
if (isCI(process.env)) {
2127
console.log('[git-hooks]', 'CI Environment detected, skip the git-hooks installation')
2228
} else {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@amazingandyyy/git-hooks",
33
"description": "Minimalism's pre-commit, pre-push hooks.",
4-
"version": "0.0.17",
4+
"version": "0.0.30",
55
"author": {
66
"name": "Andy Chen",
77
"email": "amazingandyyy@gmail.com",

uninstall.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
const fs = require('fs')
33
const path = require('path')
44
const HOOKS = require('./hooks')
5-
const hookPathList = HOOKS.map(hook => path.join('.git', 'hooks', hook))
5+
6+
// in the preuninstall stage
7+
// process.cwd() === __dirname
8+
// so we need to jump up three level here
9+
const root = path.join(__dirname, '../../..');
10+
const hookPathList = HOOKS.map(hook => path.join(root, '.git', 'hooks', hook))
611

712
const generatedByGitHooks = '# git-hooks'
813

@@ -18,7 +23,7 @@ function removeHook (hook) {
1823
fs.unlinkSync(hook)
1924
}
2025

21-
if (fs.existsSync('.git')) {
26+
if (fs.existsSync(path.join(root, '.git'))) {
2227
hookPathList.filter(isGeneratedByGitHooks).forEach(removeHook)
2328
} else {
2429
console.log('[git-hooks]', 'No .git folder found, skip git-hooks uninstallation')

0 commit comments

Comments
 (0)