r11na
June 28, 2019, 10:02am
1
I’m trying to write a git pre-push hook using elixir
I want to be able to read user input when the script executes and then depending on the user input proceed with the push or abort.
The problem I’m having is when excuted as a pre-push script, the script immediately exits, not waiting for my IO.gets() command.
When the script is run manually from the cmd line, it correctly waits for user input at IO.gets() and returns the result.
Is there something i’m missing here why does it not properly wait for input when triggered as a pre-push hook?
NobbZ
June 28, 2019, 10:23am
2
Have you tried inspecting the return value of IO.gets/2
? If so, did it really print nothing?
IO.inspect(IO.gets(""))
Also please share some more code. It should not just exit… It should return either a string, :eof
or {:error, reason}
.
r11na
June 28, 2019, 10:29am
3
It does print the IO.gets prompt, but it immediately shows :eof before I get to type anything.
NobbZ
June 28, 2019, 10:44am
4
I took a quick look at the documentation, you should receive local and remote ref data per stdin. You can not ask for user input:
Information about what is to be pushed is provided on the hook’s standard input with lines of the form:
<local ref> SP <local sha1> SP <remote ref> SP <remote sha1> LF
For instance, if the command git push origin master:foreign
were run the hook would receive a line like the following:
refs/heads/master 67890 refs/heads/foreign 12345
2 Likes
r11na
June 28, 2019, 10:47am
5
ah i see, i was afraid i’d be out of luck being able to get user input
thanks for your help, you saved me the time of trying for hours in vain!
Correct, git hooks do not support talking to the user via stdin/stdout as they are already used for other purposes. I however would use something like kdialog
instead (falling back to some defaults or a config file or so when no GUI session). ^.^
r11na
July 2, 2019, 9:40am
7
OvermindDL1:
kdialog
Thanks, I didn’t think of just using a GUI dialog.
Are you aware of something similar to kdialog for OSX?
edit : Seems cocoadialog might be it.
1 Like