From f925192f0605cd205f0bca0cf4a5de12bf21ad7f Mon Sep 17 00:00:00 2001 From: mataha Date: Sat, 16 Apr 2022 15:55:12 +0200 Subject: [PATCH] fix: force `basename`/`dirname` to treat `$0` as an argument (#1132) * fix: basename: force $0 to be treated as argument * fix: dirname: force $0 to be treated as argument --- .husky/commit-msg | 2 +- .husky/pre-commit | 2 +- docs/README.md | 4 ++-- husky.sh | 2 +- src/index.ts | 2 +- test/1_default.sh | 2 +- test/2_in-sub-dir.sh | 2 +- test/3_from-sub-dir.sh | 2 +- test/4_not-git-dir.sh | 2 +- test/5_set-add.sh | 2 +- test/6_git_command_not_found.sh | 2 +- test/functions.sh | 2 +- 12 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.husky/commit-msg b/.husky/commit-msg index 14d810e56..80416c7b1 100755 --- a/.husky/commit-msg +++ b/.husky/commit-msg @@ -1,4 +1,4 @@ #!/usr/bin/env sh -. "$(dirname "$0")/_/husky.sh" +. "$(dirname -- "$0")/_/husky.sh" npx --no-install commitlint --edit "$1" diff --git a/.husky/pre-commit b/.husky/pre-commit index 5834969d0..610c2a54f 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,4 @@ #!/usr/bin/env sh -. "$(dirname "$0")/_/husky.sh" +. "$(dirname -- "$0")/_/husky.sh" npm test diff --git a/docs/README.md b/docs/README.md index 97a850d78..b87cc4ba8 100644 --- a/docs/README.md +++ b/docs/README.md @@ -406,8 +406,8 @@ fi ```shell #!/usr/bin/env sh -. "$(dirname "$0")/_/husky.sh" -. "$(dirname "$0")/common.sh" +. "$(dirname -- "$0")/_/husky.sh" +. "$(dirname -- "$0")/common.sh" yarn ... ``` diff --git a/husky.sh b/husky.sh index 98fac11c5..a09c6caf7 100644 --- a/husky.sh +++ b/husky.sh @@ -6,7 +6,7 @@ if [ -z "$husky_skip_init" ]; then fi } - readonly hook_name="$(basename "$0")" + readonly hook_name="$(basename -- "$0")" debug "starting $hook_name..." if [ "$HUSKY" = "0" ]; then diff --git a/src/index.ts b/src/index.ts index 3a8b2bd50..585a9388f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -64,7 +64,7 @@ export function set(file: string, cmd: string): void { fs.writeFileSync( file, `#!/usr/bin/env sh -. "$(dirname "$0")/_/husky.sh" +. "$(dirname -- "$0")/_/husky.sh" ${cmd} `, diff --git a/test/1_default.sh b/test/1_default.sh index 479b847da..5323688b2 100644 --- a/test/1_default.sh +++ b/test/1_default.sh @@ -1,4 +1,4 @@ -. "$(dirname "$0")/functions.sh" +. "$(dirname -- "$0")/functions.sh" setup install diff --git a/test/2_in-sub-dir.sh b/test/2_in-sub-dir.sh index e58e53b54..7929de8d5 100644 --- a/test/2_in-sub-dir.sh +++ b/test/2_in-sub-dir.sh @@ -1,4 +1,4 @@ -. "$(dirname "$0")/functions.sh" +. "$(dirname -- "$0")/functions.sh" setup install diff --git a/test/3_from-sub-dir.sh b/test/3_from-sub-dir.sh index efbb8bd5b..ff4a6fe7e 100644 --- a/test/3_from-sub-dir.sh +++ b/test/3_from-sub-dir.sh @@ -1,4 +1,4 @@ -. "$(dirname "$0")/functions.sh" +. "$(dirname -- "$0")/functions.sh" setup # Example: diff --git a/test/4_not-git-dir.sh b/test/4_not-git-dir.sh index 230110726..d3488bbef 100644 --- a/test/4_not-git-dir.sh +++ b/test/4_not-git-dir.sh @@ -1,4 +1,4 @@ -. "$(dirname "$0")/functions.sh" +. "$(dirname -- "$0")/functions.sh" setup install diff --git a/test/5_set-add.sh b/test/5_set-add.sh index b5213e7cc..70cae7f58 100644 --- a/test/5_set-add.sh +++ b/test/5_set-add.sh @@ -1,4 +1,4 @@ -. "$(dirname "$0")/functions.sh" +. "$(dirname -- "$0")/functions.sh" setup install diff --git a/test/6_git_command_not_found.sh b/test/6_git_command_not_found.sh index 295c8c9dc..e7e74efe7 100644 --- a/test/6_git_command_not_found.sh +++ b/test/6_git_command_not_found.sh @@ -1,4 +1,4 @@ -. "$(dirname "$0")/functions.sh" +. "$(dirname -- "$0")/functions.sh" setup install diff --git a/test/functions.sh b/test/functions.sh index f16fd4f8c..04a378736 100644 --- a/test/functions.sh +++ b/test/functions.sh @@ -2,7 +2,7 @@ set -eu setup() { - name="$(basename $0)" + name="$(basename -- $0)" testDir="/tmp/husky-test-$name" echo echo "-------------------"