I'm using inquirer to build a little CLI tool, great library!
I have a script that's my pre-push hook for git below
#!/bin/bash
node ~/my-script.js || exit
When running under git it auto-populates the answer in inquirer, when I run the script manually it works and asks me the question. I've been reading through the issues but I can't figure out why this might happen.
Inquirer won't run in non-tty environment. The git hook is probably called in a sub process or a process without access to the prompt tty.
Thanks @SBoudrias for the quick response, more googling required from me then! Thanks for the hint
Thanks again @SBoudrias - this was the hint I needed
Adding the following command to my pre-hook has made my tool work as expected
exec < /dev/tty #allow interactive shell commands
@bapti Brilliant!!! this thread saved the day.
Since my team uses Husky to manage githooks it was as simple as:
"postcommit": "my-script < /dev/tty"
thanks again!!
On our Windows (git bash) development machines, having"< /dev/tty" inside the package.json Husky command failed with: "The system cannot find the path specified."
This alternate approach worked:
package.json:
"pre-push": "sh hooks/prepush.sh"
prepush.sh:
exec < /dev/tty
node ./hooks/prepush/script.js
@bapti @SBoudrias @eitah it took me hours to solve this problem, thanks guys you are my heroes!
Most helpful comment
@bapti Brilliant!!! this thread saved the day.
Since my team uses Husky to manage githooks it was as simple as:
thanks again!!