Reading from STDIN on a Git pre-commit hook (with PHP)

I am looking for a way to git-commit wait for standard input. I code this in PHP since my bash skills do not exist, so I do the usual

 <?php $input = trim(fgets(STDIN)); fscanf(STDIN, "%d\n", $line); ?> 

would do the trick, and wait for me to write the material to continue, but it just continues and continues to execute my PHP script anyway.

The idea is that after I flag the release, git will push HEAD to the test web server, send a couple of tweets and let me write some details about the release in CHANGELOG.

While I can write to the file (using exec('mate -w') ), I would like it to hang until I run a quick test on the server. This will allow me to roll back if I notice any errors (lazy, I know).

Thanks for any help!

+5
git php stdin hook
Jul 01 '09 at 8:08
source share
2 answers

In most git hooks, there is something special served up by stdin, or stdin disconnected from the terminal. They are all designed to work non-interactively, so I don’t think the hook is suitable for what you want to do. You can, of course, manually talk to /dev/tty , but I don't think this is a very good idea.

I also do not think that the pre-commit hook is suitable for your task, of course, not every commit you made will be a release of some kind? More suitable is post-reception on a test web server.

+3
Jul 01 '09 at 20:57
source share

I need user input in my hook after merging (written in PHP).

I solved this with this piece of code: trim(exec('exec < /dev/tty && read input && echo $input'))

Do not ask, it works;)

+1
Nov 05 '14 at 10:42 on
source share



All Articles