qgadrian / elixir_git_hooks

🪝 Add git hooks to Elixir projects
MIT License
154 stars 16 forks source link

/dev/tty: Device not configured in pre-commit hook #50

Closed stefanluptak closed 3 years ago

stefanluptak commented 4 years ago

I am using construction like this in my pre-commit hook:

exec </dev/tty

    read -n 1 -p "Are you sure, you want to continue? [Ny] " yesno

    case $yesno in
    [yY])
        echo "OK"
        ;;

    *)
        echo "Doing nothing."
        exit 1
        ;;
    esac

    exec <&-

If I run the pre-commit hook directly from my terminal, it works. If I run it with elixir_git_hooks configured like this:

config :git_hooks,
  verbose: true,
  auto_install: true,
  hooks: [
    pre_commit: [
      tasks: [
        {:file, ".githooks/pre-commit"}
      ]
    ]
  ]

It raises an exception saying that .githooks/pre-commit: line 22: /dev/tty: Device not configured

On line 22, is this: exec </dev/tty

Any idea how I could fix this error?

Thanks a lot. :-)

qgadrian commented 3 years ago

There is no input when running the hooks, so tty is not available. I guess something like this could be achieved using an Elixir module.

It's been a while since this issue, so if it's still relevant we can reopen this conversation and I can try to help you out with it.