You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- More, see [full list](https://github.com/toplenboren/simple-git-hooks/network/dependents?package_id=UGFja2FnZS0xOTk1ODMzMTA4)
37
35
38
36
### What is a git hook?
39
37
40
38
A git hook is a command or script that is going to be run every time you perform a git action, like `git commit` or `git push`.
41
-
39
+
42
40
If the execution of a git hook fails, then the git action aborts.
43
41
44
42
For example, if you want to run `linter` on every commit to ensure code quality in your project, then you can create a `pre-commit` hook that would call `npx lint-staged`.
@@ -53,57 +51,56 @@ You can look up about git hooks on the [Pro Git book](https://git-scm.com/book/e
53
51
54
52
However, this package requires you to manually apply the changes to git hooks. If you update them often, this is probably not the best choice.
55
53
56
-
Also, this package allows you to set only one command per git hook.
54
+
Also, this package allows you to set only one command per git hook.
57
55
58
56
If you need multiple verbose commands per git hook, flexible configuration or automatic update of git hooks, please check out the other packages:
2. Add `simple-git-hooks` to your `package.json`. Fill it with git hooks and the corresponding commands.
76
73
77
-
For example:
74
+
For example:
78
75
79
-
```jsonc
80
-
{
81
-
"simple-git-hooks": {
82
-
"pre-commit":"npx lint-staged",
83
-
"pre-push":"cd ../../ && npm run format",
76
+
```jsonc
77
+
{
78
+
"simple-git-hooks": {
79
+
"pre-commit":"npx lint-staged",
80
+
"pre-push":"cd ../../ && npm run format",
84
81
85
-
// All unused hooks will be removed automatically by default
86
-
// but you can use the `preserveUnused` option like following to prevent this behavior
82
+
// All unused hooks will be removed automatically by default
83
+
// but you can use the `preserveUnused` option like following to prevent this behavior
87
84
88
-
// if you'd prefer preserve all unused hooks
89
-
"preserveUnused":true,
85
+
// if you'd prefer preserve all unused hooks
86
+
"preserveUnused":true,
90
87
91
-
// if you'd prefer preserve specific unused hooks
92
-
"preserveUnused": ["commit-msg"]
93
-
}
94
-
}
95
-
```
88
+
// if you'd prefer preserve specific unused hooks
89
+
"preserveUnused": ["commit-msg"]
90
+
}
91
+
}
92
+
```
93
+
94
+
This configuration is going to run all linters on every `commit` and formatter on `push`.
96
95
97
-
This configuration is going to run all linters on every `commit` and formatter on `push`.
98
-
99
96
> There are more ways to configure the package. Check out [Additional configuration options](#additional-configuration-options).
100
-
97
+
101
98
3. Run the CLI script to update the git hooks with the commands from the config:
102
99
103
100
```sh
104
101
npx simple-git-hooks
105
102
```
106
-
103
+
107
104
Now all the git hooks are created.
108
105
109
106
### Update git hooks command
@@ -116,7 +113,6 @@ Note for **yarn2** users: Please run `yarn dlx simple-git-hooks` instead of the
116
113
117
114
Note that you should manually run `npx simple-git-hooks`**every time you change a command**.
118
115
119
-
120
116
### Additional configuration options
121
117
122
118
You can also add a `.simple-git-hooks.cjs`, `.simple-git-hooks.js`, `simple-git-hooks.cjs`, `simple-git-hooks.js`, `.simple-git-hooks.json` or `simple-git-hooks.json` file to the project and write the configuration inside it.
@@ -128,8 +124,8 @@ This way `simple-git-hooks` configuration in `package.json` will not take effect
128
124
```js
129
125
module.exports= {
130
126
"pre-commit":"npx lint-staged",
131
-
"pre-push": "cd ../../ && npm run format"
132
-
}
127
+
"pre-push":"cd ../../ && npm run format",
128
+
};
133
129
```
134
130
135
131
`.simple-git-hooks.json` or `simple-git-hooks.json` should look like the following.
@@ -141,6 +137,8 @@ module.exports = {
141
137
}
142
138
```
143
139
140
+
If you need to have multiple configuration files or just your-own configuration file, you install hooks manually from it by `npx simple-git-hooks ./my-config.js`.
141
+
144
142
### Uninstall simple-git-hooks
145
143
146
144
> Uninstallation will remove all the existing git hooks.
@@ -149,14 +147,13 @@ module.exports = {
149
147
npm uninstall simple-git-hooks
150
148
```
151
149
152
-
153
150
## Common issues
154
151
155
152
### When migrating from `husky` git hooks are not running
156
153
157
154
**Why is this happening?**
158
155
159
-
Husky might change the `core.gitHooks` value to `.husky`, this way, git hooks would search `.husky` directory instead of`.git/hooks/`.
156
+
Husky might change the `core.gitHooks` value to `.husky`, this way, git hooks would search `.husky` directory instead of `.git/hooks/`.
160
157
161
158
Read more on git configuration in [Git book](https://git-scm.com/docs/githooks)
throw('[ERROR] Config was not found! Please add `.simple-git-hooks.js` or `simple-git-hooks.js` or `.simple-git-hooks.json` or `simple-git-hooks.json` or `simple-git-hooks` entry in package.json.\r\nCheck README for details')
@@ -222,16 +224,31 @@ function _getPackageJson(projectPath = process.cwd()) {
0 commit comments