Skip to content
Browse files

Initial extraction.

  • Loading branch information...
0 parents commit 8beaf82132344956593068376208c78d42bb09a4 @jbarnette committed Aug 19, 2009
Showing with 163 additions and 0 deletions.
  1. +5 −0 .autotest
  2. +2 −0 .gitignore
  3. +3 −0 CHANGELOG.rdoc
  4. +7 −0 Manifest.txt
  5. +40 −0 README.rdoc
  6. +14 −0 Rakefile
  7. +51 −0 lib/vlad/git.rb
  8. +41 −0 test/test_vlad_git.rb
5 .autotest
@@ -0,0 +1,5 @@
+require "autotest/restart"
+
+Autotest.add_hook :initialize do |at|
+ at.testlib = "minitest/autorun"
+end
2 .gitignore
@@ -0,0 +1,2 @@
+doc
+pkg
3 CHANGELOG.rdoc
@@ -0,0 +1,3 @@
+=== 2.0.0 / 2009-08-19
+
+* Birthday!
7 Manifest.txt
@@ -0,0 +1,7 @@
+.autotest
+CHANGELOG.rdoc
+Manifest.txt
+README.rdoc
+Rakefile
+lib/vlad/git.rb
+test/test_vlad_git.rb
40 README.rdoc
@@ -0,0 +1,40 @@
+= Git for Vlad
+
+* http://github.com/jbarnette/vlad-git
+* http://rubyforge.org/projects/hitsquad
+
+== Description
+
+Vlad plugin for Git support. This was previously part of Vlad, but all
+modules outside the core recipe have been extracted.
+
+== Examples
+
+ Vlad.load :scm => :git
+
+== Installation
+
+ $ gem install vlad-git
+
+== License
+
+Copyright 2009 Vlad contributors, John Barnette (jbarnette@rubyforge.org)
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14 Rakefile
@@ -0,0 +1,14 @@
+require "rubygems"
+require "hoe"
+
+Hoe.plugin :doofus, :git
+
+Hoe.spec "vlad-git" do
+ developer "John Barnette", "jbarnette@rubyforge.org"
+
+ self.extra_rdoc_files = FileList["*.rdoc"]
+ self.history_file = "CHANGELOG.rdoc"
+ self.readme_file = "README.rdoc"
+ self.rubyforge_name = "hitsquad"
+ self.testlib = :minitest
+end
51 lib/vlad/git.rb
@@ -0,0 +1,51 @@
+class Vlad::Git
+
+ VERSION = "2.0.0"
+
+ set :source, Vlad::Git.new
+ set :git_cmd, "git"
+
+ ##
+ # 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
+
+ [ "rm -rf #{destination}",
+ "#{git_cmd} clone #{repository} #{destination}",
+ "cd #{destination}",
+ "#{git_cmd} checkout -f -b deployed-#{revision} #{revision}",
+ "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 -)",
+ "cd -",
+ "cd .."
+ ].join(" && ")
+ end
+
+ ##
+ # Returns a command that maps human-friendly revision identifier +revision+
+ # into a git SHA1.
+
+ def revision(revision)
+ revision = 'HEAD' if revision =~ /head/i
+
+ "`#{git_cmd} rev-parse #{revision}`"
+ end
+end
41 test/test_vlad_git.rb
@@ -0,0 +1,41 @@
+require 'vlad_test_case'
+require 'vlad'
+require 'vlad/git'
+
+class TestVladGit < VladTestCase
+ def setup
+ super
+ @scm = Vlad::Git.new
+ set :repository, "git@myhost:/home/john/project1"
+ end
+
+ # Checkout the way the default :update task invokes the method
+ def test_checkout
+ cmd = @scm.checkout 'head', '/the/scm/path'
+ 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 && cd -', cmd
+ end
+
+ # This is not how the :update task invokes the method
+ def test_checkout_revision
+ # Checkout to the current directory
+ cmd = @scm.checkout 'master', '.'
+ assert_equal 'rm -rf ./repo && git clone git@myhost:/home/john/project1 ./repo && cd ./repo && git checkout -f -b deployed-master master && cd -', cmd
+
+ # Checkout to a relative path
+ cmd = @scm.checkout 'master', 'some/relative/path'
+ 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 && cd -', cmd
+ end
+
+ def test_export
+ cmd = @scm.export 'master', 'the/release/path'
+ assert_equal 'mkdir -p the/release/path && cd repo && git archive --format=tar deployed-master | (cd the/release/path && tar xf -) && cd - && cd ..', cmd
+ end
+
+ def test_revision
+ ['head', 'HEAD'].each do |head|
+ cmd = @scm.revision(head)
+ expected = "`git rev-parse HEAD`"
+ assert_equal expected, cmd
+ end
+ end
+end

0 comments on commit 8beaf82

Please sign in to comment.
Something went wrong with that request. Please try again.