Giter Club home page Giter Club logo

husky's Introduction

husky

Node.js CI

Modern native Git hooks made easy

Husky improves your commits and more 🐢 woof!

Features

  • Just 2 kB (πŸ“¦ gzipped) with no dependencies
  • Extremely fast (runs in ~1ms)
  • Uses new Git feature (core.hooksPath)
  • Supports:

And more:

  • Branch-specific hooks
  • Use POSIX shell to script advanced cases
  • Adheres to Git's native hook organization
  • Aligns with npm best practices using prepare script
  • Opt-in/opt-out options
  • User-friendly error messages

Changelog

Check out the v9 changelog to discover all the new and improved features!

Documentation

https://typicode.github.io/husky

Important Upgrading from v4 to v9 requires migrating previous config, please see the docs.

Sponsors

Support this project by becoming a sponsor here πŸ’–

Special Sponsor


Get rewards for your open-source contributions

GitHub

Open Collective

husky's People

Contributors

afc163 avatar amilajack avatar arcanis avatar boxfoot avatar branneman avatar chalkygames123 avatar dependabot[bot] avatar fearphage avatar greatislander avatar hunnble avatar hyperupcall avatar jamiehaywood avatar jetersen avatar meetmangukiya avatar mokhajavi75 avatar nathanpovo avatar nihaals avatar nilswindisch avatar noamokman avatar onbjerg avatar ozzywalsh avatar piperchester avatar pnodet avatar pombam avatar rainboxx avatar rakleed avatar rozbo avatar sibiraj-s avatar spoike avatar typicode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

husky's Issues

0.8.1 breaks on a git submodule

$ git commit -m "Test"
/src/web-dev/.git/modules/web-tools/hooks/pre-commit: 5: cd: can't cd to ../../web-tools

Where the project structure is:

  • /src/web-dev - git repo with multiple git submodules
  • /src/web-dev/web-tools - one of such git submodules which contains a package.json and where husky is installed in node_modules

Which Git Hooks are supported?

From reading the README I thought Husky would support all Git Hooks. So I tried postmerge but it seems, that it doesn't work. So I looked into .git/hooks/ and if I read the source correctly Husky only supports precommit and prepush. Is this true? Will you add support for more hooks?

Use case: run npm install after every postmerge.

Error on (re)install

When running npm install the git hooks are set up.

After removing node_modules and running npm install I get the following error

setting up hooks in .git/hooks
fs.js:922
  return binding.mkdir(pathModule._makeLong(path),
                 ^

Error: EEXIST: file already exists, mkdir '/<MY_PROJECT>/.git/hooks'
    at Error (native)
    at Object.fs.mkdirSync (fs.js:922:18)
    at Object.create (/<MY_PROJECT>/node_modules/husky/src/index.js:123:33)
    at /<MY_PROJECT>/node_modules/husky/bin/install.js:22:13
    at Array.forEach (native)
    at /<MY_PROJECT>/node_modules/husky/bin/install.js:20:11
    at /<MY_PROJECT>/node_modules/husky/src/index.js:17:9
    at ChildProcess.exithandler (child_process.js:197:7)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)

# ... install tree

npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/bin/iojs" "/usr/local/bin/npm" "i"
npm ERR! node v6.6.0
npm ERR! npm  v3.10.3
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `node ./bin/install.js`
npm ERR! Exit status 1

postcheckout hook never exits during interactive rebase

I've been struggling to resolve a problem with a postcheckout hook that is running during an git interactive rebase.

