From e419556fc87b76cc2882d5c6b83b7d88dc359412 Mon Sep 17 00:00:00 2001 From: typicode Date: Thu, 28 Sep 2023 15:51:07 +0200 Subject: [PATCH] refactor: avoid subshell --- src/index.ts | 2 +- test/7_time.sh | 9 +++++++++ test/all.sh | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 test/7_time.sh diff --git a/src/index.ts b/src/index.ts index 033e79dd5..8e1666963 100644 --- a/src/index.ts +++ b/src/index.ts @@ -69,7 +69,7 @@ export default function(dir = '.husky'): void { fs.copyFileSync(new URL('../husky.sh', import.meta.url), p.join(h, 'husky.sh')) // Prepare hooks - const data = `#!/bin/sh\n. "$(dirname "$0")/husky.sh"` + const data = `#!/usr/bin/env sh\n. "\${0%/*}/husky.sh"` for (const hook of hooks) { fs.writeFileSync(p.join(h, hook), data, { mode: 0o755 }) } diff --git a/test/7_time.sh b/test/7_time.sh new file mode 100644 index 000000000..ddc012400 --- /dev/null +++ b/test/7_time.sh @@ -0,0 +1,9 @@ +. "$(dirname -- "$0")/functions.sh" +setup +install + +npx --no-install husky + +git add package.json +echo "echo pre-commit" >.husky/pre-commit +time git commit -m foo diff --git a/test/all.sh b/test/all.sh index 984616224..286459fa8 100644 --- a/test/all.sh +++ b/test/all.sh @@ -7,3 +7,4 @@ sh test/3_from-sub-dir.sh sh test/4_not-git-dir.sh sh test/5_git_command_not_found.sh sh test/6_command_not_found.sh +sh test/7_time.sh \ No newline at end of file