Giter VIP home page Giter VIP logo

pre-commit's People

Contributors

3rd-eden avatar akiva avatar alex-sokolov avatar alexdisler avatar alexindigo avatar antialias avatar barroudjo avatar bbondy avatar bregenspan avatar cvan avatar faazshift avatar fhemberger avatar filipbarak avatar greenkeeper[bot] avatar jenkins-li-bot avatar jgantunes avatar jltalens avatar josegal avatar kevinoid avatar kriskowal avatar luanmuniz avatar mcollina avatar qard avatar raynos avatar saiichihashimoto avatar sergel avatar seriousmanual avatar sonicoder86 avatar tassmjau avatar tikotzky 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

pre-commit's Issues

multi tasks output different from one single task for the same task.

Here is my single task config.

  "scripts": {
    "eslint": "eslint $(git diff-index --cached HEAD --name-only --diff-filter ACMR | egrep '.js$')"
  },
  "pre-commit": ["eslint"],
  "precommit.silent": true

It works well even if I did not change any javascript file.

And below is my multi tasks config.

  "scripts": {
    "eslint": "eslint $(git diff-index --cached HEAD --name-only --diff-filter ACMR | egrep '.js$')",
    "scss-lint": "scss-lint $(git diff-index --cached HEAD --name-only --diff-filter ACMR | egrep '.s(a|c)ss$')"
  },
  "pre-commit": ["eslint", "scss-lint"],
  "precommit.silent": true

Let's say I just modified a sass file and commit it .

eslint [options] file.js [file.js] [dir]

Basic configuration:
  -c, --config path::String   Use configuration from this file or shareable
                              config
  --no-eslintrc               Disable use of configuration from .eslintrc
  --env [String]              Specify environments
  --ext [String]              Specify JavaScript file extensions - default: .js
  --global [String]           Define global variables
  --parser String             Specify the parser to be used - default: espree
  --parser-options Object     Specify parser options

Caching:
  --cache                     Only check changed files - default: false
  --cache-file path::String   Path to the cache file. Deprecated: use
                              --cache-location - default: .eslintcache
  --cache-location path::String  Path to the cache file or directory

Specifying rules and plugins:
  --rulesdir [path::String]   Use additional rules from this directory
  --plugin [String]           Specify plugins
  --rule Object               Specify rules

Ignoring files:
  --ignore-path path::String  Specify path of ignore file
  --no-ignore                 Disable use of .eslintignore
  --ignore-pattern [String]   Pattern of files to ignore (in addition to those
                              in .eslintignore)

Using stdin:
  --stdin                     Lint code provided on <STDIN> - default: false
  --stdin-filename String     Specify filename to process STDIN as

Handling warnings:
  --quiet                     Report errors only - default: false
  --max-warnings Int          Number of warnings to trigger nonzero exit code
                              - default: -1

Output:
  -o, --output-file path::String  Specify file to write report to
  -f, --format String         Use a specific output format - default: stylish
  --no-color                  Disable color in piped output

Miscellaneous:
  --init                      Run config initialization wizard - default: false
  --fix                       Automatically fix problems
  --debug                     Output debugging information
  -h, --help                  Show help
  -v, --version               Outputs the version number
  --no-inline-config          Allow comments to change eslint config/rules
  --print-config              Print the configuration to be used
client/styles/food/food-box.sass:11 [E] Syntax Error: Invalid CSS after "    border: none": expected "{", was ";"

This's what I got. It contains eslint output. I mean if you run eslint without any arguments, You will get those.

For the single task config, if I do not modify any javascript file, eslint will run with empty arguments, but it won't output those stuff, So I guess pre-commit handle that for me .
What about multi task config ? is it a bug or what ?

Commit hooks requiring user input - how to handle?

I have a pre-commit hook that asks a few questions to the committer prior to running the rest of the standard commit hooks (those not requiring user input). When I attempt to commit, the script that gather user input starts, prints out some chunk of the prompt and then exits. I tried to track this down and see why and it appears that the 'close' event on the spawned process is getting called earlier than I would expect on the user-input-expecting hook AKA almost immediately after printing the first prompt it emits a 'close' event on the spawned process. This causes 'again' to be called unexpectedly. I need to find out why that is happening. I had the same issue with the readline module and the prompt module. Maybe it is how user prompting works generally?
My question is: Is requesting user input and waiting on it before continuing on to the next hook not a feature we want to support or is it bad practice to ask for user input during a hook? I would like to make it possible, but just wanted to see some opinions on this.

Configurable git root

Hello,

I have a multi-technology / single-repository project, something like that :

  • project_root/
    • .git/
      • config
      • hooks/
    • api/
      • composer.json
      • [ php files ]
    • frontend/
      • package.json
      • [ js files ]

