Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Created July 16, 2010 20:03
Show Gist options
  • Save ryanflorence/478846 to your computer and use it in GitHub Desktop.
Save ryanflorence/478846 to your computer and use it in GitHub Desktop.
Ruby Git post-receive hook to parse out the stdin and assign them to variables
#!/usr/bin/env ruby
# figure out which repository this is
# assumes it's a bare repository
repository = /([^\/]*?)\.git$/.match(`pwd`.chomp)[1]
# get the stdins from git
stdins = []; stdins << $_ while gets
stdins.each do |str|
# parse the stdin string
arr = str.split
refs = arr[2].split('/')
# what we're really after
oldrev = arr[0] # SHA
newrev = arr[1] # SHA
ref_type = refs[1] # tags || heads (branch)
ref_name = refs[2] # develop, 1.4 etc.
# now do whatcha gotta do
end
@ryanflorence
Copy link
Author

Cool, thanks. Not the case with JavaScript, my native tongue.

@dpmcnevin
Copy link

Thanks for this! It helped me create an integration with Pivotal Tracker: https://gist.github.com/895521

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment