Skip to content

Commit

Permalink
fix: force basename/dirname to treat $0 as an argument (typicod…
Browse files Browse the repository at this point in the history
…e#1132)

* fix: basename: force $0 to be treated as argument

* fix: dirname: force $0 to be treated as argument
  • Loading branch information
mataha authored and nikoladavitkovski committed Sep 2, 2022
1 parent fe43339 commit e9176d2
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"
. "$(dirname -- "$0")/_/husky.sh"

npx --no-install commitlint --edit "$1"
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"
. "$(dirname -- "$0")/_/husky.sh"

npm test
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...
```
Expand Down
2 changes: 1 addition & 1 deletion husky.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
`,
Expand Down
2 changes: 1 addition & 1 deletion test/1_default.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
. "$(dirname "$0")/functions.sh"
. "$(dirname -- "$0")/functions.sh"
setup
install

Expand Down
2 changes: 1 addition & 1 deletion test/2_in-sub-dir.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
. "$(dirname "$0")/functions.sh"
. "$(dirname -- "$0")/functions.sh"
setup
install

Expand Down
2 changes: 1 addition & 1 deletion test/3_from-sub-dir.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
. "$(dirname "$0")/functions.sh"
. "$(dirname -- "$0")/functions.sh"
setup

# Example:
Expand Down
2 changes: 1 addition & 1 deletion test/4_not-git-dir.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
. "$(dirname "$0")/functions.sh"
. "$(dirname -- "$0")/functions.sh"
setup
install

Expand Down
2 changes: 1 addition & 1 deletion test/5_set-add.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
. "$(dirname "$0")/functions.sh"
. "$(dirname -- "$0")/functions.sh"
setup
install

Expand Down
2 changes: 1 addition & 1 deletion test/6_git_command_not_found.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
. "$(dirname "$0")/functions.sh"
. "$(dirname -- "$0")/functions.sh"
setup
install

Expand Down
2 changes: 1 addition & 1 deletion test/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -eu

setup() {
name="$(basename $0)"
name="$(basename -- $0)"
testDir="/tmp/husky-test-$name"
echo
echo "-------------------"
Expand Down

0 comments on commit e9176d2

Please sign in to comment.