views:

42

answers:

1

I've created a post-receive hook in git. The hook output messages to the screen, which are sent back to the git client doing the push, and outputted back.

How can I get rid of the 'remote: ' text before every single line of output? It's rather distracting. (I know it's possible because I've seen it in practice, I just don't know how it's done.)

+3  A: 

Note: The prefix can be important to avoid mistaking messages from the remote system as messages from the local system.

That said, there is no way to turn off the prefix, but they are all written to stderr. You could redirect/capture/filter the stderr of git push to do what you want.

A rough way of doing might be something like this:

git push ... 2>&1 | sed -e 's/^remote: //'

It sends stdout to a pipe and makes stderr goto the same place. At the other end of the pipe, sed reads the combined output and deletes any remote: prefixes. This should be okay since it we are unlikely to see remote: prefixes in the stdout stream. Combining stdout and stderr like this is generally acceptable for interactive use (since they were probably going to the same tty device anyway), but it may not be a good idea for use in automated contexts (e.g scripts).

Chris Johnsen
+1, and a second voice saying "you probably shouldn't take remove the prefix, it means something important."
Jefromi
Is it possible to do it from the server side? (heroku.com does it) And the messages are indented with arrows anyway to show that the messages are coming from remote.
dkulchenko
As far as I can tell, the status messages that Heroku sends back are sent outside of the Git protocol (directly through the stderr of the SSH connection; i.e. SSH_MSG_CHANNEL_EXTENDED_DATA/SSH_EXTENDED_DATA_STDERR messages). To replicate this, you would have the incoming SSH connection run some program instead of *git-receive-pack* (e.g. a script) where you could generate messages to stderr. Such a program should run the actual *git-receive-pack* before/after/between writing to stderr.
Chris Johnsen