Skip to content

Instantly share code, notes, and snippets.

@schacon
Created September 16, 2010 18:12
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save schacon/582888 to your computer and use it in GitHub Desktop.
Save schacon/582888 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
# this script takes your current commit, finds all the submodules in it,
# makes them static files in a new tree and updates a branch called 'heroku'
# - this way you can push a project with submodules to heroku easily
# just run this, then run "git push heroku heroku:master"
current_commit = `git rev-parse HEAD`
current_tree = `git rev-parse HEAD^{tree}`
puts "Starting at tree #{current_tree}"
# get a list of submodules
status = `git submodule status`.chomp
subdata = status.split("\n")
subdata.each do |subline|
sharaw, path = subline.split(" ")
sha = sharaw[1, sharaw.size - 1]
remote = path.gsub('/', '-')
puts "Preparing #{remote} at #{sha}"
`git remote add #{remote} #{path} 2>/dev/null` # fetch each submodule into a remote
`git fetch #{remote}`
`git read-tree --prefix=#{path} #{sha}` # for each submodule/sha, read-tree the sha into the path
end
# find heroku parent
prev_commit = `git rev-parse heroku 2>/dev/null`.chomp
pcommit = (prev_commit != "heroku") ? "-p #{prev_commit}" : ''
# write-tree/commit-tree with message of what commit sha it's based on
tree_sha = `git write-tree`.chomp
commit_sha = `echo "deploy at #{current_commit}" | git commit-tree #{tree_sha} #{pcommit}`
puts "COMMIT: #{commit_sha}"
# update-ref
`git update-ref refs/heads/heroku #{commit_sha}`
# reset
`git reset HEAD`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment