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

fix(shell): double quote params #824

Merged
merged 4 commits into from Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions .husky/commit-msg
@@ -1,4 +1,6 @@
#!/bin/sh
typicode marked this conversation as resolved.
Show resolved Hide resolved
. "$(dirname $0)/_/husky.sh"

npx --no-install commitlint --edit $1
# shellcheck source=./_/husky.sh
. "$(dirname "$(readlink -f "$0")")/_/husky.sh"

npx --no-install commitlint --edit "$1"
4 changes: 3 additions & 1 deletion .husky/pre-commit
@@ -1,4 +1,6 @@
#!/bin/sh
. "$(dirname $0)/_/husky.sh"

# shellcheck source=./_/husky.sh
. "$(dirname "$(readlink -f "$0")")/_/husky.sh"

npm test
2 changes: 1 addition & 1 deletion scripts/pre-commit
Expand Up @@ -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/_"
dargmuesli marked this conversation as resolved.
Show resolved Hide resolved
git config core.hooksPath "$husky_dir"

echo "husky: ok"
Expand Down
7 changes: 6 additions & 1 deletion src/commands/add.ts
Expand Up @@ -15,7 +15,12 @@ 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 = [
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const data = [
const data = ['#!/bin/sh', '. "$(dirname "$0")/_/husky.sh"', '', cmd].join('\n')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, except for the additional indentation (?) :)

'#!/bin/sh',
'# shellcheck source=./_/husky.sh',
'. "$(dirname "$(readlink -f "$0")")/_/husky.sh"',
cmd,
].join('\n')

fs.writeFileSync(file, data, 'utf-8')
// Show "./file" instead of just "file"
Expand Down
6 changes: 4 additions & 2 deletions test/default.sh
@@ -1,4 +1,7 @@
. $(dirname $0)/_functions.sh
#!/bin/bash
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the shebang can be removed since these scripts are not executable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced that with the shellcheck comment.


# shellcheck source=./_functions.sh
. "$(dirname "$0")/_functions.sh"

title "default"
tempDir="/tmp/husky-default-test"
Expand All @@ -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"

2 changes: 1 addition & 1 deletion test/sub-dir.sh
@@ -1,4 +1,4 @@
. $(dirname $0)/_functions.sh
. $(dirname "$0")/_functions.sh
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 could you change test/config-dir.sh too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


# Example:
# .git
Expand Down