Skip to content

Instantly share code, notes, and snippets.

@pobo380
Created September 4, 2012 16:56
Show Gist options
  • Save pobo380/3623427 to your computer and use it in GitHub Desktop.
Save pobo380/3623427 to your computer and use it in GitHub Desktop.
post-commit-hook-for-git
#!/usr/bin/ruby
require 'fileutils'
log = open('|git log HEAD -1 --name-only --pretty="format:"').read
base_changes = log.scan(/^base\/(.*)\.(textile|yaml)$/)
unless base_changes.empty?
base_changes.each do |path, ext|
src_path, dest_path = ['base/', 'html/'].map{|e| e + path}
FileUtils.mkpath(File.dirname(dest_path))
FileUtils.cp(src_path + '.' + ext, dest_path + '.copied.html')
end
puts open('|git add html/').read
puts open('|git commit html/ -m "auto commit"').read
puts open('|git checkout adjusted').read
puts open('|git merge source').read
end
html_changes = log.scan(/^html\/(.*)\.html$/)
unless html_changes.empty?
puts open('|git push origin adjusted')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment