tags:

views:

113

answers:

3

Git is notorious by its encouraged length limit for commit message titles: first line should not be more than 50 characters long (to fit an e-mail header).

That reminds me of... well, is there a hook that automatically posts commit messages to twitter as soon as they're pushed to the server?

A: 

Github does this with their "Service Hooks" feature. At first glance, they don't seem to publish the code they use for it, though.

Michael Borgwardt
+2  A: 

Some googling discovered friedcode. Haven't tried it myself but it seems to do the job.

laalto
From that page: "the script ... contains some horrible python one-liners" -- and indeed it does :-) Thanks for the link, anyway.
Pavel Shved
+6  A: 

Here you go:

#!/bin/sh
username=<your Twitter account>
password=<your Twitter password>

service_uri=http://api.twitter.com/1/statuses/update.json

subject=`git log --pretty=format:%s -n1`

curl -u "${username}:${password}" -d status="${subject}" $service_uri

Save as .git/hooks/post-commit in your repository and make it executable.

[Note: completely untested, I just made this up on the spot.]

Jörg W Mittag
Unix shell 1, python 0
Dan Moulding
A suggestion: this should be a post-receive hook, which runs on the remote after you've pushed to it. It gets on stdin all the refs that were updated: "<old-value> <new-value> <ref-name>" so you can do something like `while read line; do fields=($line); subject="$(git log --pretty=format:%s ${fields[0]}..${fields[1]})"; ....; done`.
Jefromi