Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Created July 16, 2010 20:03
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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

If anybody can think of better variable names for ref_type and ref_name, please suggest!

refs/heads/master
refs/tags/1.0

Need a name that describes both heads and tags, and a name that describes both master and 1.0

@mkroman
Copy link

mkroman commented Aug 21, 2010

The default separator for String#split is $, which is set to ' ', so "oh hi thar".split and "oh hi thar".split(' ') gives the same result.

@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