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

Husky 4.x: Usage of SHELL environment variable can cause unexpected behavior #683

Closed
barretron opened this issue Mar 3, 2020 · 2 comments · Fixed by #707
Closed

Husky 4.x: Usage of SHELL environment variable can cause unexpected behavior #683

barretron opened this issue Mar 3, 2020 · 2 comments · Fixed by #707

Comments

@barretron
Copy link

barretron commented Mar 3, 2020

I'm not sure if this is an actual bug or if this is just something that might need to be documented, but I was running into problems upgrading to Husky 4.x and finally figured out what the issue was.

Background
My company sets /bin/tcsh as the default shell, but I override this in the user settings of apps like VSCode and Terminal.app to use /bin/zsh. As a result, Husky uses /bin/tcsh to run its scripts since the SHELL environment variable remains unchanged. However, tcsh behaves differently from sh in that it uses a login shell with -c unless the -f flag is set. Unfortunately, my company's standard login script (.cshrc) is destructive and resets the PATH. This results in Husky erroring out due to not being able to find lint-staged. Husky <= 3.x does not have this issue.

Workaround
Exporting a different SHELL environment variable in ~/.huskyrc does the trick:

# ~/.huskyrc
export SHELL=/bin/sh

OS: macOS 10.14.6
Terminal: VSCode integrated terminal
Shell: /bin/zsh

Example output (without workaround):

❯ HUSKY_DEBUG=1 git commit -m "Test commit"
husky:debug husky v4.2.3 - pre-commit
husky:debug Current working directory is /Users/barretron/Documents/projects/co/app/packages/front-end
husky:debug source ~/.huskyrc
husky > pre-commit (node v12.4.0)
lint-staged: Command not found.
husky > pre-commit hook failed (add --no-verify to bypass)
husky:debug yarn run --silent husky-run exited with 1 exit code
@frantic1048
Copy link

An elvish user here. After upgrading to 4.0, I got Parse error: unexpected rune '&' from elvish because hook script uses '&&' operator which only bash like shell supports.

I have to wrap the whole hook script with sh -c to force the script is running in a specific shell.
And it is very unreliable because husky is calling elvish -c 'sh -c <HOOK STUFF>' (which assumes elvish has a '-c' option which accepts command string.) on first.

@typicode
Copy link
Owner

typicode commented Apr 9, 2020

Hi @barretron,

Thanks for raising this issue. Just published a new version 4.2.4. It should always be sh now (like in v3).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants