Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
This paste will be private.
class Vlad::Git set :source, Vlad::Git.new set :git_cmd, "git" ## # Returns the command that will check out +revision+ from the repository # into directory +destination+. +revision+ can be any SHA1 or equivalent # (e.g. branch, tag, etc...) def checkout(revision, destination) destination = 'repo' if destination == '.' revision = 'HEAD' if revision =~ /head/i # Clone from scratch or update the existing copy of the repository. # # NOTE Requires source.checkout to be run separately from other commands # since 'if' can't be joined with && to other shell commands. [ "if [ -d #{destination}/.git ]", "then cd #{destination} && #{git_cmd} checkout -f -b deployed-#{revision} #{revision}", "else #{git_cmd} clone #{repository} #{destination}", "fi" ].join(" ; ") end ## # Returns the command that will export +revision+ from the repository into # the directory +destination+. # # TODO Assumes that checkout will handle the appropriate version. def export(revision_or_source, destination) source_dir = 'repo' if revision_or_source == '.' revision_name = revision_or_source revision_name = 'HEAD' if revision_or_source == "." [ "cd #{source_dir}", "mkdir -p #{destination}", "#{git_cmd} archive --format=tar #{revision_name} | (cd #{destination} && tar xf -)" ].join(" && ") end ## # Returns a command that maps human-friendly revision identifier +revision+ # into a git SHA1. def revision(revision) revision = 'HEAD' if revision =~ /head/i "`#{git_cmd} rev-parse #{revision}`" end end
From the Design Piracy series on my blog: