Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force basename/dirname to treat $0 as an argument #1132

Merged
merged 2 commits into from
Apr 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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