Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,22 @@ In config/deploy.rb, set the repository:
set :deploy_to, "/path/to/install"
set :repository, '[email protected]: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
Expand Down
52 changes: 11 additions & 41 deletions lib/vlad/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,29 @@ class Vlad::Git

set :source, Vlad::Git.new
set :git_cmd, "git"
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
# SHA1 or equivalent (e.g. branch, tag, etc...)

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
# directory into the directory +destination+. Expects to be run
# 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 -)",
Expand All @@ -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
Expand Down