Skip to content

Commit

Permalink
Move HUSKY_SKIP_HOOKS check to shell script (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
typicode committed Jun 5, 2019
1 parent a9f94f0 commit 4942ec4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
26 changes: 21 additions & 5 deletions src/installer/__tests__/__snapshots__/getScript.ts.snap
Expand Up @@ -18,13 +18,21 @@ hookName=\`basename \\"$0\\"\`
gitParams=\\"$*\\"
debug() {
[ \\"\${HUSKY_DEBUG}\\" = \\"true\\" ] || [ \\"\${HUSKY_DEBUG}\\" = \\"1\\" ] && echo \\"husky:debug $1\\"
if [ \\"\${HUSKY_DEBUG}\\" = \\"true\\" ] || [ \\"\${HUSKY_DEBUG}\\" = \\"1\\" ]; then
echo \\"husky:debug $1\\"
fi
}
debug \\"$hookName hook started...\\"
debug \\"$hookName hook started\\"
if [ \\"\${HUSKY_SKIP_HOOKS}\\" = \\"true\\" ] || [ \\"\${HUSKY_SKIP_HOOKS}\\" = \\"1\\" ]; then
debug \\"HUSKY_SKIP_HOOKS is set to \${HUSKY_SKIP_HOOKS}, skipping hook\\"
exit 0
fi
if ! command -v node >/dev/null 2>&1; then
echo \\"Info: Can't find node in PATH, trying to find a node binary on your system\\"
echo \\"Info: can't find node in PATH, trying to find a node binary on your system\\"
fi
if [ -f \\"$scriptPath\\" ]; then
Expand Down Expand Up @@ -61,10 +69,18 @@ hookName=\`basename \\"$0\\"\`
gitParams=\\"$*\\"
debug() {
[ \\"\${HUSKY_DEBUG}\\" = \\"true\\" ] || [ \\"\${HUSKY_DEBUG}\\" = \\"1\\" ] && echo \\"husky:debug $1\\"
if [ \\"\${HUSKY_DEBUG}\\" = \\"true\\" ] || [ \\"\${HUSKY_DEBUG}\\" = \\"1\\" ]; then
echo \\"husky:debug $1\\"
fi
}
debug \\"$hookName hook started...\\"
debug \\"$hookName hook started\\"
if [ \\"\${HUSKY_SKIP_HOOKS}\\" = \\"true\\" ] || [ \\"\${HUSKY_SKIP_HOOKS}\\" = \\"1\\" ]; then
debug \\"HUSKY_SKIP_HOOKS is set to \${HUSKY_SKIP_HOOKS}, skipping hook\\"
exit 0
fi
if [ -f \\"$scriptPath\\" ]; then
# if [ -t 1 ]; then
Expand Down
14 changes: 11 additions & 3 deletions src/installer/getScript.ts
Expand Up @@ -47,16 +47,24 @@ hookName=\`basename "$0"\`
gitParams="$*"
debug() {
[ "$\{HUSKY_DEBUG}" = "true" ] || [ "$\{HUSKY_DEBUG}" = "1" ] && echo "husky:debug $1"
if [ "$\{HUSKY_DEBUG}" = "true" ] || [ "$\{HUSKY_DEBUG}" = "1" ]; then
echo "husky:debug $1"
fi
}
debug "$hookName hook started..."
debug "$hookName hook started"
if [ "$\{HUSKY_SKIP_HOOKS}" = "true" ] || [ "$\{HUSKY_SKIP_HOOKS}" = "1" ]; then
debug "HUSKY_SKIP_HOOKS is set to $\{HUSKY_SKIP_HOOKS}, skipping hook"
exit 0
fi
${
platform === 'win32'
? ''
: `
if ! command -v node >/dev/null 2>&1; then
echo "Info: Can't find node in PATH, trying to find a node binary on your system"
echo "Info: can't find node in PATH, trying to find a node binary on your system"
fi
`
}
Expand Down
12 changes: 0 additions & 12 deletions src/runner/index.ts
Expand Up @@ -7,7 +7,6 @@ import getConf from '../getConf'
export interface Env extends NodeJS.ProcessEnv {
HUSKY_GIT_STDIN?: string
HUSKY_GIT_PARAMS?: string
HUSKY_SKIP_HOOKS?: string
}

/**
Expand All @@ -18,17 +17,6 @@ export default async function run(
[, scriptPath, hookName = '', HUSKY_GIT_PARAMS]: string[],
getStdinFn: () => Promise<string> = getStdin
): Promise<number> {
if (
process.env.HUSKY_SKIP_HOOKS === 'true' ||
process.env.HUSKY_SKIP_HOOKS === '1'
) {
console.log(
"HUSKY_SKIP_HOOKS environment variable is set to 'true',",
'skipping running Git hooks.'
)
return 0
}

const cwd = path.resolve(scriptPath.split('node_modules')[0])
// In some cases, package.json may not exist
// For example, when switching to gh-page branch
Expand Down

0 comments on commit 4942ec4

Please sign in to comment.