ktheory-vlad-git 2.1.0ktheory1

Sign up to get free protection for your applications and to get access to all the features.
data/.autotest ADDED
@@ -0,0 +1,5 @@
1
+ require "autotest/restart"
2
+
3
+ Autotest.add_hook :initialize do |at|
4
+ at.testlib = "minitest/autorun"
5
+ end
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ === 2.1.0 / 2009-10-14
2
+
3
+ * Added git submodule support. [Balazs Nagy]
4
+
5
+ === 2.0.0 / 2009-08-19
6
+
7
+ * Birthday!
data/Manifest.txt ADDED
@@ -0,0 +1,7 @@
1
+ .autotest
2
+ CHANGELOG.rdoc
3
+ Manifest.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/vlad/git.rb
7
+ test/test_vlad_git.rb
data/README.rdoc ADDED
@@ -0,0 +1,40 @@
1
+ = Git for Vlad
2
+
3
+ * http://github.com/jbarnette/vlad-git
4
+ * http://rubyforge.org/projects/hitsquad
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
+ == Examples
12
+
13
+ Vlad.load :scm => :git
14
+
15
+ == Installation
16
+
17
+ $ gem install vlad-git
18
+
19
+ == License
20
+
21
+ Copyright 2009 Vlad contributors, John Barnette (jbarnette@rubyforge.org)
22
+
23
+ Permission is hereby granted, free of charge, to any person obtaining
24
+ a copy of this software and associated documentation files (the
25
+ 'Software'), to deal in the Software without restriction, including
26
+ without limitation the rights to use, copy, modify, merge, publish,
27
+ distribute, sublicense, and/or sell copies of the Software, and to
28
+ permit persons to whom the Software is furnished to do so, subject to
29
+ the following conditions:
30
+
31
+ The above copyright notice and this permission notice shall be
32
+ included in all copies or substantial portions of the Software.
33
+
34
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
35
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
37
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
38
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
39
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
40
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require "rubygems"
2
+ require "hoe"
3
+
4
+ Hoe.plugin :doofus, :git
5
+
6
+ Hoe.spec "ktheory-vlad-git" do
7
+ developer "John Barnette", "jbarnette@rubyforge.org"
8
+
9
+ self.extra_rdoc_files = FileList["*.rdoc"]
10
+ self.history_file = "CHANGELOG.rdoc"
11
+ self.readme_file = "README.rdoc"
12
+ self.rubyforge_name = "hitsquad"
13
+ self.testlib = :minitest
14
+ end
data/lib/vlad/git.rb ADDED
@@ -0,0 +1,87 @@
1
+ class Vlad::Git
2
+
3
+ # Duh.
4
+ VERSION = "2.1.0ktheory1"
5
+
6
+ set :source, Vlad::Git.new
7
+ set :git_cmd, "git"
8
+
9
+ ##
10
+ # Returns the command that will check out +revision+ from the
11
+ # repository into directory +destination+. +revision+ can be any
12
+ # SHA1 or equivalent (e.g. branch, tag, etc...)
13
+
14
+ def checkout(revision, destination)
15
+ destination = File.join(destination, 'repo')
16
+ revision = 'HEAD' if revision =~ /head/i
17
+ new_revision = ('HEAD' == revision) ? "origin" : revision
18
+
19
+ if fast_checkout_applicable?(revision, destination)
20
+ [ "cd #{destination}",
21
+ "#{git_cmd} checkout -q origin",
22
+ "#{git_cmd} fetch",
23
+ "#{git_cmd} reset --hard #{new_revision}",
24
+ "#{git_cmd} submodule init",
25
+ "#{git_cmd} submodule update",
26
+ "#{git_cmd} branch -f deployed-#{revision} #{revision}",
27
+ "#{git_cmd} checkout deployed-#{revision}",
28
+ "cd -"
29
+ ].join(" && ")
30
+ else
31
+ [ "rm -rf #{destination}",
32
+ "#{git_cmd} clone #{repository} #{destination}",
33
+ "cd #{destination}",
34
+ "#{git_cmd} submodule init",
35
+ "#{git_cmd} submodule update",
36
+ "#{git_cmd} checkout -f -b deployed-#{revision} #{revision}",
37
+ "cd -"
38
+ ].join(" && ")
39
+ end
40
+ end
41
+
42
+ ##
43
+ # Returns the command that will export +revision+ from the current directory
44
+ # into the directory +destination+.
45
+ # Expects to be run from +scm_path+ after Vlad::Git#checkout
46
+
47
+ def export(revision, destination)
48
+ revision = 'HEAD' if revision =~ /head/i
49
+ revision = "deployed-#{revision}"
50
+
51
+ [ "mkdir -p #{destination}",
52
+ "cd repo",
53
+ "#{git_cmd} archive --format=tar #{revision} | (cd #{destination} && tar xf -)",
54
+ "#{git_cmd} submodule foreach '#{git_cmd} archive --format=tar $sha1 | (cd #{destination}/$path && tar xf -)'",
55
+ "cd -",
56
+ "cd .."
57
+ ].join(" && ")
58
+ end
59
+
60
+ ##
61
+ # Returns a command that maps human-friendly revision identifier +revision+
62
+ # into a git SHA1.
63
+
64
+ def revision(revision)
65
+ revision = 'HEAD' if revision =~ /head/i
66
+
67
+ "`#{git_cmd} rev-parse #{revision}`"
68
+ end
69
+
70
+ private
71
+
72
+ # Checks if fast-checkout is applicable
73
+ def fast_checkout_applicable?(revision, destination)
74
+ revision = 'HEAD' if revision =~ /head/i
75
+
76
+ begin
77
+ cmd = [ "if cd #{destination}",
78
+ "#{git_cmd} rev-parse #{revision}",
79
+ "#{git_cmd} remote -v | grep -q #{repository}",
80
+ "cd -; then exit 0; else exit 1; fi &>/dev/null" ].join(" && ")
81
+ run cmd
82
+ return true
83
+ rescue Vlad::CommandFailedError
84
+ return false
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,65 @@
1
+ require 'vlad_test_case'
2
+ require 'vlad'
3
+ require 'vlad/git'
4
+ require 'mocha'
5
+
6
+ class TestVladGit < VladTestCase
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 submodule init && git submodule update && git checkout -f -b deployed-HEAD HEAD && 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 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 submodule init && git submodule update && git checkout -f -b deployed-master master && 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 submodule init && git submodule update && git checkout -f -b deployed-master master && 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 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 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
+
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ktheory-vlad-git
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.0ktheory1
5
+ platform: ruby
6
+ authors:
7
+ - John Barnette
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-15 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.3
24
+ version:
25
+ description: |-
26
+ Vlad plugin for Git support. This was previously part of Vlad, but all
27
+ modules outside the core recipe have been extracted.
28
+ email:
29
+ - jbarnette@rubyforge.org
30
+ executables: []
31
+
32
+ extensions: []
33
+
34
+ extra_rdoc_files:
35
+ - Manifest.txt
36
+ - CHANGELOG.rdoc
37
+ - README.rdoc
38
+ files:
39
+ - .autotest
40
+ - CHANGELOG.rdoc
41
+ - Manifest.txt
42
+ - README.rdoc
43
+ - Rakefile
44
+ - lib/vlad/git.rb
45
+ - test/test_vlad_git.rb
46
+ has_rdoc: true
47
+ homepage: http://github.com/jbarnette/vlad-git
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options:
52
+ - --main
53
+ - README.rdoc
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">"
65
+ - !ruby/object:Gem::Version
66
+ version: 1.3.1
67
+ version:
68
+ requirements: []
69
+
70
+ rubyforge_project: hitsquad
71
+ rubygems_version: 1.3.5
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Vlad plugin for Git support
75
+ test_files:
76
+ - test/test_vlad_git.rb