From 12df22c585070c051c0cbca74f4a1fc22d38400a Mon Sep 17 00:00:00 2001 From: Jarl Friis Date: Thu, 11 Oct 2012 11:24:59 +0200 Subject: [PATCH 1/2] simplified code. Reduced amount of code that is cloned --- README.rdoc | 13 +++++++++++-- lib/vlad/git.rb | 52 +++++++++++-------------------------------------- 2 files changed, 22 insertions(+), 43 deletions(-) diff --git a/README.rdoc b/README.rdoc index b428920..ee909ed 100644 --- a/README.rdoc +++ b/README.rdoc @@ -33,13 +33,22 @@ In config/deploy.rb, set the repository: set :deploy_to, "/path/to/install" set :repository, 'git@example.com:project' -By default, vlad-git will deploy origin/master. To deploy an arbitrary +By default, vlad-git will deploy "master". To deploy an arbitrary rev-spec, set the :revision in config/deploy.rb: - set :revision, "origin/my_branch" # Deploy a branch + set :revision, "my_branch" # Deploy a branch set :revision, "v2.0" # Deploy a tag set :revision, "a3539b3f3e9edba1" # Deploy a commit +If you want to deploy from your local repository, you can use + + set :repository, "file://#{Dir.pwd}" + +But you should be aware the that :revision refers branches, tags, +commit-ids in the repository, and branch names may be different in +your repository from branch names in a remote repository. And tags and +commit-ids may not be up to date. + == Contributors * John Barnette http://github.com/jbarnette diff --git a/lib/vlad/git.rb b/lib/vlad/git.rb index 2611cfe..b10a841 100644 --- a/lib/vlad/git.rb +++ b/lib/vlad/git.rb @@ -5,6 +5,7 @@ class Vlad::Git set :source, Vlad::Git.new set :git_cmd, "git" + set :revision, "master" ##This can be either branch, tag or git-commit # Returns the command that will check out +revision+ from the # repository into directory +destination+. +revision+ can be any @@ -12,28 +13,14 @@ class Vlad::Git def checkout(revision, destination) destination = File.join(destination, 'repo') - revision = 'HEAD' if revision =~ /head/i - new_revision = ('HEAD' == revision) ? "origin" : revision - - if fast_checkout_applicable?(revision, destination) - [ "cd #{destination}", - "#{git_cmd} checkout -q origin", - "#{git_cmd} fetch", - "#{git_cmd} reset --hard #{new_revision}", - submodule_cmd, - "#{git_cmd} branch -f deployed-#{revision} #{revision}", - "#{git_cmd} checkout deployed-#{revision}", - "cd -" - ].join(" && ") - else - [ "rm -rf #{destination}", - "#{git_cmd} clone #{repository} #{destination}", - "cd #{destination}", - "#{git_cmd} checkout -f -b deployed-#{revision} #{revision}", - submodule_cmd, - "cd -" - ].join(" && ") - end + depth = is_commit_id?(revision) ? "0" : "1" + [ "rm -rf #{destination}", + "#{git_cmd} clone --depth=#{depth} #{repository} #{destination}", + "cd #{destination}", + "#{git_cmd} checkout -q #{revision}", + submodule_cmd, + "cd -" + ].join(" && ") end # Returns the command that will export +revision+ from the current @@ -41,9 +28,6 @@ def checkout(revision, destination) # from +scm_path+ after Vlad::Git#checkout. def export(revision, destination) - revision = 'HEAD' if revision =~ /head/i - revision = "deployed-#{revision}" - [ "mkdir -p #{destination}", "cd repo", "#{git_cmd} archive --format=tar #{revision} | (cd #{destination} && tar xf -)", @@ -57,27 +41,13 @@ def export(revision, destination) # +revision+ into a git SHA1. def revision(revision) - revision = 'HEAD' if revision =~ /head/i - "`#{git_cmd} rev-parse #{revision}`" end private - # Checks if fast-checkout is applicable - def fast_checkout_applicable?(revision, destination) - revision = 'HEAD' if revision =~ /head/i - - begin - cmd = [ "if cd #{destination}", - "#{git_cmd} rev-parse #{revision}", - "#{git_cmd} remote -v | grep -q #{repository}", - "cd -; then exit 0; else exit 1; fi &>/dev/null" ].join(" && ") - run cmd - return true - rescue Rake::CommandFailedError - return false - end + def is_commit_id?(revision) + revision.match(/^[0-9a-f]{6,40}$/) ? true : false end def submodule_cmd From 52293e1fa79fdb655088da1dfb5525ff789b038f Mon Sep 17 00:00:00 2001 From: Jarl Friis Date: Thu, 11 Oct 2012 13:02:48 +0200 Subject: [PATCH 2/2] Only uses master as fallback --- lib/vlad/git.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vlad/git.rb b/lib/vlad/git.rb index b10a841..a6fb558 100644 --- a/lib/vlad/git.rb +++ b/lib/vlad/git.rb @@ -5,7 +5,7 @@ class Vlad::Git set :source, Vlad::Git.new set :git_cmd, "git" - set :revision, "master" ##This can be either branch, tag or git-commit + set :revision, (revision || "master") ##This can be either branch, tag or git-commit # Returns the command that will check out +revision+ from the # repository into directory +destination+. +revision+ can be any