diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 43caca20e..55dec7ff4 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1 +1,5 @@ - + + diff --git a/README.md b/README.md index 4ddbe2eb4..da863472e 100644 --- a/README.md +++ b/README.md @@ -115,9 +115,9 @@ Support this project with your organization. Your logo will show up here with a * [Monorepos](#monorepos) * [Node version managers](#node-version-managers) * [Local commands (~/.huskyrc)](#local-commands-huskyrc) - * [Debug](#debug) * [Multiple commands](#multiple-commands) * [Troubleshoot](#troubleshoot) + + [Debug messages](#debug-messages) + [Hooks aren't running](#hooks-arent-running) + [Commits aren't blocked](#commits-arent-blocked) + [Commits are slow](#commits-are-slow) @@ -247,10 +247,6 @@ export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" ``` -### Debug - -Use `HUSKY_DEBUG=1` to log debug messages. - ### Multiple commands By design and just like `scripts` defined in `package.json`, husky will run hook scripts as a single command. @@ -278,6 +274,15 @@ Tools like [npm-run-all](https://github.com/mysticatea/npm-run-all) can help too ### Troubleshoot +#### Debug messages + +`HUSKY_DEBUG=1` can provide additional informations when running commands. + +``` +HUSKY_DEBUG=1 npm install husky --save-dev +HUSKY_DEBUG=1 git commit ... +``` + #### Hooks aren't running Check if hooks were installed. Verify that `.git/hooks/pre-commit` exists and have husky code. It should start with: diff --git a/package.json b/package.json index 85ff7fce9..f008241e0 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "postpublish": "pinst --disable", "lint": "eslint . --ext .js,.ts --ignore-path .gitignore", "fix": "npm run lint -- --fix", + "doc": "markdown-toc -i README.md", "_postinstall": "opencollective-postinstall || exit 0" }, "repository": { diff --git a/src/installer/bin.ts b/src/installer/bin.ts index 8e599dac2..e95887f68 100644 --- a/src/installer/bin.ts +++ b/src/installer/bin.ts @@ -6,8 +6,8 @@ import { install, uninstall } from './' import gitRevParse from './gitRevParse' // Debug -debug(`cwd: ${process.cwd()}`) -debug(`INIT_CWD: ${process.env.INIT_CWD}`) +debug(`Current working directory is '${process.cwd()}'`) +debug(`INIT_CWD environment variable is set to '${process.env.INIT_CWD}'`) // Action can be "install" or "uninstall" // huskyDir is ONLY used in dev, don't use this arguments @@ -33,12 +33,19 @@ try { process.exit(0) } + if (process.env.GIT_DIR) { + debug(`GIT_DIR environment variable is set to '${process.env.GIT_DIR}'.`) + debug( + `Unless it's on purpose, you may want to unset GIT_DIR as it will affect where Git hooks are going to be installed.` + ) + } + // Get top level and git dir const { topLevel, absoluteGitDir } = gitRevParse() - // Debug - debug(`topLevel: ${topLevel}`) - debug(`gitDir: ${absoluteGitDir}`) + debug('Git rev-parse command returned:') + debug(` topLevel: ${topLevel}`) + debug(` absoluteGitDir: ${absoluteGitDir}`) // Install or uninstall if (action === 'install') { diff --git a/src/installer/getScript.ts b/src/installer/getScript.ts index 270bfceec..50b6344eb 100644 --- a/src/installer/getScript.ts +++ b/src/installer/getScript.ts @@ -60,24 +60,24 @@ if [ "$\{HUSKY_SKIP_HOOKS}" = "true" ] || [ "$\{HUSKY_SKIP_HOOKS}" = "1" ]; then fi if [ "$\{HUSKY_USE_YARN}" = "true" ] || [ "$\{HUSKY_USE_YARN}" = "1" ]; then - debug "calling husky through Yarn" + debug "Calling husky through Yarn" yarn husky-run $hookName "$gitParams" else - ${ - platform === 'win32' - ? '' - : ` +${ + 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" fi - ` - } +` +} if [ -f "$scriptPath" ]; then # if [ -t 1 ]; then # exec < /dev/tty # fi if [ -f ${huskyrc} ]; then - debug "source ${huskyrc}" + debug "Sourcing '${huskyrc}'" . ${huskyrc} fi ${node} "$scriptPath" $hookName "$gitParams" diff --git a/src/installer/index.ts b/src/installer/index.ts index 19fb78ae6..db0d6d791 100644 --- a/src/installer/index.ts +++ b/src/installer/index.ts @@ -4,6 +4,7 @@ import pkgDir from 'pkg-dir' import getConf from '../getConf' import getScript from './getScript' import { isGhooks, isHusky, isPreCommit, isYorkie } from './is' +import debug from '../debug' const hookList = [ 'applypatch-msg', @@ -159,6 +160,7 @@ export function install( fs.mkdirSync(gitHooksDir) } + debug(`Installing hooks in '${gitHooksDir}'`) const hooks = getHooks(gitDir) const script = getScript(topLevel, huskyDir, requireRunNodePath) createHooks(hooks, script) diff --git a/src/runner/bin.ts b/src/runner/bin.ts index f70d1c3bb..eff76a191 100644 --- a/src/runner/bin.ts +++ b/src/runner/bin.ts @@ -2,7 +2,7 @@ import index from './' import debug from '../debug' // Debug -debug(`cwd: ${process.cwd()}`) +debug(`Current working directory is '${process.cwd()}'`) // Run hook index(process.argv) diff --git a/src/runner/index.ts b/src/runner/index.ts index 18b0fa68b..c3892697d 100644 --- a/src/runner/index.ts +++ b/src/runner/index.ts @@ -22,7 +22,7 @@ export default async function run( const cwd = path.resolve(scriptPath.split('node_modules')[0]) // Debug - debug(`cwd: ${cwd} (updated)`) + debug(`Changed current working directory to '${cwd}'`) // In some cases, package.json may not exist // For example, when switching to gh-page branch