Skip to content

Commit c3f58f4

Browse files
committed
fix: change source to .
1 parent abb0cce commit c3f58f4

5 files changed

Lines changed: 28 additions & 15 deletions

File tree

.changeset/many-foxes-beam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vnphanquang/githooks": patch
3+
---
4+
5+
change `source` to `.` to support support `sh`

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vnphanquang/githooks",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"exports": {
55
".": "./src/mod.ts",
66
"./bin": "./src/bin.ts",

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ hook_script=$(dirname "$(dirname "$0")")/\${GITHOOKS_CURRENT_HOOK:-$(basename "$
6868
6969
# source the global init script if any
7070
init_script="\${XDG_CONFIG_HOME:-$HOME/.config}/githooks/init"
71-
[ -f "$init_script" ] && source "$init_script"
71+
[ -f "$init_script" ] && . "$init_script"
7272
7373
# skip if GITHOOKS_SKIP=0
7474
[ "$GITHOOKS" = "0" ] && echo "Found GITHOOKS=0. Skipping..." && exit 0

src/init.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export async function init(cwd: string = Deno.cwd()) {
6969
const hookPath = join(hooksUnderscoredDir, hook);
7070
const script = `\
7171
#!/usr/bin/env sh
72-
GITHOOKS_CURRENT_HOOK=${hook} source "$(dirname "$0")/${GITHOOKS_SCRIPT_NAME}" $@
72+
GITHOOKS_CURRENT_HOOK=${hook} . "$(dirname "$0")/${GITHOOKS_SCRIPT_NAME}" $@
7373
`;
7474
return Deno.writeTextFile(hookPath, script, {
7575
create: true,

tests/init.test.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,21 @@ Deno.test({
2929
},
3030
});
3131

32-
async function expectCommonGitInit(cwd: string = Deno.cwd()) {
33-
const { success: gitInitSuccess } = await git(cwd, 'init').output();
34-
expect(gitInitSuccess).toBe(true);
32+
async function expectCommonGitInit(cwd: string = Deno.cwd(), config = false) {
33+
let { success } = await git(cwd, 'init').output();
34+
expect(success).toBe(true);
35+
36+
if (config) {
37+
// configure git user
38+
({ success } = await git(cwd, 'config', 'user.email', 'tester@example.com').output());
39+
expect(success).toBe(true);
40+
({ success } = await git(cwd, 'config', 'user.name', 'Deno Tester').output());
41+
expect(success).toBe(true);
42+
43+
// skip gpg sign
44+
({ success } = await git(cwd, 'config', 'commit.gpgsign', 'false').output());
45+
expect(success).toBe(true);
46+
}
3547
}
3648

3749
const PRE_COMMIT_PATH = path.join(GITHOOKS_DIRNAME, 'pre-commit');
@@ -192,28 +204,24 @@ Deno.test({
192204
await using sbox = await sandbox();
193205

194206
try {
195-
await expectCommonGitInit();
196-
await init();
207+
await expectCommonGitInit(Deno.cwd(), true);
208+
await expectCommonInit(Deno.cwd());
197209

198210
await Deno.writeTextFile('main.ts', 'console.log("hello")');
199211

200212
// add
201-
let { success } = await git(Deno.cwd(), 'add', 'main.ts').output();
202-
expect(success).toBe(true);
203-
204-
// skip gpg sign
205-
({ success } = await git(Deno.cwd(), 'config', 'commit.gpgsign', 'false').output());
213+
const { success } = await git(Deno.cwd(), 'add', 'main.ts').output();
206214
expect(success).toBe(true);
207215

208216
// commit
209217
const { success: commitSuccess, stderr } = await git(
210218
Deno.cwd(),
211219
'commit',
212220
'-m',
213-
'initial commit',
221+
'test pre-commit hook',
214222
).output();
215-
expect(commitSuccess).toBe(true);
216223
expect(new TextDecoder().decode(stderr)).toContain('Checked 1 file');
224+
expect(commitSuccess).toBe(true);
217225
} finally {
218226
await sbox[Symbol.asyncDispose]();
219227
}

0 commit comments

Comments
 (0)