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
> This library was written and tested in [Deno 2](https://deno.com/blog/v2.0), It has also been
6
+
> This library was written in [Deno 2](https://deno.com/blog/v2.0),
7
7
> tested on Windows, MacOS, and Linux. See [code coverage](https://app.codecov.io/github/vnphanquang/githooks/flags?flags%5B0%5D=macos-latest&flags%5B1%5D=ubuntu-latest&flags%5B2%5D=windows-latest) for more information.
8
8
9
9
## Usage as CLI
10
10
11
-
1. Make sure your project is within a git directory
11
+
1. Make sure your project is within a git directory...
12
12
13
13
```bash
14
-
git init
14
+
git init.
15
15
```
16
16
17
-
2. Run initialization script:
17
+
2. Run initialization script...
18
18
19
19
```bash
20
20
deno run -A jsr:@vnphanquang/githooks/bin init
21
21
```
22
22
23
-
> [!NOTE]
24
-
> `init` will search up and run at the nearest git root directory, if any, or fail otherwise.
25
-
26
-
Alternatively, run with verbose permissions **at project root**:
23
+
`init` will search up and run at the nearest git root directory, if any, or fail otherwise. Alternatively, run with verbose permissions **at project root**:
27
24
28
25
```bash
29
26
deno run --allow-read="." --allow-write=".githooks" --allow-run="git" jsr:@vnphanquang/githooks/bin init
30
27
```
31
28
32
-
3. Edit `./githooks/pre-commit` to your needs. Alternatively, you can create any git hook script by adding
33
-
it to `.githooks/<your_hook>`. For example:
29
+
3. Edit `./githooks/pre-commit` to your needs. You can create, edit, or remove any git hook script `.githooks/<your_hook>`. For example:
34
30
35
31
```bash
36
32
#!/usr/bin/env sh
@@ -39,7 +35,7 @@ Utility for setting up git hooks. A Deno port of [husky]
39
35
# file: .githooks/pre-push
40
36
```
41
37
42
-
4. Optionally, add script as [deno task](https://docs.deno.com/runtime/reference/cli/task_runner/).
38
+
4. Optionally, add script as [Deno task](https://docs.deno.com/runtime/reference/cli/task_runner/).
43
39
See [Running as Deno Task](#automatic-initialization-for-fresh-repository) for more information.
44
40
45
41
## Usage as Library
@@ -56,7 +52,7 @@ await init(Deno.cwd());
56
52
57
53
### Running as Deno Task
58
54
59
-
It is helpful to save the script as a Deno task:
55
+
It is helpful to save the script as a [Deno task](https://docs.deno.com/runtime/reference/cli/task_runner/):
60
56
61
57
```json
62
58
{
@@ -81,11 +77,11 @@ For example, you can quickly add/update `pre-commit` by running:
81
77
echo"npm test"> .githooks/pre-commit
82
78
```
83
79
84
-
### (No) Automatic Initialization for Fresh Repository
80
+
### (No) Automatic Initialization
85
81
86
82
Unlike Node, Deno does not support pre- or post- script pattern.
87
83
Prefer to [use Deno task](#running-as-deno-task) and include
88
-
explicit instruction for your team to run it after each `git clone`.
84
+
explicit instruction for your team to run it after each `git clone` or upgrade.
89
85
90
86
### Usage with [lint-staged]
91
87
@@ -98,6 +94,8 @@ deno run -A npm:lint-staged
98
94
# file: .githooks/pre-commit
99
95
```
100
96
97
+
As expected, this should look for any lint-staged config files at the project root. See [lint-staged configuration documentation](https://github.com/lint-staged/lint-staged?tab=readme-ov-file#configuration) for more information.
98
+
101
99
### Skipping Certain Hooks
102
100
103
101
If your git command supports `--no-verify`. You may skip running hooks by adding this flag.
@@ -154,11 +152,49 @@ scripts. Underneath, this run `set -x`.
154
152
GITHOOKS=2 git commit -m "verbose run"
155
153
```
156
154
157
-
## Prior Arts
155
+
## Prior Arts & Acknowledgements
156
+
157
+
### Comparison and Benchmark vs [husky]
158
+
159
+
This project is greatly inspired by [husky]; it is even fair to say this is a direct Deno port of `huksy` . Credits should go to [@typicode](https://github.com/typicode). Please show support over there. In fact, today, you can use `husky` directly in Deno:
160
+
161
+
```bash
162
+
deno run -A npm:husky
163
+
```
164
+
165
+
This project builds upon ideas from `husky` while trying to stay minimal and only extend on some functionality that satisfies my personal needs. It is also an attempt to utilize Deno for more explicit permissions and idiomatic testing (`husky` uses `bash` for tests, which is totally fine but simply not my preference).
166
+
167
+
Regarding performance, both `npm:husky` and `jsr:@vnphanquang/githooks` are comparable, with `husky`
168
+
being 1.02x to 1.05x faster, according to the benchmark of the `init` command run on my machine, as of #968d885:
npm:husky 5.3 ms 187.6 ( 5.0 ms … 14.7 ms) 5.3 ms 5.7 ms 14.7 ms
178
+
jsr:@vnphanquang/githooks 5.4 ms 183.5 ( 5.2 ms … 5.9 ms) 5.5 ms 5.8 ms 5.9 ms
179
+
180
+
summary
181
+
npm:husky
182
+
1.02x faster than jsr:@vnphanquang/githooks
183
+
```
184
+
185
+
You can try the benchmark yourself by cloning the repository and running:
186
+
187
+
```bash
188
+
deno task bench
189
+
```
190
+
191
+
### Similar Projects
158
192
159
-
This project is greatly inspired by [husky]; credits go to [@typicode](https://github.com/typicode). Please show support over there.
193
+
Other projects with similar objective exists. Please show them some love too.
160
194
161
-
[Yakiyo/deno_hooks](https://github.com/Yakiyo/deno_hooks) is a similar project. Please show them some love too.
195
+
-[Yakiyo/deno_hooks](https://github.com/Yakiyo/deno_hooks): also inspired by [husky], written in Deno 1; no tests have been implemented as of this writing.
196
+
-[xCykrix/githooked](https://github.com/xCykrix/githooked): also inspired by [husky] but are likely
197
+
no longer maintained or has been migrated away from Deno towards a standalone shell script.
0 commit comments