From b032f55a003be35f10dae9578bca4e34c68f76c8 Mon Sep 17 00:00:00 2001 From: Jonas Thelemann Date: Wed, 27 Jan 2021 04:20:49 +0100 Subject: [PATCH] fix(shell): double quote params (#824) --- .husky/commit-msg | 6 ++++-- .husky/pre-commit | 4 +++- scripts/pre-commit | 2 +- src/commands/add.ts | 2 +- test/config-dir.sh | 7 +++++-- test/default.sh | 6 ++++-- test/sub-dir.sh | 2 +- 7 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.husky/commit-msg b/.husky/commit-msg index 4f15872e3..567ff71f0 100755 --- a/.husky/commit-msg +++ b/.husky/commit-msg @@ -1,4 +1,6 @@ #!/bin/sh -. "$(dirname $0)/_/husky.sh" -npx --no-install commitlint --edit $1 +# shellcheck source=./_/husky.sh +. "$(dirname "$0")/_/husky.sh" + +npx --no-install commitlint --edit "$1" diff --git a/.husky/pre-commit b/.husky/pre-commit index 84166368b..7d0a96b9c 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,6 @@ #!/bin/sh -. "$(dirname $0)/_/husky.sh" + +# shellcheck source=./_/husky.sh +. "$(dirname "$0")/_/husky.sh" npm test diff --git a/scripts/pre-commit b/scripts/pre-commit index 2b22239fd..bbf9415be 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -4,7 +4,7 @@ echo "husky: installing Git hooks" mkdir -p "$husky_dir/_" echo "_" > "$husky_dir/.gitignore" -cp "$(dirname $0)/husky.sh" "$husky_dir/_" +cp "$(dirname "$0")/husky.sh" "$husky_dir/_" git config core.hooksPath "$husky_dir" echo "husky: ok" diff --git a/src/commands/add.ts b/src/commands/add.ts index 3c3e613a6..bbe6ef79c 100644 --- a/src/commands/add.ts +++ b/src/commands/add.ts @@ -15,7 +15,7 @@ function createHookFile(file: string, cmd: string) { throw new Error(`${file} already exists`) } - const data = ['#!/bin/sh', '. "$(dirname $0)/_/husky.sh"', '', cmd].join('\n') + const data = ['#!/bin/sh', '. "$(dirname "$0")/_/husky.sh"', '', cmd].join('\n') fs.writeFileSync(file, data, 'utf-8') // Show "./file" instead of just "file" diff --git a/test/config-dir.sh b/test/config-dir.sh index f916139be..a040983bb 100644 --- a/test/config-dir.sh +++ b/test/config-dir.sh @@ -1,6 +1,9 @@ -. $(dirname $0)/_functions.sh +# shellcheck shell=bash -# Example: +# shellcheck source=./_functions.sh +. "$(dirname "$0")/_functions.sh" + +# Example: # .config/husky title "config directory" tempDir="/tmp/husky-config-dir-test" diff --git a/test/default.sh b/test/default.sh index 9dc35a5d6..882aad6f9 100644 --- a/test/default.sh +++ b/test/default.sh @@ -1,4 +1,7 @@ -. $(dirname $0)/_functions.sh +# shellcheck shell=bash + +# shellcheck source=./_functions.sh +. "$(dirname "$0")/_functions.sh" title "default" tempDir="/tmp/husky-default-test" @@ -23,4 +26,3 @@ git commit -m "should fail" || echo -e "\e[0;32mOK\e[m" # Uninstall npx --no-install husky uninstall git config core.hooksPath || echo -e "\e[0;32mOK\e[m" - diff --git a/test/sub-dir.sh b/test/sub-dir.sh index 48bb4341a..a69d692f1 100644 --- a/test/sub-dir.sh +++ b/test/sub-dir.sh @@ -1,4 +1,4 @@ -. $(dirname $0)/_functions.sh +. $(dirname "$0")/_functions.sh # Example: # .git