Skip to content

Instantly share code, notes, and snippets.

@minhajuddin
Created December 10, 2010 09:48
Show Gist options
  • Save minhajuddin/736033 to your computer and use it in GitHub Desktop.
Save minhajuddin/736033 to your computer and use it in GitHub Desktop.
Post receive hook for git syncing
#!/usr/bin/env ruby
class Sync
def initialize(gitpart)
@from, @to, @ref = gitpart.split
@branch = @ref.split('/').last
end
def exec
puts '---------- executing receive hook ----------'
case @branch
when "dev"
push "cv-mirror"
when "master"
push "cv-mirror"
push "github-mirror"
when "deploy"
push "cv-mirror"
push "github-mirror"
puts 'deploying to remote server'
end
puts '---------- executed receive hook ----------'
end
private
def push(remote)
puts ">>>>> pushing to #{@branch} to #{remote}"
op = `git push #{remote} #{@branch}`
puts op
puts ">>>>> pushed to #{@branch} to #{remote}"
end
end
Sync.new(ARGF.read).exec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment