Skip to content

Instantly share code, notes, and snippets.

@gumayunov
Created June 27, 2009 16:54
Show Gist options
  • Save gumayunov/137045 to your computer and use it in GitHub Desktop.
Save gumayunov/137045 to your computer and use it in GitHub Desktop.
set :git_reuse_repo, true
class Vlad::Git
def checkout(revision, destination)
destination = File.join(destination, 'repo')
revision = 'HEAD' if revision =~ /head/i
cached_upate = [
"cd #{destination}",
"#{git_cmd} fetch origin",
"#{git_cmd} reset --hard origin/#{revision}"
].join " && "
clone = [
"#{git_cmd} clone #{repository} #{destination}",
"cd #{destination}",
"#{git_cmd} checkout -f -b deployed-#{revision} #{revision}"
].join " && "
update = if defined?(git_reuse_repo) && git_reuse_repo
"if [ -e #{destination} ]; then #{cached_upate}; else #{clone}; fi"
else
"rm -rf #{destination} && #{clone}"
end
"sh -c \"#{update}\""
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment