Skip to content

Commit

Permalink
Improve debug messages
Browse files Browse the repository at this point in the history
  • Loading branch information
typicode committed Sep 28, 2019
1 parent 391269e commit 3336d84
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 21 deletions.
6 changes: 5 additions & 1 deletion .github/ISSUE_TEMPLATE.md
@@ -1 +1,5 @@
<!-- Love ❤️ husky? Please consider supporting this project by clicking the Sponsor button 🙏 -->
<!--
If you like husky, please consider supporting this project by clicking the Sponsor button :)
Please check the Troubleshoot section in the README and try running commands with HUSKY_DEBUG=1 for additional informations.
-->

15 changes: 10 additions & 5 deletions README.md
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -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": {
Expand Down
17 changes: 12 additions & 5 deletions src/installer/bin.ts
Expand Up @@ -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
Expand All @@ -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') {
Expand Down
16 changes: 8 additions & 8 deletions src/installer/getScript.ts
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions src/installer/index.ts
Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/runner/bin.ts
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/runner/index.ts
Expand Up @@ -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
Expand Down

0 comments on commit 3336d84

Please sign in to comment.