Skip to content

Commit d5c8808

Browse files
sdsShane da Silva
authored and
Shane da Silva
committed
Reopen STDIN when Overcommit isn't installed
Git hooks are not run in an interactive context, meaning STDIN isn't a TTY and so we can't read user input. The solution to this is to reopen STDIN to manually wire up a TTY. Change-Id: Ia12c5cceba26d95313bdf1b1f9d271ef3a421248 Reviewed-on: http://gerrit.causes.com/35618 Reviewed-by: Shane da Silva <shane@causes.com> Tested-by: Shane da Silva <shane@causes.com>
1 parent ef928c8 commit d5c8808

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

template-dir/hooks/overcommit-hook

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ rescue LoadError
2222
puts 'Overcommit is not installed. Install it to manage git hooks for ' <<
2323
'this repository? (y/n)'
2424

25+
# If the hook isn't interactive, we need to map STDIN to keyboard manually
26+
STDIN.reopen('/dev/tty') if STDIN.eof?
27+
2528
if (answer = gets) && answer.strip.downcase.start_with?('y')
2629
if system('gem install overcommit')
2730
require 'overcommit'

0 commit comments

Comments
 (0)