The problem is : the install.js doesn't find the .git directory, because it isn't in frontend directory but 1 level up. I don't know how to detect accuratly the git root, but maybe we can specify it manually in package.json, along side pre-commit scripts ?

Symlinks on Vagrant running on Windows

I've been using this project for a while but am stuck with v0.0.11. My default OS is Windows (sad, I know), so to make things less weird I use Vagrant for development.

After 248d18c it's not possible to install pre-commit because of this:

vagrant@vagrant-ubuntu-trusty-64:~/cha/api/code$ npm install --save-dev pre-commit --no-bin-links
/
> [email protected] install /home/vagrant/cha/api/code/node_modules/pre-commit
> node install.js

pre-commit:
pre-commit: Detected an existing git pre-commit hook
pre-commit: Old pre-commit hook backuped to pre-commit.old
pre-commit:
pre-commit:
pre-commit: Failed to symlink the hook file in your .git/hooks folder because:
pre-commit: EPROTO: protocol error, symlink '/home/vagrant/cha/api/code/node_modules/pre-commit/hook' -> '/home/vagrant/cha/api/code/.git/hooks/pre-co
mmit'
pre-commit: The hook was not installed.
pre-commit:
[email protected] node_modules/pre-commit
└── [email protected]

There are ways to enable symlinking from Vagrant on Windows, but they're all hacks and really, really painful.

What do you guys think about supporting copying again (in case symlink creation fails)? If you agree, I can send a PR to support this :)

Thanks!

Exclude test script

I only want to pre-commit my pretest (linting) step, and exclude test. How can I do this?

Windows binary operator error

I'm getting the following error on Windows when I try to use this package:

.git/hooks/pre-commit: line 11: [: /c/Program: binary operator expected pre-commit:

This is line 11 from the referenced file:

if [ -z $HAS_NODE ] && [ -f ~/.bash_profile ]; then

Can you provide any help?

Package version 1.0.10
Node version: 0.10.31
NPM version 2.13.2
Windows 7

Exit code from "snazzy" is ignored

I'm not sure if this is a bug with pre-commit, a bug with snazzy or both. So I'm filing it here and copying @feross

The following "project" will commit without error despite failing the linting step:

package.json

{
  "scripts": {
    "lint": "snazzy",
    "foo": "exit 0"
  },
  "precommit": [
    "lint",
    "foo"
  ],
  "devDependencies": {
    "pre-commit": "^1.2.2",
    "snazzy": "^6.0.0",
    "standard": "^10.0.0"
  }
}

index.js

'use strict'

function invalid() {
  return 1
} // note missing newline EOF

If you replace "lint": "snazzy" with "lint": "standard" then the commit will fail as it should.

Upgrading from 1.1.3 to 1.2.1 breaks

As the subject states, when I update to the latest version, the pre-commit no longer happens when doing a commit.

The pre-commit file and pre-commit.old show no differences.

can't uninstall

I attempted to uninstall this from a project I'm working on (we're over 100 tests and switching branches became a process). Once uninstalled, I started seeing this in my commit message:
.git/hooks/pre-commit: line 2: ./node_modules/pre-commit/hook: No such file or directory
I had to re-install the package and add this to my package.json to get the project functional again:

  "pre-commit": {
    "silent": true,
    "run": []
  }

I fully accept that the problem could be me, but if anyone else has experienced this I'd love to see a better solution

