Created
July 16, 2010 20:03
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
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.
Cool, thanks. Not the case with JavaScript, my native tongue.
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
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