Giter Site home page Giter Site logo

pre-git's Introduction

bahmutov

"npx bahmutov" - to see my info

NPM

Build status semantic-release standard renovate-app badge

Inspired by (and shamelessly copied from) npx marius

Install

Requires Node and NPM with npx utility.

npx bahmutov

   ╭──────────────────────────────────────────────────────────────────────────╮
   │                                                                          │
   │   Gleb Bahmutov, PhD                                                     │
   │   JavaScript ninja, image processing expert, software quality fanatic.   │
   │                                                                          │
   │          Web: https://glebbahmutov.com                                   │
   │         Blog: https://glebbahmutov.com/blog                              │
   │         Work: https://www.cypress.io                                     │
   │       Slides: https://slides.com/bahmutov                                │
   │       GitHub: https://github.com/bahmutov                                │
   │      Twitter: https://twitter.com/bahmutov                               │
   │     LinkedIn: https://linkedin.com/in/bahmutov                           │
   │                                                                          │
   │   Go on, give https://github.com/cypress-io/cypress a star!              │
   │                                                                          │
   ╰──────────────────────────────────────────────────────────────────────────╯

Small print

Author: Gleb Bahmutov <[email protected]> © 2018

License: MIT - do anything with the code, but don't blame me if it does not work.

Support: if you find any problems with this module, email / tweet / open issue on Github

MIT License

Copyright (c) 2018 Gleb Bahmutov <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

pre-git's People

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

pre-git's Issues

Access to the stdin lines as described by Git

Would be really useful if we could get hold of the actual input used when running pre-push as described here:

http://git-scm.com/docs/githooks#_pre_push

...and used in action in the sample here:

https://github.com/git/git/blob/master/templates/hooks--pre-push.sample

Seems git itself takes control of the stdin; I've had a look at least, and cannot seem to access this information cleanly, if at all.

Would certainly be useful to ascertain the actual branch being pushed, as it would be possible for a user to push a branch that is different to their current active branch.

Commit fails with error:

git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree commit -q -F /var/folders/hp/0cj2csyn2fj6gmlw_t3skynr0000gn/T/SourceTreeTemp.wiV3x9
executing task "grunt"

pre-commit: You've failed to pass all the hooks.
pre-commit:
pre-commit: The "grunt" script failed.
pre-commit:
pre-commit: You can skip the git pre-commit hook by running:
pre-commit:
pre-commit: git commit -n (--no-verify)
pre-commit:
pre-commit: But this is not adviced as your tests are obviously failing.

Completed with errors, see above

stdout maxBuffer exceeded when running pre-push hook

Hi Gleb,

I am using your library to create hooks for git. Kudos for the good work. I am getting an error though:

pre-push Failed to check for commits. Cannot run the tests.
pre-push [Error: stdout maxBuffer exceeded.]

I think this is due to the limitation of the stdout maxBuffer that Nodejs defaults to 200KB, see https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback.

I have verified that the command is causing trouble is

git diff --name-only origin/master..HEAD

I committed by mistake my node_modules folder and now I want to remove it from my repository. Obviously, the list of files is big and the command above produces a lot of text. I could increase the maxBuffer but I have read the article on http://www.hacksparrow.com/difference-between-spawn-and-exec-of-node-js-child_process.html that does not recommend to do that. What do you think? Do you have anything against using spawn rather than exec to create the child process?

No compatible shelljs version.

npm ERR! Error: No compatible version found: shelljs@'^0.3.0'
npm ERR! Valid install targets:

  • 0.0.1 - 0.0.9
  • 0.1.0 - 0.1.4
  • 0.2.0 - 0.2.6
  • 0.3.0
  • 0.0.1-alpha1, 0.0.2-pre1, 0.0.4-pre1 0.0.5-pre1 0.0.5-pre2 0.0.5-pre3 0.0.5-pre4 0.0.6-pre1 0.0.6-pre2