Problems on Windows - Help! No such file or directory 2: ./node_modules/pre-commit/hook : integer expression expected: [: 127 : numeric argument required 5:

I've been pulling my hair out trying to make sense of this for someone I'm working with who is having this problem. It's breaking their workflow.

No such file or directory 2: ./node_modules/pre-commit/hook
: integer expression expected: [: 127
: numeric argument required 5:

I've tried Windows machines near me, and VMs and don't have the problem.

This happens in cmd, powershell, MinGW, WebStorm.

Any ideas?

Cannot install on Windows?

I'm getting the following error while trying to install on Windows:

> [email protected] install c:\path\to\project\node_modules\pre-commit
> node install.js


fs.js:741
  return binding.symlink(preprocessSymlinkDestination(destination, type),
                 ^
Error: EPERM, operation not permitted 'c:\path\to\project\node_modules\pre-commit\hook'
    at Object.fs.symlinkSync (fs.js:741:18)
    at Object.<anonymous> (c:\path\to\project\node_modules\pre-commit\install.js:49:4)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

pre-commit hooks has false positives

When I use git add -p or even git add some files it will run my tests before the commit however the tests pass because of the unstaged changes I have locally.

If I were to stash before running npm test then the tests would have failed.

Is it the responsibility of pre-commit to ensure that the tests pass based on only the staged changes or is that the users responsibility ?

list of suggested scripts to use

would be nice for non node people if there was a list of suggested node tools for common tasks:

  • merge conflicts
  • trailing white space
  • etc

It does not write pre-commit file in hooks folder on Windows

Pretty much a duplicate of #43

pre-commit:
pre-commit: Failed to symlink the hook file in your .git/hooks folder because:
pre-commit: EPERM: operation not permitted, symlink '..\..\node_modules\pre-commit\hook' -> 'C:\path\to\glory\.git\hooks\pre-commit'
pre-commit: The hook was not installed.
pre-commit:

However, I'd like to share some more info: https://en.wikipedia.org/wiki/NTFS_symbolic_link

Ideally, we could request elevation something like https://www.npmjs.com/package/windows-elevate or call a native function.

Thanks!

npm run-script and git commit returns different results

Hi!

My package.json looks like this:

  "scripts": {
    "lint-changed": "eslint $(git diff --name-only | grep -e \\.js$)"
  },
  "pre-commit": ["lint-changed"]

Running npm run-script lint-changed works as expected, but git commit returns this:

$ git commit -a
eslint [options] file.js [file.js] [dir]

Options:
[..]

What am I doing wrong?

Pass list of commiting files as parameter to npm script

Hello, thanks for good module!
But one thing is really needed.
For example, I have lint script on npm, that run linting gulp lint task. And in this task I can get list of all changed files from last commit through gulp-git to lint only them like this

gulp.task('git-diff', callback => {
  git.exec({args: `diff-index --name-only HEAD | grep .*\\.js | grep -v json`, quiet: true}, (err, stdout) => {
    .....
  });
});

But if I commit only some files this task anyway will take every changed, i.e. some files that I don't want to commit right now may have broken lint rules (for examples this files in deep development in that moment).
It would be great, if pre-commit passed list of files to npm script, for example if we have

"scripts": {
   "lint": "gulp lint"
},
"pre-commit": [
  "lint"
]

And pre-commit can call npm run lint -- --file path1 [--file path2 [--file path3]] where pathN is path to commiting files. In this case I can read in gulp array of passed files and lint only them.

invoking npm with cp.spawn doesn't work on windows

This fails on windows with the error:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: spawn ENOENT
    at errnoException (child_process.js:1001:11)
    at Process.ChildProcess._handle.onexit (child_process.js:792:34)

because you can't use spawn to invoke npm on windows.

pre-commit doesn't work when the current path contains a space

I just installed pre-commit for a project which contains a space in the path name (e.g. /projects/example path). npm test itself runs fine, but when I try to commit, I get the following error:

$ git commit -m "package.json: add pre-commit"
module.js:338
    throw err;
          ^
Error: Cannot find module '/projects/example'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:286:25)
    at Function.Module.runMain (module.js:471:10)
    at startup (node.js:117:18)
    at node.js:948:3

Builds aren't added to commit

What could be done to make sure build files created by pre-commit are added to the stage?

Is this something that can be in pre-commit, or is there something I can do on my end?

For instance I could just add a command to the package.json scripts that stages the built files on pre commit.

It does not write pre-commit file in hooks folder on Windows 7

npm install --save-dev pre-commit
/
> [email protected] postinstall c:\git\iron-node\node_modules\pre-commit\node_modules\cross-spawn\node_modules\spawn-sync
> node postinstall


> [email protected] install c:\git\iron-node\node_modules\pre-commit
> node install.js

pre-commit:
pre-commit: Failed to symlink the hook file in your .git/hooks folder because:
pre-commit: EPERM, operation not permitted 'c:\git\iron-node\.git\hooks\pre-commit'
pre-commit: The hook was not installed.
pre-commit:
[email protected] node_modules\pre-commit
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected])

Skip actual `npm run`?

I love the fact that pre-commit ties directly into package.json scripts from an ergonomics perspective.

However, I think it'd be a good idea to avoid the npm sub-process altogether, for performance reasons. You could, for example, look up the scripts yourself and run them with the ./node_modules/.bin prefix.

Every commit will pay a penalty of ~380ms per pre-commit script defined. See investigation by @vjeux: prettier/prettier#443

Since pre-commit is now the recommended way to set up prettier, I think this is very much a worthwhile optimization that'll save a lot of time to many people.

Nothing happens after ng test is successfully run

Hello, I am trying to make run your precommit hook on this environment:

  • angular 2.3.1
  • jasmine-core 3.3.1
  • karma-jasmine 1.0.2
  • karma 1.2.0
  • pre-commit 1.2.2
  • W10

When I run git commit the test pass successfully but then nothing happens.

Commit template does not clean itself up after configuration is removed

