0.1.2 • Published 4 years ago

@jshawl/pre-commit v0.1.2

Weekly downloads
-
License
GPL-3.0-only
Repository
-
Last release
4 years ago

Pre-Commit Hook

This npm package generates a git pre-commit hook that runs a set of customizable bash commands.

Philosophy

No package.json changes

Local commits are a very personal activity. Your own commit guards don't need to be shared with other contributors to your repository.

Not npm specific

This package's runtime is nodejs but you can add arbitrary bash commands as commit guards:

.pre-commit-scripts:

npm run format:check
npm run format # format anyway to pass the next check
npm run lint
! git diff --staged | grep console.log # prevent accidentally sharing debug statements

Index safe by default

No changes are ever applied to the staging area programmatically.

The general workflow is:

  1. Try to commit
  2. See commit guard errors
  3. Fix errors
  4. Stage changes
  5. Try to commit (and succeed this time)

Install

npm install @jshawl/pre-commit

A post-install script will copy a pre-commit executable to .git/hooks/pre-commit.

Usage

git commit --allow-empty -m "testing pre-commit hook"

A few npm scripts will run. If any of them fail, git will not commit. You can skip the pre-commit hook by adding the --no-verify to a git commit command.

Configuration

It's possible to override the default commands.

Create a .pre-commit-scripts file like this one:

npm run format:check
npm run format
npm run lint
npm run build

in your repository's root directory, and list whichever commands you want to exit 0 before allowing a commit.

Optionally, consider ignoring this file so other contributors to the repository don't have to follow your own commit rules:

echo .pre-commit-scripts >> .git/info/exclude

Uninstall

npm uninstall @jshawl/pre-commit

or just remove the pre-commit hook:

rm .git/hooks/pre-commit
0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago