0

I am trying to take input from git hook execution code(commit-msg hook). But the ruby is not able to stop at the input point. And its executing the code as if input is like a puts statement. Here is the code I tried and failed.

#!/usr/bin/env ruby
require 'open3'

def take_input_here

  Open3.popen3("pwd", :chdir=>"/") {|stdin, stdout, stderr, thread|
    p stdout.read.chomp #=> "/"
  }

  input_val = gets.chomp
  puts input_val
  puts 'Hellow World!'
end
take_input_here
puts "Commit Aborted."
Process.exit(1)

Somebody please help my take this interactive input or else suggest me a good language for writing git hooks. Thanks in advance.

SV Madhava Reddy
  • 1,858
  • 2
  • 15
  • 33

1 Answers1

0

Most Git hooks are run with stdin either coming from a pipe to which Git writes information, or with stdin disconnected from the terminal entirely. The commit-msg hook falls into this second category.

It won't matter which language you use: reading stdin in a commit-msg hook will see EOF immediately, as stdin is connected to /dev/null (Linux/Unix) or NUL: (Windows).

On Unix-like systems, you can try opening /dev/tty. Note that if Git is being run from something that doesn't have a /dev/tty (some detached process, e.g., via cron) or where reading /dev/tty is bad for some other reason, this may cause other issues, so be careful with this.

torek
  • 448,244
  • 59
  • 642
  • 775