{"id":13432196,"url":"https://github.com/observing/pre-commit","last_synced_at":"2025-05-13T23:09:36.500Z","repository":{"id":7948866,"uuid":"9343284","full_name":"observing/pre-commit","owner":"observing","description":"Automatically installs a git pre-commit script in your git repository which runs your `npm test` on pre-commit","archived":false,"fork":false,"pushed_at":"2023-05-22T08:17:07.000Z","size":118,"stargazers_count":1883,"open_issues_count":78,"forks_count":153,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-05-10T15:53:54.794Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/observing.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2013-04-10T10:00:08.000Z","updated_at":"2025-04-27T19:05:35.000Z","dependencies_parsed_at":"2022-07-12T15:03:11.695Z","dependency_job_id":"114387ca-7b0c-452f-a962-1033e5279d99","html_url":"https://github.com/observing/pre-commit","commit_stats":{"total_commits":150,"total_committers":36,"mean_commits":4.166666666666667,"dds":"0.33333333333333337","last_synced_commit":"a84bdc87aabf79493343a366872ab204a62b1613"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/observing%2Fpre-commit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/observing%2Fpre-commit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/observing%2Fpre-commit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/observing%2Fpre-commit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/observing","download_url":"https://codeload.github.com/observing/pre-commit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254042174,"owners_count":22004860,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T02:01:09.327Z","updated_at":"2025-05-13T23:09:31.473Z","avatar_url":"https://github.com/observing.png","language":"JavaScript","readme":"# pre-commit\n\n[![Version npm][version]](http://browsenpm.org/package/pre-commit)[![Build Status][build]](https://travis-ci.org/observing/pre-commit)[![Dependencies][david]](https://david-dm.org/observing/pre-commit)[![Coverage Status][cover]](https://coveralls.io/r/observing/pre-commit?branch=master)\n\n[version]: http://img.shields.io/npm/v/pre-commit.svg?style=flat-square\n[build]: http://img.shields.io/travis/observing/pre-commit/master.svg?style=flat-square\n[david]: https://img.shields.io/david/observing/pre-commit.svg?style=flat-square\n[cover]: http://img.shields.io/coveralls/observing/pre-commit/master.svg?style=flat-square\n\n**pre-commit** is a pre-commit hook installer for `git`. It will ensure that\nyour `npm test` (or other specified scripts) passes before you can commit your\nchanges. This all conveniently configured in your `package.json`.\n\nBut don't worry, you can still force a commit by telling `git` to skip the\n`pre-commit` hooks by simply committing using `--no-verify`.\n\n### Installation\n\nIt's advised to install the **pre-commit** module as a `devDependencies` in your\n`package.json` as you only need this for development purposes. To install the\nmodule simply run:\n\n```\nnpm install --save-dev pre-commit\n```\n\nTo install it as `devDependency`. When this module is installed it will override\nthe existing `pre-commit` file in your `.git/hooks` folder. Existing\n`pre-commit` hooks will be backed up as `pre-commit.old` in the same repository.\n\n### Configuration\n\n`pre-commit` will try to run your `npm test` command in the root of the git\nrepository by default unless it's the default value that is set by the `npm\ninit` script.\n\nBut `pre-commit` is not limited to just running your `npm test`'s during the\ncommit hook. It's also capable of running every other script that you've\nspecified in your `package.json` \"scripts\" field. So before people commit you\ncould ensure that:\n\n- You have 100% coverage\n- All styling passes.\n- JSHint passes.\n- Contribution licenses signed etc.\n\nThe only thing you need to do is add a `pre-commit` array to your `package.json`\nthat specifies which scripts you want to have ran and in which order:\n\n```js\n{\n  \"name\": \"437464d0899504fb6b7b\",\n  \"version\": \"0.0.0\",\n  \"description\": \"ERROR: No README.md file found!\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: I SHOULD FAIL LOLOLOLOLOL \\\" \u0026\u0026 exit 1\",\n    \"foo\": \"echo \\\"fooo\\\" \u0026\u0026 exit 0\",\n    \"bar\": \"echo \\\"bar\\\" \u0026\u0026 exit 0\"\n  },\n  \"pre-commit\": [\n    \"foo\",\n    \"bar\",\n    \"test\"\n  ]\n}\n```\n\nIn the example above, it will first run: `npm run foo` then `npm run bar` and\nfinally `npm run test` which will make the commit fail as it returns the error\ncode `1`.  If you prefer strings over arrays or `precommit` without a middle\ndash, that also works:\n\n```js\n{\n  \"precommit\": \"foo, bar, test\"\n  \"pre-commit\": \"foo, bar, test\"\n  \"pre-commit\": [\"foo\", \"bar\", \"test\"]\n  \"precommit\": [\"foo\", \"bar\", \"test\"],\n  \"precommit\": {\n    \"run\": \"foo, bar, test\",\n  },\n  \"pre-commit\": {\n    \"run\": [\"foo\", \"bar\", \"test\"],\n  },\n  \"precommit\": {\n    \"run\": [\"foo\", \"bar\", \"test\"],\n  },\n  \"pre-commit\": {\n    \"run\": \"foo, bar, test\",\n  }\n}\n```\n\nThe examples above are all the same. In addition to configuring which scripts\nshould be ran you can also configure the following options:\n\n- **silent** Don't output the prefixed `pre-commit:` messages when things fail\n  or when we have nothing to run. Should be a boolean.\n- **colors** Don't output colors when we write messages. Should be a boolean.\n- **template** Path to a file who's content should be used as template for the\n  git commit body.\n\nThese options can either be added in the `pre-commit`/`precommit` object as keys\nor as `\"pre-commit.{key}` key properties in the `package.json`:\n\n```js\n{\n  \"precommit.silent\": true,\n  \"pre-commit\": {\n    \"silent\": true\n  }\n}\n```\n\nIt's all the same. Different styles so use what matches your project. To learn\nmore about the scripts, please read the official `npm` documentation:\n\nhttps://docs.npmjs.com/misc/scripts\n\nAnd to learn more about git hooks read:\n\nhttp://githooks.com\n\n### License\n\nMIT\n","funding_links":[],"categories":["JavaScript","Repository","Productivity"],"sub_categories":["Git","React Components"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fobserving%2Fpre-commit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fobserving%2Fpre-commit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fobserving%2Fpre-commit/lists"}