typicode / husky

Git hooks made easy 🐶 woof!

Home Page:https://typicode.github.io/husky

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

process.stdin in the `commit-msg` hook script is not a tty

tanhauhau opened this issue · comments

I am using commitizen to prompt user input during commit-msg hook, however the process.stdin of the process is not tty, ie, i couldn't get user keyboard input from the process.

I've created a Pull Request #386 for this issue.

I have the same problem when run pre-commit hook command in docker container:

{
  "hooks": {
     "pre-commit": "docker-compose exec app npm test"
  }
}

There is error message from docker-compose:

the input device is not a TTY

It's an undocumented feature for the moment, but starting with v1.1.4, Husky will source ~/.huskyrc if it exists. This should let people enable things locally.

# ~/.huskyrc
exec < /dev/tty # <- enables interactive shell

Thanks @tanhauhau for the PR

Is ~/.huskyrc documented anywhere? maybe I can help document it down?

@ikokostya Not sure if you've already had this resolved, but you can also try adding -T to disable psuedo-tty (https://docs.docker.com/compose/reference/exec/)

You may lose colors and need to add a npm config set colors always to get colored output on your tests, but you should at least be able to run tests that way too.

commented

Hello, I wrote an npm package, force-stdin-tty to enable stdin in node. Instructions are in the README.

I guess you could also have husky run a shell script that does exec < /dev/tty before running a node script so each developer doesn't have to set up ~/.huskyrc. force-stdin-tty just makes it easier since everything is in javascript.

File issues or contribute to the GitHub repo

It's an undocumented feature for the moment, but starting with v1.1.4, Husky will source ~/.huskyrc if it exists. This should let people enable things locally.

# ~/.huskyrc
exec < /dev/tty # <- enables interactive shell

Thanks @tanhauhau for the PR

Would be possible to have a per-project configuration as well? I mean, besides the .huskyrc file in $HOME, in order to avoid forcing all developers to write their own .huskyrc file (is it possible to place that same file in the project directory?).

Solutions like force-stdin-tty provided by @dosentmatter can be problematic in some cases. I'll present a quite special corner case that is very difficult to fix relying on these workarounds:

I'm working on a tool to run containerized cli tools (like NodeJS and its related binaries: node, npm, npx, yarn...). So far, the tool is working quite well... but when it comes to NodeJS + Husky + Commitizen, it fails miserably.

As many other developers, I'm using Husky to manage some Git hooks, when I use the "native" tools (node+npm+npx) I have no problem, since it's easy to apply the exec < /dev/tty trick inside the hook scripts.

BUT, when I run the containerized tools (even if my "wrapper" is smart enough to toggle correctly the -t and -i flags of the docker run command), there is no simple way to make it work. The exec < /dev/tty trick must be performed BEFORE the npx tool is executed (more specifically, before the container is created; so my tool has enough information to properly auto-configure itself), but right now there is no simple/clean way to configure/parameterize the "lower level layers" of Husky (basically the husky.sh script).

Being able to have a per-project .huskyrc file (and not just per-user), would be really useful.

Closing as husky 5 doesn't have this line of code anymore.