lib/shaddox/shadow.rb in shaddox-0.0.17 vs lib/shaddox/shadow.rb in shaddox-0.0.18

- old
+ new

@@ -41,33 +41,73 @@ def exists(path) system("test -e #{path.exp_path}") end + def exists_d(path) + system("test -d #{path.exp_path}") + end + + def exists_f(path) + system("test -f #{path.exp_path}") + end + def ln_s(source, dest, opts = {}) + ensure_parent_dir(source) + ensure_parent_dir(dest) info "Linking '#{source}' to '#{dest}'", 1 if @verbose FileUtils::ln_s(source.exp_path, dest.exp_path, opts) end def mkdir(path) info "Ensuring directory '#{path}' exists", 1 if @verbose FileUtils::mkdir_p(path.exp_path) end + def ensure_parent_dir(path) + dir, base = File.split(path.exp_path) + mkdir(dir) + end + def ensure_git() unless @git_installed install 'git' @git_installed = true end end - def repo_clone(repo_key, path) - ensure_git() + def repo_deploy(repo_key, deploy_path, opts ={}) + keep_releases = opts[:keep_releases] || 5 repo = @repos[repo_key] - cd path do + + ensure_git() + ensure_parent_dir(deploy_path) + deploy_path = deploy_path.exp_path + + cd deploy_path do + + # Get the current release number + release = 0 + cd 'releases' do + current_max = Dir.entries('.').select { |e| e =~ /\d+/ }.max + release = current_max.to_i + 1 if current_max + end + + # Make a new release dir + release_path = "./releases/#{release}" + mkdir(release_path) + case repo.vcs when :git - sh "git clone #{repo.url}" + # Clone/update repo in vcs: + if exists_d('vcs') + cd 'vcs' do + sh "git fetch #{repo.url} #{repo.branch}:#{repo.branch} --force" + end + else + sh "git clone #{repo.url} vcs -b #{repo.branch} --bare" + end + sh "git clone ./vcs #{release_path} --recursive --brach #{repo.branch}" end end end def install(package)