The symptoms of the problem are very obvious:

  • git rebase somesha -i
  • select that you want to reword one of the commit messages
  • confirm your answers (in my case I'm rewording one of the commit messages)
  • ... wait, wait, wait... give up waiting for the text editor to appear to prompt me to edit the commit message

This happens even for the simplest of postcheckout hooks.

For testing purposes I wrote the following hook which fails as described above:

package.json:

  "postcheckout": "node scripts/clean.js"

scripts/clean.js:

  process.exitCode = 0;

My setup is as follows:

Any pointers as to what I need to do to get the postcheckout hook to exit so that the interactive rebase can continue?

Thanks
Christian

how to get git params

hi.
i want to prevent git push when branch name match the regular expression.
so, the question is, how can i get the command cli param.
e.g: git push publish/0.0.4, the string 'publish/0.0.4' is what is want.

Ignore unstaged changes (precommit)

I'm not submitting PRs for this because I wanted to talk about things first.

When running git commit ./some-path I don't necessarily commit all the changes in my working copy - but the scripts invoked on pre-commit don't know that. They will run on the current state my FS sees, not what I'm actually committing.

The common workaround is to save a diff, reset to head, run the tests and then re-apply the diff as can be seen here. Maybe switching between the two behaviors could be made "configurable", simply by running "npm run precommit" on everything and "npm run precommit:staged" on what is really about to be committed?

While already meddling with this, how about providing a list of actually changed resources, so that a linter wouldn't have to check the entire source directory, if only one file got changed. extracting that info seems easy - but I have no idea how best to pipe it into a script.

I'm not sure if any of this applies to any hook but pre-commit (possibly post-commit).

post-rewrite and pre-rebase hooks

Hey! Thanks for building husky. It's a great idea :)

It would be great if those 2 hooks where added if possible. Can't fully switch to husky at the moment.

For now we are using a script to install the hooks. Just found husky and decided to give it a go.

Thanks

"nvm set default" vs. "nvm use"

Hello all,

I'm having this issue since version 0.11.0 (commit 11ae323)

I work on a project that relies on different Node.js versions. My default nvm version is set to 0.10.42, and then I use nvm use to switch to the other version, v4.3.0.

However, husky will always use the default version instead of the one currently in use by nvm. Which works fine whenever I'm working on a 0.10.42 project, but won't work so smooth when I'm working on v4.3.0.

Example:

πŸ• git push
npm WARN deprecated This version of npm lacks support for important features,
npm WARN deprecated such as scoped packages, offered by the primary npm
npm WARN deprecated registry. Consider upgrading to at least npm@2, if not the
npm WARN deprecated latest stable version. To upgrade to npm@2, run:
npm WARN deprecated
npm WARN deprecated   npm -g install npm@latest-2
npm WARN deprecated
npm WARN deprecated To upgrade to the latest stable version, run:
npm WARN deprecated
npm WARN deprecated   npm -g install npm@latest
npm WARN deprecated
npm WARN deprecated (Depending on how Node.js was installed on your system, you
npm WARN deprecated may need to prefix the preceding commands with `sudo`, or if
npm WARN deprecated on Windows, run them from an Administrator prompt.)
npm WARN deprecated
npm WARN deprecated If you're running the version of npm bundled with
npm WARN deprecated Node.js 0.10 LTS, be aware that the next version of 0.10 LTS
npm WARN deprecated will be bundled with a version of npm@2, which has some small
npm WARN deprecated backwards-incompatible changes made to `npm run-script` and
npm WARN deprecated semver behavior.

> [***]@2.0.0 prepush [***]
> gulp test

[12:52:25] Using gulpfile [***]/gulpfile.js
[12:52:25] Starting 'pre-test'...
[12:52:26] Finished 'pre-test' after 659 ms
[12:52:26] Starting 'test'...
dyld: lazy symbol binding failed: Symbol not found: _node_module_register
  Referenced from: [***]/node_modules/bunyan/node_modules/dtrace-provider/build/Release/DTraceProviderBindings.node
  Expected in: dynamic lookup

dyld: Symbol not found: _node_module_register
  Referenced from: [***]/node_modules/bunyan/node_modules/dtrace-provider/build/Release/DTraceProviderBindings.node
  Expected in: dynamic lookup

.git/hooks/pre-push: line 9: 35011 Trace/BPT trap: 5       npm run prepush

husky - pre-push hook failed (add --no-verify to bypass)

error: failed to push some refs to '[***]'

Is this intended functionality? If so, does anybody know of a way to solve this without having to use nvm set default all the time, instead of nvm use?

Best regards,
Arturo

Update hook is in the wrong directory

Thanks for this great npm. Pre-commit works great, but having issue with an update hook.

I added some echo statements to .git/hooks/update and it looks like pwd is showing project/.git instead of project:

so the following at .git/hooks/update is on the remote (Ubuntu) and is correctly triggered after a git push from my local:

#!/bin/sh
# husky
cd .
echo $(pwd) 
[ -f package.json ] && cat package.json | grep -q '"update"\s*:'
[ $? -ne 0 ] && exit 0

however the echo above shows /home/ubuntu/project/.git

$ git push -f [email protected]:/home/user/project HEAD:develop       
remote: /home/user/project/.git    

Not sure why the dir is different in this case and what the best fix would be that wouldn't affect the other hooks.

Manually changing cd . to cd .. fixes the issue for this hook, but I assume it would break the others.

Install issue on non-git environments

Husky couldn't detect our Jenkins CD environment because the BUILD_NUMBER env variable was not present and failed to install. Why not just checking if the .git directory exists?

v0.10.0: gulp is trying to use β€œorigin” as a task

Hi,

after updating to v0.10.0, I have a weird behavior in my prepush hook which is the following:

{
  "scripts": {
    "prepush": "gulp --gulpfile gulpfile.js test:build"
  }
}

Where test:build is the name of gulp task. When I run it as npm run prepush, everything is fine. But when husky is running it on git push origin master, I have the following error:

[10:34:31] Using gulpfile ~/*PROJECT_DIRECTORY*/gulpfile.js
[10:34:31] Task never defined: origin
[10:34:31] Please check the documentation for proper gulpfile formatting

husky - pre-push hook failed (add --no-verify to bypass)

Which means that for some reason I have origin parameter leaked into npm script and it's trying to find gulp task named origin. Probably it's because of this commit?

Error: failed to push some refs to 'git@repo'

❯ node -v
v0.10.33

❯ npm -v
2.1.8

❯ npm i husky

> [email protected] install /Users/maxvipon/Projects/datef/node_modules/husky
> node ./bin/install.js

husky
  setting up hooks in .git/hooks/
  done

[email protected] node_modules/husky

❯ git push origin master

husky - pre-push hook failed (add -n to bypass)

error: failed to push some refs to '[email protected]:maxvipon/datef.git'

❯ git push -n origin master

husky - pre-push hook failed (add -n to bypass)

error: failed to push some refs to '[email protected]:maxvipon/datef.git'

❯ cat package.json
{
  ...
  "scripts": {
    "precommit": "grunt lint"
  }
}

# googling…

❯ git push origin master --no-verify
# works!

[Windows] npm: command not found

I've run this to install husky:

$ npm i husky --save-dev
npm http GET https://registry.npmjs.org/husky
npm http 304 https://registry.npmjs.org/husky

> [email protected] install C:\Users\bvandermeer\Source\_\current-processes\node_modules\husky
> node ./bin/install.js

husky
  setting up hooks in .git/hooks/
  done

[email protected] node_modules\husky

I've added this in my package.json:

{
  "scripts": {
    "precommit": "node test.js"
  }
}

This is the contents of test.js:

console.log('FAILED');
process.exit(-1);

And when I try to commit I get this error:

$ git add package.json
$ git commit -m 'Added husky'
.git/hooks/pre-commit: line 4: npm: command not found

husky - pre-commit hook failed (add -n to bypass)

This is the PATH variable inside the file .git/hooks/pre-commit, that husky added:

PATH="c:\Users\bvandermeer\.nodist\bin\node_modules\npm\bin\node-gyp-bin;c:\Users\bvandermeer\Source\_\current-processes\node_modules\husky\node_modules\.bin;c:\Users\bvandermeer\Source\_\current-processes\node_modules\.bin;C:\Users\bvandermeer\.nodist\bin\;C:\Program Files\ImageMagick-6.8.9-Q16;C:\Program Files\Python27\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Apache24\bin;C:\Program Files (x86)\Git\cmd;C:\Program Files (x86)\Windows Imaging\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft Windows Performance Toolkit\;C:\Program Files (x86)\svn-win32-1.7.10\bin;C:\users\bvandermeer\strawberry-perl\c\bin;C:\users\bvandermeer\strawberry-perl\perl\site\bin;C:\users\bvandermeer\strawberry-perl\perl\bin;C:\Program Files\WinRAR\;C:\Program Files\MongoDB\bin;C:\Program Files (x86)\scala\\bin;C:\Users\bvandermeer\.nodist\bin;C:\Program Files\dart\dart-sdk\bin;C:\Ruby200\bin;C:\Program Files (x86)\WinAnt\bin;C:\Program Files (x86)\Git\bin;C:\Program Files\Java\jre7\bin;C:\Program Files\nssm;C:\Program Files\Oracle\VirtualBox"

And here are the paths as a list:

  • c:\Users\bvandermeer\.nodist\bin\node_modules\npm\bin\node-gyp-bin
  • c:\Users\bvandermeer\Source\_\current-processes\node_modules\husky\node_modules\.bin
  • c:\Users\bvandermeer\Source\_\current-processes\node_modules\.bin
  • C:\Users\bvandermeer\.nodist\bin\
  • C:\Program Files\ImageMagick-6.8.9-Q16
  • C:\Program Files\Python27\
  • C:\WINDOWS\system32
  • C:\WINDOWS
  • C:\WINDOWS\System32\Wbem
  • C:\WINDOWS\System32\WindowsPowerShell\v1.0\
  • C:\Program Files (x86)\Apache24\bin
  • C:\Program Files (x86)\Git\cmd
  • C:\Program Files (x86)\Windows Imaging\
  • C:\Program Files\Microsoft SQL Server\110\Tools\Binn\
  • C:\Program Files\Microsoft Windows Performance Toolkit\
  • C:\Program Files (x86)\svn-win32-1.7.10\bin
  • C:\users\bvandermeer\strawberry-perl\c\bin
  • C:\users\bvandermeer\strawberry-perl\perl\site\bin
  • C:\users\bvandermeer\strawberry-perl\perl\bin
  • C:\Program Files\WinRAR\
  • C:\Program Files\MongoDB\bin
  • C:\Program Files (x86)\scala\bin
  • C:\Users\bvandermeer\.nodist\bin
  • C:\Program Files\dart\dart-sdk\bin
  • C:\Ruby200\bin
  • C:\Program Files (x86)\WinAnt\bin
  • C:\Program Files (x86)\Git\bin
  • C:\Program Files\Java\jre7\bin
  • C:\Program Files\nssm
  • C:\Program Files\Oracle\VirtualBox

And in the case of Nodist, my npm executable (npm.cmd on windows), is actually located here: C:\Users\bvandermeer\.nodist\bin, which is actually twice in the PATH variable. But I don't understand why it doesn't work.

Temporary solution

If I comment the PATH="..." line from the file .git/hooks/pre-commit, it actually works, the output is then:

$ git commit -m 'Added husky'
FAILED

husky - pre-commit hook failed (add -n to bypass)

So, when I created pull/#5, I was trying to fix this problem. This is the commit you decided not to merge, which makes it fail on Windows: branneman@89b13e2

But as you've said before, removing the PATH makes it fail on OSX. So we need a another solution thats cross platform.

npm installation fails using Git Bash on Windows 8

Trying to install husky via npm using Git Bash:

$ npm install husky --save-dev

fails.

npm WARN continuing anyway [email protected] uninstall: `./bin/uninstall.js`
npm WARN continuing anyway Exit status 1
npm ERR! [email protected] install: `./bin/install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the husky package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     ./bin/install.js
npm ERR! You can get their info via:
npm ERR!     npm owner ls husky
npm ERR! There is likely additional logging output above.

The additional logging output is in German in my case, but roughly translates to:

> [email protected] install c:\Users\foo\bar\node_modules\husky
> ./bin/install.js

Command "." is either misspelled or could not be found.

> [email protected] uninstall c:\Users\foo\bar\node_modules\husky
> ./bin/uninstall.js

Command "." is either misspelled or could not be found.

how to setting up?

By using readme.md i install husky npm install husky --save-dev
then i add precommit and prepush hooks to npm.

Now I try to do commits

but hooks not works.

what am I doing wrong?

Slow to execute

Really digging this repo, but there's a noticeable delay running through the hooks, even ones that you haven't specified (ex. git commit when you only have a prepush). Do you think this is something that could be sped up?

Code changes on precommit

Hi, not sure this is an issue with this module or maybe it's just how git works.
I'm trying to automate package.json version bumping before every commit.

I installed uver-cli in devDependencies, it's just a module that bumps the version.
Then:

{
  "scripts": {
    "precommit":"uver"
  }
}

It was effectively called but the version bump was left as an uncommited change.

Shouldn't precommit be able to change code? Is there another hook that should? Maybe it's something wrong with my code?

Thanks

Pass hook parameters through to scripts

By default, git passes a variety of parameters through to its hooks. This lets you do things like write a post-checkout hook that knows which branch it switched from and can compare what changed.

Currently, husky strips those parameters out, but it would be handy (and helpful) if the parameters were passed through using syntax for optional parameters to npm run.

Don't pollute enclosing project hooks

I just ran npm install on a package within my project's node_modules. This package has husky listed as a devDependency. husky ended up writing hooks into my project's .git/hooks, instead of the package within node_modules. Now I can't commit code in my own project without removing the hooks / --no-verifying.

Thank you

Not actually an issue, but Thank you for husky. Had issues with ghooks was referred here, setup and commit hooks seamless. ! Awesome work πŸ‘πŸΌ πŸ‘πŸΌ πŸ‘πŸΌ ✨

Prepare Commit Message existing hook

I am trying to use Husky for a project. But the problem is that I have several git hooks which are really specific and I still want to run them using bash.

I tried, but it seems they are not taking the parameters. Are there a way to keep using the existing hooks plus the ones on the package.json?

can't commit from smartgit on ubuntu

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/nodejs', '/usr/bin/npm', 'run', 'precommit' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'precommit' ]
5 info lifecycle @~precommit: @
6 verbose lifecycle @~precommit: unsafe-perm in lifecycle true
7 verbose lifecycle @~precommit: PATH: /usr/lib/node_modules/npm/bin/node-gyp-bin:/home/cotne/Documents/api.myvideo/node_modules/.bin:/usr/lib/git-core:/home/cotne/bin:/home/cotne/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
8 verbose lifecycle @~precommit: CWD: /home/cotne/Documents/api.myvideo
9 silly lifecycle @~precommit: Args: [ '-c', 'tasker lint' ]
10 info lifecycle @~precommit: Failed to exec precommit script
11 verbose stack Error: @ precommit: `tasker lint`
11 verbose stack spawn ENOENT
11 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/lib/utils/spawn.js:33:16)
11 verbose stack     at emitTwo (events.js:106:13)
11 verbose stack     at ChildProcess.emit (events.js:191:7)
11 verbose stack     at maybeClose (internal/child_process.js:877:16)
11 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
12 verbose pkgid @
13 verbose cwd /home/cotne/Documents/api.myvideo
14 error Linux 4.4.0-53-generic
15 error argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "precommit"
16 error node v6.9.1
17 error npm  v4.0.3
18 error file sh
19 error code ELIFECYCLE
20 error errno ENOENT
21 error syscall spawn
22 error @ precommit: `tasker lint`
22 error spawn ENOENT
23 error Failed at the @ precommit script 'tasker lint'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the  package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error     tasker lint
23 error You can get information on how to open an issue for this project with:
23 error     npm bugs
23 error Or if that isn't available, you can get their info via:
23 error     npm owner ls
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]

i think cwd is wrong here

works if i commit from terminal

cd path incorrect on Windows systems

When installing on Windows systems, husky creates hooks with cd paths as follows:

#!/bin/sh
# husky
cd directory\subdirectory\package_directory
[ -f package.json ] && cat package.json | grep -q '"precommit"\s*:'
[ $? -ne 0 ] && exit 0
npm run precommit --silent
if [ $? -ne 0 ]; then
  echo
  echo "husky - pre-commit hook failed (add --no-verify to bypass)"
  echo
  exit 1
fi

where the cd paths should be

#!/bin/sh
# husky
cd directory/subdirectory/package_directory
[ -f package.json ] && cat package.json | grep -q '"precommit"\s*:'
[ $? -ne 0 ] && exit 0
npm run precommit --silent
if [ $? -ne 0 ]; then
  echo
  echo "husky - pre-commit hook failed (add --no-verify to bypass)"
  echo
  exit 1
fi

Using back-slashes in the file path escapes characters instead of separating them with a slash, this stops husky from finding the package.json file which, in turn, stops husky working. I'm guessing this is a Windows vs. UNIX issue, the cd path needs to be sanitized and back-slashes replaced with forward-slashes on Windows

fatal: Not a git repository

Hello,

I am trying to install husky inside a docker container that has a host directory mounted as a data volume.

Apparently, the working directory is set to ./node_modules/husky instead of . so hooksDir fails:

root@f5412bf9a01f:/usr/src/web# npm install husky --save-dev
-
> [email protected] install /usr/src/web/node_modules/husky
> node ./bin/install.js

husky
setting up hooks in .git/hooks
  fatal: Not a git repository (or any parent up to mount point /usr/src/web/node_modules)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

[email protected] node_modules/husky
β”œβ”€β”€ [email protected]
└── [email protected]
root@f5412bf9a01f:/usr/src/web# pwd
/usr/src/web
root@f5412bf9a01f:/usr/src/web# git rev-parse --git-dir
.git
root@f5412bf9a01f:/usr/src/web# cd node_modules/husky/
root@f5412bf9a01f:/usr/src/web/node_modules/husky# git rev-parse --git-dir
fatal: Not a git repository (or any parent up to mount point /usr/src/web/node_modules)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

I need to manually run the following to get it to work:

root@f5412bf9a01f:/usr/src/web# node node_modules/husky/bin/install.js
husky
setting up hooks in .git/hooks
done

I suppose it should work on npm install as well.

PS: My npm version is 2.15.9

Check if pushed branch is the checked out branch

When pushing a branch it's not necessarily so that you have that branch checked out so eg. running some linting to check if the pushed code is okay will not be very accurate.

Would be nice with a simple check that matched the current checked out commit against the pushed commit and in the case of a mismatch aborted or warned about that mismatch.

Possible?

Failing on windows 10

Node v4.24
npm v3.8.3
git v1.9.5.msysgit.1

The generated logic in the post-commit hook looks like this:
[ -f package.json ] && cat package.json | grep '"postcommit"\s*:'
[ $? -ne 0 ] && exit 0

What's happening is that the \s*: is not working as expected. It will find nothing and exit 0.
If I change grep '"postcommit"\s*:' to grep '"postcommit"[[:space:]]*:' It works.
Maybe this is more of a git bash issue, but I'm raising awareness.

Create hooks directory if needed

Using some git UI clients (like the Github Mac OS client) does not create the proper hooks directory in the .git folder.

husky should verify if that folder exists and create it if needed, otherwise it will fail on trying to install the hooks.

thoughts on ignoring certain filetypes?

I'm not one for flooding features, but... it would be quite nice if husky had the ability to filter out glob patterns. my particular use case is that our repository has multiple languages committing which don't require our push hook, which enforces eslint to run.

food for thought!

Missing the post-rewrite hook

Actually you added it due to Issue #19 but while your refactoring to hooks.json it was removed or just forgotten to move to the json-file: 69701d4

I would really appreciate it if you can add it again cause we need it in our project for the exact same reason as described in #19 :)

Thanks!

husky 0.11.5 breaks hooks

Hi,

I have an issue with husky 0.11.5, which breaks my ability to git push correctly as it gives me an error:

Here it is (with edits to the relevant parts of the project name):

.git/hooks/pre-push: 10: export: [email protected]:group-name/ProjectName.git: bad variable name
error: failed to push some refs to '[email protected]:group-name/ProjectName.git'

The issue appeared with 0.11.5. as npm i [email protected] fixes the issue

override dir in package.json

Some projects hold package.json in subdirectory rather than in root.

In such case, husky will report can't find .git/hooks/

This could be easily solved if husky was able to read package.json and look up for specific property like gitDir or so.

Expose git stdin parameters for pre-push

As you can see in the pre-push sample: https://github.com/git/git/blob/master/templates/hooks--pre-push.sample, they use some stdin parameters to determine local and remote sha and ref.

Main usecases for having these parameters are:

  • To not execute pre-push hook when you are deleting a remote branch (this is the most important, since it's kind of annoying when hooks starts when you just want to delete a branch)
  • To filter branch names which you want to execute pre-push hooks on

silent npm run

why did you choose run npm scripts in silent? usually its hiding some problems

prepush: "npm run unexisting",

husky will fail, and you will have no idea what is a problem

Option to not install git hooks on npm install

When a user runs npm install husky, all of the git hooks get installed automatically. This is usually great, but it would be handy to optionally be able to skip that install step and run it manually later.

ghooks offers this via opt-cli (it's broken in my testing though), which would allow a user to prevent the hook installations if they'd like to via a settings file or some configuration in the package.json file. It would be great if husky had the same, so that automatic installation could be optionally disabled.

This is something I'd like to create a PR for, but I wanted to have a discussion about it here before building the feature.

Use scripts exit status

If a script fails the hook exits with 1 as exit status, it should exit using the failure exit status of the script that have just executed.

git add could be invoked at the end of pre-commit for files added before

Currently I have the case with jsBeautify which modifies some files during pre-commit. The problem is that after that modified files are not automatically added to commit so that I have to run git add again.

It would be perfect if files that were added to commit before hook could be added automatically again at the end of the pre-commit.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.