System:
Windows XP SP3 (I know it's old)
npm 1.2.18
node 0.10.5

Support package.json in different folder than .git

Do to a restriction outside of my control, we have a single git repo that contains multiple node projects. The repo is structured like this:

/.git/
/.git/hooks/
/project1/
/project1/package.json
/project1/node_modules
/project2/
/project2/package.json
/project2/node_modules

The pre-git hooks assume that there is only one package.json and that it is in the same directory as the .git folder. What would be involved in getting the hook to walk up the directory tree and locate the first package.json? This would allow me to run git commit in the /project1 directory and find its package.json instead of throwing an error that the file doesn't exist.

By the way, it looks like process.cwd() reports the directory that contains /.git, however process.env.GIT_PREFIX contains the sub-path to where the user ran the git command.

spawn doesn't work on windows (with npm for example)

hi when i do
git commit -m "blah blah blah"
with
"pre-commit": [
"npm version"
]
in package.json, it gives me :

executing task "npm" with args "version"
events.js:85
throw er; // Unhandled 'error' event
^
Error: spawn npm ENOENT
at exports._errnoException (util.js:746:11)
at Process.ChildProcess._handle.onexit (child_process.js:1053:32)
at child_process.js:1144:20
at process._tickCallback (node.js:355:11)

The same thing happens with gulp
"pre-commit": [
"gulp"
]

i think the problem is spawn in windows
maybe this help https://www.npmjs.com/package/cross-spawn

pre-push fails when branch does not exist on origin

Create a new branch, add some changes, and commit locally.

Enable pre-push in your usual way.

then try to push

$ git push origin brand/new/branch
pre-push Failed to check for commits. Cannot run the tests.
pre-push { [Error: Command failed: C:\windows\system32\cmd.exe /s /c "git diff --name-only origin/brand/new/branch..HEAD"
fatal: ambiguous argument 'origin/brand/new/branch..HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
]
  killed: false,
  code: 128,
  signal: null,
  cmd: 'C:\\windows\\system32\\cmd.exe /s /c "git diff --name-only origin/brand/new/branch..HEAD"' }
error: failed to push some refs to 'ssh://[email protected]/project-name'

Perhaps the hook needs to check if the branch exists, and if not, ignore the diff?

does not work

pre-push Nothing to pre- test. Bailing out.

Scripts property:

"pre-push": [ "node -e 'throw new Error('damn');" ]

No colors in command output

When using pre-commit/push commands that produces colored output, the colors aren't shown in hook output. Also, all the hook output seems to be sent to the terminal at the end of the execution. Do you think it is possible to use streams for command runner here?

postinstall fails

I have a dependency project (e.g. B) that uses pre-git. Requiring the project B in project A, and doing npm install, fails with this error:

> [email protected] postinstall /Users/nracovit/Dev/project-A/node_modules/project-B/node_modules/pre-git
> node install
>>> ... removes the existing hooks under the root project A, it should not ....
> /Users/nracovit/Dev/project-A/node_modules/angular-scope-watch-promise/node_modules/pre-git/install.js:185
    throw new Error('Cannot find changelog module among ' +
          ^
Error: Cannot find changelog module among ["node_modules/pre-git/node_modules/cz-conventional-changelog","node_modules/cz-conventional-changelog"]

I think it's due to the "postinstall": "node install", line in pre-git. I guess it should be
"postinstall": "./node install", or similar. Can you verify?

Thank you!

Add post-commit hook

For example to run check for modified but uncommitted files

git diff-index --name-status --exit-code HEAD --

Do not rely on paths in commit config

Using paths for configuring commitizen like

"czConfig": {
    "path": "node_modules/pre-git/node_modules/cz-conventional-changelog"
  }

is breaking between npm 2 and npm 3.

package.json in a different folder

hi
it's possible to support a package.json file in a folder different from the folder that contains .git?
something like this:

.git
extra
project_one/package.json
project_two
lib

Because at the moment when i run git commit from the root folder, pre-common.js fails with this message:
pre-commit An Error was thrown: RangeError: Maximum call stack size exceeded
(it cant find package.json in project_one i suppose)

thanks

Support commit-msg hook

I'm working on validation for commit messages, which makes sense to implement using the commit-msg hook. Could you support that one as well?

Write command to start commitizen

Instead of relying on nested module ./node_modules/pre-git/node_modules/commitizen/bin/git-cz to execute the npm run commit command

Add post-install script

to automatically put empty keys pre-commit, pre-push, etc. into package.json if they don't exist already.

spawn doesn't handle pipes

The taskRunner code splits the command on a space to obtain the arguments, however this fails when trying to pipe a command as it treats the pipe as an extra argument. Perhaps a better alternative would be to use childProcess.exec which has the same API as childProcess.spawn but does not have the requirement of separate arguments and works on Windows (#33).

{"pre-commit": "git diff --name-only --cached | xargs -l jshint"}

produces the following output

executing task "git" with args "diff,--name-only,--cached,|,xargs,-l,jshint"

Erro ao instalar o hook

Se o hook pre-commit não existir por exemplo ele dá erro na instalação em vez de criar o arquivo.

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.