├── .autotest ├── .gitignore ├── CHANGELOG.rdoc ├── Gemfile ├── Manifest.txt ├── README.rdoc ├── Rakefile ├── lib └── vlad │ └── git.rb ├── test └── test_vlad_git.rb └── vlad-git.gemspec /.autotest: -------------------------------------------------------------------------------- 1 | require "autotest/restart" 2 | 3 | Autotest.add_hook :initialize do |at| 4 | at.testlib = "minitest/autorun" 5 | end 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | doc 2 | pkg 3 | Gemfile.lock 4 | -------------------------------------------------------------------------------- /CHANGELOG.rdoc: -------------------------------------------------------------------------------- 1 | === 2.2.0 / 2010-08-22 2 | 3 | * New maintainer, Aaron Suggs! 4 | * Expanded README 5 | * Compatible with Vlad 2.1. 6 | * Fixed git submodule initialization for older git versions (< 1.5.6). 7 | * Add a fast checkout/update mode. [fisons] 8 | 9 | === 2.1.0 / 2009-10-14 10 | 11 | * Added git submodule support. [Balazs Nagy] 12 | 13 | === 2.0.0 / 2009-08-19 14 | 15 | * Birthday! 16 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source :rubygems 2 | gemspec 3 | -------------------------------------------------------------------------------- /Manifest.txt: -------------------------------------------------------------------------------- 1 | .autotest 2 | CHANGELOG.rdoc 3 | Manifest.txt 4 | README.rdoc 5 | Rakefile 6 | lib/vlad/git.rb 7 | test/test_vlad_git.rb 8 | -------------------------------------------------------------------------------- /README.rdoc: -------------------------------------------------------------------------------- 1 | = Git for Vlad 2 | 3 | * http://github.com/jbarnette/vlad-git 4 | * http://rubyhitsquad.com/Vlad_the_Deployer.html 5 | 6 | == Description 7 | 8 | Vlad plugin for Git support. This was previously part of Vlad, but all 9 | modules outside the core recipe have been extracted. 10 | 11 | == Installation 12 | 13 | $ gem install vlad-git 14 | 15 | == Usage 16 | 17 | (Adapted from Vlad's getting started guide: 18 | http://hitsquad.rubyforge.org/vlad/doco/getting_started_txt.html) 19 | 20 | In your Rakefile, load Vlad with the :scm => :git: 21 | 22 | begin 23 | require 'vlad' 24 | Vlad.load :scm => :git 25 | rescue 26 | # do nothing 27 | end 28 | 29 | In config/deploy.rb, set the repository: 30 | 31 | set :application, "project" 32 | set :domain, "example.com" 33 | set :deploy_to, "/path/to/install" 34 | set :repository, 'git@example.com:project' 35 | 36 | By default, vlad-git will deploy origin/master. To deploy an arbitrary 37 | rev-spec, set the :revision in config/deploy.rb: 38 | 39 | set :revision, "origin/my_branch" # Deploy a branch 40 | set :revision, "v2.0" # Deploy a tag 41 | set :revision, "a3539b3f3e9edba1" # Deploy a commit 42 | 43 | == Contributors 44 | 45 | * John Barnette http://github.com/jbarnette 46 | * Aaron Suggs http://github.com/ktheory 47 | 48 | == License 49 | 50 | Copyright 2009 Vlad contributors, John Barnette (code@jbarnette.com) 51 | 52 | Permission is hereby granted, free of charge, to any person obtaining 53 | a copy of this software and associated documentation files (the 54 | 'Software'), to deal in the Software without restriction, including 55 | without limitation the rights to use, copy, modify, merge, publish, 56 | distribute, sublicense, and/or sell copies of the Software, and to 57 | permit persons to whom the Software is furnished to do so, subject to 58 | the following conditions: 59 | 60 | The above copyright notice and this permission notice shall be 61 | included in all copies or substantial portions of the Software. 62 | 63 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 64 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 65 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 66 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 67 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 68 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 69 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 70 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "rubygems" 2 | require "hoe" 3 | 4 | Hoe.plugins.delete :rubyforge 5 | Hoe.plugin :doofus, :git 6 | 7 | Hoe.spec "vlad-git" do 8 | developer "John Barnette", "code@jbarnette.com" 9 | developer "Aaron Suggs", "aaron@ktheory.com" 10 | 11 | self.extra_rdoc_files = FileList["*.rdoc"] 12 | self.history_file = "CHANGELOG.rdoc" 13 | self.readme_file = "README.rdoc" 14 | self.testlib = :minitest 15 | self.extra_deps << ["vlad", ">= 2.1.0"] 16 | end 17 | -------------------------------------------------------------------------------- /lib/vlad/git.rb: -------------------------------------------------------------------------------- 1 | class Vlad::Git 2 | 3 | # Duh. 4 | VERSION = "2.2.0" 5 | 6 | set :source, Vlad::Git.new 7 | set :git_cmd, "git" 8 | 9 | # Returns the command that will check out +revision+ from the 10 | # repository into directory +destination+. +revision+ can be any 11 | # SHA1 or equivalent (e.g. branch, tag, etc...) 12 | 13 | def checkout(revision, destination) 14 | destination = File.join(destination, 'repo') 15 | revision = 'HEAD' if revision =~ /head/i 16 | new_revision = ('HEAD' == revision) ? "origin" : revision 17 | 18 | if fast_checkout_applicable?(revision, destination) 19 | [ "cd #{destination}", 20 | "#{git_cmd} checkout -q origin", 21 | "#{git_cmd} fetch", 22 | "#{git_cmd} reset --hard #{new_revision}", 23 | submodule_cmd, 24 | "#{git_cmd} branch -f deployed-#{revision} #{revision}", 25 | "#{git_cmd} checkout deployed-#{revision}", 26 | "cd -" 27 | ].join(" && ") 28 | else 29 | [ "rm -rf #{destination}", 30 | "#{git_cmd} clone #{repository} #{destination}", 31 | "cd #{destination}", 32 | "#{git_cmd} checkout -f -b deployed-#{revision} #{revision}", 33 | submodule_cmd, 34 | "cd -" 35 | ].join(" && ") 36 | end 37 | end 38 | 39 | # Returns the command that will export +revision+ from the current 40 | # directory into the directory +destination+. Expects to be run 41 | # from +scm_path+ after Vlad::Git#checkout. 42 | 43 | def export(revision, destination) 44 | revision = 'HEAD' if revision =~ /head/i 45 | revision = "deployed-#{revision}" 46 | 47 | [ "mkdir -p #{destination}", 48 | "cd repo", 49 | "#{git_cmd} archive --format=tar #{revision} | (cd #{destination} && tar xf -)", 50 | "#{git_cmd} submodule foreach '#{git_cmd} archive --format=tar $sha1 | (cd #{destination}/$path && tar xf -)'", 51 | "cd -", 52 | "cd .." 53 | ].join(" && ") 54 | end 55 | 56 | # Returns a command that maps human-friendly revision identifier 57 | # +revision+ into a git SHA1. 58 | 59 | def revision(revision) 60 | revision = 'HEAD' if revision =~ /head/i 61 | 62 | "`#{git_cmd} rev-parse #{revision}`" 63 | end 64 | 65 | private 66 | 67 | # Checks if fast-checkout is applicable 68 | def fast_checkout_applicable?(revision, destination) 69 | revision = 'HEAD' if revision =~ /head/i 70 | 71 | begin 72 | cmd = [ "if cd #{destination}", 73 | "#{git_cmd} rev-parse #{revision}", 74 | "#{git_cmd} remote -v | grep -q #{repository}", 75 | "cd -; then exit 0; else exit 1; fi &>/dev/null" ].join(" && ") 76 | run cmd 77 | return true 78 | rescue Rake::CommandFailedError 79 | return false 80 | end 81 | end 82 | 83 | def submodule_cmd 84 | "#{git_cmd} submodule sync && #{git_cmd} submodule update --init --recursive" 85 | end 86 | end 87 | -------------------------------------------------------------------------------- /test/test_vlad_git.rb: -------------------------------------------------------------------------------- 1 | require 'minitest/autorun' 2 | require 'vlad' 3 | require 'vlad/git' 4 | require 'mocha' 5 | 6 | class TestVladGit < MiniTest::Unit::TestCase 7 | def setup 8 | super 9 | @scm = Vlad::Git.new 10 | @scm.stubs(:fast_checkout_applicable?).returns(false) 11 | 12 | @scm_fast = Vlad::Git.new 13 | @scm_fast.stubs(:fast_checkout_applicable?).returns(true) 14 | 15 | set :repository, "git@myhost:/home/john/project1" 16 | end 17 | 18 | # Checkout the way the default :update task invokes the method 19 | def test_checkout 20 | cmd = @scm.checkout 'head', '/the/scm/path' 21 | assert_equal 'rm -rf /the/scm/path/repo && git clone git@myhost:/home/john/project1 /the/scm/path/repo && cd /the/scm/path/repo && git checkout -f -b deployed-HEAD HEAD && git submodule sync && git submodule init && git submodule update && cd -', cmd 22 | end 23 | 24 | # (fast-mode) Checkout the way the default :update task invokes the method 25 | def test_checkout_fast 26 | cmd = @scm_fast.checkout 'head', '/the/scm/path' 27 | assert_equal 'cd /the/scm/path/repo && git checkout -q origin && git fetch && git reset --hard origin && git submodule sync && git submodule init && git submodule update && git branch -f deployed-HEAD HEAD && git checkout deployed-HEAD && cd -', cmd 28 | end 29 | 30 | # This is not how the :update task invokes the method 31 | def test_checkout_revision 32 | # Checkout to the current directory 33 | cmd = @scm.checkout 'master', '.' 34 | assert_equal 'rm -rf ./repo && git clone git@myhost:/home/john/project1 ./repo && cd ./repo && git checkout -f -b deployed-master master && git submodule sync && git submodule init && git submodule update && cd -', cmd 35 | 36 | # Checkout to a relative path 37 | cmd = @scm.checkout 'master', 'some/relative/path' 38 | assert_equal 'rm -rf some/relative/path/repo && git clone git@myhost:/home/john/project1 some/relative/path/repo && cd some/relative/path/repo && git checkout -f -b deployed-master master && git submodule sync && git submodule init && git submodule update && cd -', cmd 39 | end 40 | 41 | # (fast-mode) This is not how the :update task invokes the method 42 | def test_checkout_revision_fast 43 | # Checkout to the current directory 44 | cmd = @scm_fast.checkout 'master', '.' 45 | assert_equal 'cd ./repo && git checkout -q origin && git fetch && git reset --hard master && git submodule sync && git submodule init && git submodule update && git branch -f deployed-master master && git checkout deployed-master && cd -', cmd 46 | 47 | cmd = @scm_fast.checkout 'master', 'some/relative/path' 48 | assert_equal 'cd some/relative/path/repo && git checkout -q origin && git fetch && git reset --hard master && git submodule sync && git submodule init && git submodule update && git branch -f deployed-master master && git checkout deployed-master && cd -', cmd 49 | end 50 | 51 | def test_export 52 | # default mode 53 | cmd = @scm.export 'master', 'the/release/path' 54 | assert_equal "mkdir -p the/release/path && cd repo && git archive --format=tar deployed-master | (cd the/release/path && tar xf -) && git submodule foreach 'git archive --format=tar \$sha1 | (cd the/release/path/\$path && tar xf -)' && cd - && cd ..", cmd 55 | end 56 | 57 | def test_revision 58 | ['head', 'HEAD'].each do |head| 59 | cmd = @scm.revision(head) 60 | expected = "`git rev-parse HEAD`" 61 | assert_equal expected, cmd 62 | end 63 | end 64 | end 65 | 66 | -------------------------------------------------------------------------------- /vlad-git.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | 3 | Gem::Specification.new do |s| 4 | s.name = 'vlad-git' 5 | s.version = "2.2.0" 6 | 7 | s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= 8 | s.authors = ["John Barnette", "Aaron Suggs"] 9 | s.date = %q{2011-09-17} 10 | s.description = %q{Vlad plugin for Git support. This was previously part of Vlad, but all 11 | modules outside the core recipe have been extracted.} 12 | s.email = ["code@jbarnette.com", "aaron@ktheory.com"] 13 | s.extra_rdoc_files = ["Manifest.txt", "CHANGELOG.rdoc", "README.rdoc"] 14 | s.files = [".autotest", "CHANGELOG.rdoc", "Manifest.txt", "README.rdoc", "Rakefile", "lib/vlad/git.rb", "test/test_vlad_git.rb"] 15 | s.homepage = %q{http://github.com/jbarnette/vlad-git} 16 | s.rdoc_options = ["--main", "README.rdoc"] 17 | s.require_paths = ["lib"] 18 | s.rubyforge_project = 'vlad-git' 19 | s.rubygems_version = '1.6.2' 20 | s.summary = %q{Vlad plugin for Git support} 21 | s.test_files = ["test/test_vlad_git.rb"] 22 | 23 | s.add_runtime_dependency('vlad', ">= 2.1.0") 24 | 25 | s.add_development_dependency('hoe', "~> 2.12") 26 | s.add_development_dependency('minitest') 27 | s.add_development_dependency('mocha') 28 | s.add_development_dependency('hoe-doofus') 29 | s.add_development_dependency('hoe-git') 30 | end 31 | --------------------------------------------------------------------------------