1

I have this ruby code in a hook, but it does not hang to wait for user input as I would like.

puts 'Do you really want to commit on master? [y/N]'

answer = gets.strip

Is there any way to do this?

vmarquet
  • 2,384
  • 3
  • 25
  • 39

1 Answers1

2

git hooks are not handed a tty so doing something like this is tricky

additionally the framework is designed to never have interactivity. you can hack it together by hijacking /dev/tty -- though this is not portable and not recommended.

the suggested approach instead if you want some explicit user input is to produce an error suggesting the user utilize SKIP=hookid for the next run

for more on this, there are a few duplicates in the issue tracker:


disclaimer: I am the author of pre-commit

anthony sottile
  • 61,815
  • 15
  • 148
  • 207