uber-archive / npm-shrinkwrap

A consistent shrinkwrap tool
MIT License
773 stars 47 forks source link

How to put into .git/hooks/pre-commit ? #45

Open danschumann opened 10 years ago

danschumann commented 10 years ago

Hey I put npm shrinkwrap into a pre-commit git hook, but either git does its check too soon, or shrinkwrap writes it too late, because that commit doesn't have a changed shrinkwrap.

I'd like to automatically shrinkwrap before a commit and have the changed shrinkwrap file go into that same commit. Is this possible or do I need to write a bash script?

Raynos commented 10 years ago

If npm-shrinkwrap doesn't write npm-shrinkwrap.json then it will have errored out.

I don't know why it doesn't work :(

peterjwest commented 9 years ago

I'd like to try this, did you remember to run git add in your hook?

jcorbin commented 9 years ago

The following suffices:

#!/bin/sh
set -e

if ! git diff --cached --quiet -- package.json; then
    npm shrinkwrap # or npm run ... to taste
    git add npm-shrinkwrap.json
fi

Tested in a trivial foo repo, it:

peterjwest commented 9 years ago

Yeah I just did the same, works fine! If you leave out the package.json check, though, it will detect modules which are not saved in your package.json.

turadg commented 9 years ago

@jcorbin thanks for that snippet!

I used it to make this drop-in hook code https://github.com/turadg/npm-shrinkwrap-git-hooks