As an experiment, I tried the template option.

It did not work (apparently due to #80)

After removing the template option, my pre-commit hook still failed.

fatal: could not read '".commit-template"': No such file or directory

I had to manually edit my .git/config to fix this.

I can't think of a nice way to handle this, and honestly the more I think about it, I am not sure if having this option in your project really makes that much sense to begin with (but of course, thats your prerogative)

Thanks for your great work!

Support .bashrc

My loading of NVM on local dev machine is in .bashrc file and if i try to commit from Phpstorm it doesnt find the node executable

Execute with zsh shell (oh-my-zsh and SourceTree error)

I am using the zsh shell with oh-my-zsh. I also often use the SourceTree client. Lastly, I'm using react-boilerplate which uses pre-commit.

When I commit from the command line (zsh shell), everything works ok. But I just started getting errors when committing from inside the SourceTree client (which worked fine yesterday):

git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree commit -q -F /var/folders/wt/bj_21zvn7518qvf6bfxtt3w40000gn/T/SourceTreeTemp.IWP5H8 
/Users/tauren/.oh-my-zsh/oh-my-zsh.sh: line 12: autoload: command not found
/Users/tauren/.oh-my-zsh/oh-my-zsh.sh: line 31: syntax error near unexpected token `('
/Users/tauren/.oh-my-zsh/oh-my-zsh.sh: line 31: `for config_file ($ZSH/lib/*.zsh); do'
/Users/tauren/.zshrc: line 95: brew: command not found
/Users/tauren/.zshrc: line 95: /nvm.sh: No such file or directory
zsh-syntax-highlighting: error: not compatible with NO_FUNCTION_ARGZERO
./node_modules/pre-commit/hook: line 49: : command not found
./node_modules/pre-commit/hook: line 49: : command not found
Completed with errors, see above

I've been using this setup for quite some time without issues, and I'm not quite sure what changed. The most recent thing I did was blow away node_modules in my react-boilerplate project and run npm install again. I did update to the latest SourceTree a few days ago, but I'm pretty sure I've committed using it since then. I tried updating to [email protected] from 1.1.3, but the same thing happens.

As with any oh-my-zsh setup, my ~/.zshrc file sources ~/.oh-my-zsh/oh-my-zsh.sh. This file executes autoload which is a ZSH shell command and blows up. It looks like pre-commit is running in a bash shell, so the command wouldn't be available.

But what I don't understand how it was ever working... This error just started, and my OMZ script has had autoload in it forever.

Is there something I can do to fix this? Can pre-commit take measures to run with the correct shell? Anything else I should do?

sourcing .bash_profile clash with nvm

If you are developing using nvm, sourcing the bash profile will change which node version are you targeting. This means that if you are developing a native addon against iojs and your default is 0.10, everything falls apart.

A quick solution for this might be checking if node is already present, and if so do not source. I will send a PR with this fix.

Side note, can you please bump the MINOR or at least the MAJOR when you change the hook? It broke a lot of stuff for the way I work.

Incorrectly reports failure in scripts

I started with the following in my package.json

  "pre-commit": [
    "jshint app.js"
  ],

This resulted in the following when I commit:

pre-commit:
pre-commit: We've failed to pass the specified git pre-commit hooks as the `jshint app.js`
pre-commit: hook returned an exit code (1). If you're feeling adventurous you can
pre-commit: skip the git pre-commit hooks by adding the following flags to your commit:
pre-commit:
pre-commit:   git commit -n (or --no-verify)
pre-commit:
pre-commit: This is ill-advised since the commit is broken.
pre-commit:

Running jshint from the command line returns 0. So under some expert advice I changed my package.json to

  "pre-commit": [
    "true"
  ],

and it reports the same error as before except it says true returned exit code 1. So something is obviously wrong or misconfigured. Any help to troubleshoot?

I am running OS X 10.11.4 and the following:
node v5.5.0
npm 3.5.3
pre-commit 1.1.2
same behavior occurs using Fish shell and bash

Windows fails to run hook bash script

Hi
when i try to install the new version v1.1.0, it fails on row 26 of install.js
if (shelly.exec(hook +' --dry-run', { silent: true }).code !== 0) {..}

If i change silent to false and run node install.js from pre-commit folder, it gives me
"...\node_modules\pre-commit\hook" non è riconosciuto come comando interno o esterno, un programma eseguibile o un file batch.
pre-commit:
pre-commit: The --dry-run of the pre-commit hook failed to execute.
pre-commit:
pre-commit: The hook was not installed.
pre-commit:

because windows cant run

./hook --dry-run

Instead i must use

sh ./hook --dry-run

sh.exe is the emulator on windows of unix shell installed with msysgit (git for windows) for example

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.