vendorificator 0.5.git.v0.4.0.63.g8e9d54d → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +9 -9
  2. data/.travis.yml +2 -2
  3. data/CHANGELOG.md +10 -0
  4. data/Gemfile +5 -12
  5. data/README.md +27 -1
  6. data/Rakefile +2 -8
  7. data/features/chef_cookbook.feature +4 -4
  8. data/features/download.feature +1 -1
  9. data/features/edgecases.feature +15 -0
  10. data/features/environment.feature +3 -2
  11. data/features/fake_mode.feature +15 -0
  12. data/features/git.feature +4 -4
  13. data/features/overlay.feature +99 -0
  14. data/features/step_definitions/basic.rb +22 -0
  15. data/features/step_definitions/git.rb +16 -0
  16. data/features/step_definitions/vendorificator.rb +9 -4
  17. data/features/support/aruba_ext.rb +4 -0
  18. data/features/support/env.rb +3 -0
  19. data/features/tarball.feature +2 -2
  20. data/features/tarball_edit.feature +3 -3
  21. data/features/tool.feature +6 -4
  22. data/features/tool_shortcuts.feature +3 -3
  23. data/features/tool_specs.feature +62 -0
  24. data/features/vendor.feature +4 -3
  25. data/lib/vendorificator.rb +7 -1
  26. data/lib/vendorificator/cli.rb +12 -11
  27. data/lib/vendorificator/config.rb +32 -1
  28. data/lib/vendorificator/environment.rb +23 -27
  29. data/lib/vendorificator/hooks/chef_cookbook.rb +2 -2
  30. data/lib/vendorificator/overlay.rb +17 -0
  31. data/lib/vendorificator/segment.rb +376 -0
  32. data/lib/vendorificator/segment/overlay.rb +114 -0
  33. data/lib/vendorificator/segment/vendor.rb +115 -0
  34. data/lib/vendorificator/vendor.rb +25 -279
  35. data/lib/vendorificator/vendor/tool.rb +40 -23
  36. data/lib/vendorificator/version.rb +1 -1
  37. data/spec/vendorificator/config_spec.rb +66 -0
  38. data/spec/vendorificator/environment_spec.rb +7 -7
  39. data/spec/vendorificator/fixtures/vendorfiles/overlay.rb +4 -0
  40. data/spec/vendorificator/segment/vendor_spec.rb +19 -0
  41. data/spec/vendorificator/segment_spec.rb +106 -0
  42. data/spec/vendorificator/vendor_spec.rb +0 -89
  43. data/vendorificator.gemspec +5 -5
  44. metadata +45 -29
@@ -5,7 +5,7 @@ require 'vendorificator/vendor'
5
5
 
6
6
  module Vendorificator
7
7
  class Vendor::Tool < Vendor
8
- arg_reader :specs, :command
8
+ arg_reader :specs, :extras, :command
9
9
 
10
10
  def before_conjure!
11
11
  upstream_version # to cache the version in instance attribute,
@@ -14,31 +14,48 @@ module Vendorificator
14
14
  end
15
15
 
16
16
  def conjure!
17
- specs.each do |spec|
18
- src = File.join(environment.git.git_work_tree, spec)
19
- if File.exist?(src)
20
- FileUtils.install File.join(environment.git.git_work_tree, spec),
21
- File.join(git.git_work_tree, spec),
22
- verbose: true
23
- end
24
- end
25
17
  Dir.chdir(git.git_work_tree) do
18
+ git.checkout(
19
+ environment.current_branch, '--', specs_in_repo, extras_in_repo
20
+ ) unless specs_in_repo.empty? && extras_in_repo.empty?
21
+ git.rm({:cached => true}, extras_in_repo) unless extras_in_repo.empty?
26
22
  system self.command or raise RuntimeError, "Command failed"
27
- end
28
- super
29
- end
30
-
31
- def git_add_extra_paths
32
- specs.inject(super) do |rv, path|
33
- rv << path
23
+ super
34
24
  end
35
25
  end
36
26
 
37
27
  def upstream_version
38
28
  @upstream_version ||= git.capturing.
39
- log({:n => 1, :pretty => 'format:%ad-%h', :date => 'short'}, *specs).
29
+ log({:n => 1, :pretty => 'format:%ad-%h', :date => 'short'}, specs_in_repo).
40
30
  strip
41
31
  end
32
+
33
+ private
34
+
35
+ def specs_in_repo
36
+ @spec_in_repo ||= select_by_glob_list(origin_files, specs)
37
+ end
38
+
39
+ def extras_in_repo
40
+ @extras_in_repo ||= select_by_glob_list(origin_files, extras)
41
+ end
42
+
43
+ def select_by_glob_list(haystack, needles)
44
+ return [] if !needles || needles.empty?
45
+ needles = Array(needles)
46
+ haystack.select do |straw|
47
+ needles.any? do |needle|
48
+ File.fnmatch(needle, straw, File::FNM_PATHNAME)
49
+ end
50
+ end
51
+ end
52
+
53
+ def origin_files
54
+ @origin_files ||= git.capturing.
55
+ ls_tree( {:r => true, :z => true, :name_only => true},
56
+ environment.current_branch).
57
+ split("\0")
58
+ end
42
59
  end
43
60
 
44
61
  class Config
@@ -52,12 +69,12 @@ module Vendorificator
52
69
  &block
53
70
  end
54
71
 
55
- def chef_berkshelf(&block)
56
- tool 'cookbooks',
57
- :path => 'cookbooks',
58
- :specs => [ 'Berksfile', 'Berksfile.lock' ],
59
- :command => 'berks install --path vendor/cookbooks',
60
- &block
72
+ def chef_berkshelf(args={}, &block)
73
+ args[:path] ||= 'cookbooks'
74
+ args[:specs] ||= []
75
+ args[:specs] |= [ 'Berksfile', 'Berksfile.lock' ]
76
+ args[:command] = "berks install --path vendor/#{args[:path]}"
77
+ tool 'cookbooks', args, &block
61
78
  end
62
79
  end
63
80
  end
@@ -1,3 +1,3 @@
1
1
  module Vendorificator
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -67,5 +67,71 @@ module Vendorificator
67
67
  assert { config.metadata[:foo] == :bar }
68
68
  end
69
69
  end
70
+
71
+ describe '#overlay' do
72
+ let(:environment) do
73
+ env = Environment.new(Thor::Shell::Basic.new, :quiet,
74
+ 'spec/vendorificator/fixtures/vendorfiles/overlay.rb'
75
+ )
76
+ env.load_vendorfile
77
+
78
+ env
79
+ end
80
+
81
+ it 'assigns an overlay instance to all segments in the block' do
82
+ overlay = environment.segments.first
83
+ assert { overlay.segments.size > 1 }
84
+ overlay.each_segment do |seg|
85
+ assert { seg.overlay != nil }
86
+ end
87
+ end
88
+
89
+ it 'assigns the same overlay instance to all segments in the block' do
90
+ overlay = environment.segments.first
91
+ assert { overlay.segments.size > 1 }
92
+ overlay.each_segment do |vendor|
93
+ assert { vendor.overlay == overlay }
94
+ end
95
+ end
96
+ end
97
+
98
+ describe 'fake_mode?' do
99
+ it 'returns false when config not set' do
100
+ MiniGit::Capturing.stubs(:git).with(:config, 'vendorificator.stub').raises(MiniGit::GitError)
101
+ assert { config.fake_mode? == false }
102
+ end
103
+
104
+ it 'returns true when set to any truish value' do
105
+ stub_fake_mode 'any_truish_value'
106
+ assert { config.fake_mode? == true }
107
+ end
108
+
109
+ it 'returns false when set to empty string' do
110
+ stub_fake_mode ''
111
+ assert { config.fake_mode? == false }
112
+ end
113
+
114
+ it 'returns false when set to false' do
115
+ stub_fake_mode 'false'
116
+ assert { config.fake_mode? == false }
117
+ end
118
+
119
+ it 'returns false when set to no' do
120
+ stub_fake_mode 'no'
121
+ assert { config.fake_mode? == false }
122
+ end
123
+
124
+ it 'returns false when set to 0' do
125
+ stub_fake_mode '0'
126
+ assert { config.fake_mode? == false }
127
+ end
128
+ end
129
+
130
+ private
131
+
132
+ def stub_fake_mode(value)
133
+ MiniGit::Capturing.stubs(:git).with(:config, 'vendorificator.stub').
134
+ returns(value)
135
+ end
70
136
  end
71
137
  end
@@ -57,7 +57,7 @@ module Vendorificator
57
57
  end
58
58
 
59
59
  it "creates a branch if it doesn't exist" do
60
- environment.vendor_instances << stub(
60
+ environment.segments << stub(
61
61
  :branch_name => 'vendor/test', :head => nil,
62
62
  :compute_dependencies! => nil
63
63
  )
@@ -68,8 +68,8 @@ module Vendorificator
68
68
  end
69
69
 
70
70
  it "handles fast forwardable branches" do
71
- environment.vendor_instances << stub(
72
- :branch_name => 'vendor/test', :head => '123456', :in_branch => true,
71
+ environment.segments << stub(
72
+ :branch_name => 'vendor/test', :head => '123456', :fast_forward => true,
73
73
  :name => 'test', :compute_dependencies! => nil
74
74
  )
75
75
  environment.expects(:fast_forwardable?).returns(true)
@@ -108,16 +108,16 @@ module Vendorificator
108
108
  end
109
109
  end
110
110
 
111
- describe '#vendor_instances' do
111
+ describe '#segments' do
112
112
  let(:environment){ Environment.new Thor::Shell::Basic.new, :default, nil }
113
113
 
114
114
  it 'is initialized on a new environment' do
115
- assert { environment.vendor_instances == [] }
115
+ assert { environment.segments == [] }
116
116
  end
117
117
 
118
118
  it 'allows to add/read instances' do
119
- environment.vendor_instances << :foo
120
- assert { environment.vendor_instances == [:foo] }
119
+ environment.segments << :foo
120
+ assert { environment.segments == [:foo] }
121
121
  end
122
122
  end
123
123
 
@@ -0,0 +1,4 @@
1
+ overlay '/some_subdir' do
2
+ vendor 'name', :option => 'value'
3
+ vendor 'other_name', :option => 'other_value'
4
+ end
@@ -0,0 +1,19 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ module Vendorificator
4
+ describe Segment::Vendor do
5
+ describe '#initialize' do
6
+ let(:segment){ Segment::Vendor.new(overlay: 'test', vendor: 'vendor') }
7
+
8
+ it 'assigns overlay' do
9
+ assert { segment.overlay == 'test' }
10
+ end
11
+
12
+ it 'assigns vendor' do
13
+ assert { segment.vendor == 'vendor' }
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+
@@ -0,0 +1,106 @@
1
+ require_relative '../spec_helper'
2
+
3
+ module Vendorificator
4
+ describe Segment do
5
+ describe '#work_dir' do
6
+ it 'includes vendor group' do
7
+ env = basic_environment
8
+ env.stubs(:relative_root_dir)
9
+ env.git.stubs(:git_work_tree)
10
+ categorized = Vendor.new(env, 'test', group: 'group').segment
11
+ uncategorized = Vendor.new(env, 'test').segment
12
+
13
+ assert { categorized.work_dir.include? 'group' }
14
+ deny { uncategorized.work_dir.include? 'group' }
15
+ end
16
+ end
17
+
18
+ describe '#branch_name' do
19
+ it 'includes vendor group' do
20
+ uncategorized = Vendor.new(basic_environment, 'test').segment
21
+ categorized = Vendor.new(basic_environment, 'test', group: 'group').segment
22
+
23
+ deny { uncategorized.branch_name.include? 'group' }
24
+ assert { categorized.branch_name.include? 'group' }
25
+ end
26
+ end
27
+
28
+ describe '#pushable_refs' do
29
+ let(:environment) do
30
+ Environment.new(Thor::Shell::Basic.new) do
31
+ vendor :nginx, :group => :cookbooks
32
+ vendor :nginx_simplecgi, :group => :cookbooks
33
+ end
34
+ end
35
+
36
+ before do
37
+ environment.git.capturing.stubs(:show_ref).returns <<EOF
38
+ a2745fdf2d7e51f139f9417c5ca045b389fa939f refs/heads/master
39
+ 127eb134185e2bf34c79321819b81f8464392d45 refs/heads/vendor/cookbooks/nginx
40
+ 0448bfa569d3d94dcb3e485c8da60fdb33d365f6 refs/heads/vendor/cookbooks/nginx_simplecgi
41
+ a2745fdf2d7e51f139f9417c5ca045b389fa939f refs/remotes/origin/master
42
+ 127eb134185e2bf34c79321819b81f8464392d45 refs/remotes/origin/vendor/cookbooks/nginx
43
+ 0448bfa569d3d94dcb3e485c8da60fdb33d365f6 refs/remotes/origin/vendor/cookbooks/nginx_simplecgi
44
+ e4646a83e6d24322958e1d7a2ed922dae034accd refs/tags/vendor/cookbooks/nginx/1.2.0
45
+ fa0293b914420f59f8eb4c347fb628dcb953aad3 refs/tags/vendor/cookbooks/nginx/1.3.0
46
+ 680dee5e56a0d49ba2ae299bb82189b6f2660c9b refs/tags/vendor/cookbooks/nginx_simplecgi/0.1.0
47
+ EOF
48
+ environment.load_vendorfile
49
+ end
50
+
51
+ it 'includes all own refs' do
52
+ refs = environment['nginx'].pushable_refs
53
+ assert { refs.include? 'refs/heads/vendor/cookbooks/nginx' }
54
+ assert { refs.include? 'refs/tags/vendor/cookbooks/nginx/1.2.0' }
55
+ assert { refs.include? 'refs/tags/vendor/cookbooks/nginx/1.3.0' }
56
+
57
+ refs = environment['nginx_simplecgi'].pushable_refs
58
+ assert { refs.include? 'refs/heads/vendor/cookbooks/nginx_simplecgi' }
59
+ assert { refs.include? 'refs/tags/vendor/cookbooks/nginx_simplecgi/0.1.0' }
60
+ end
61
+
62
+ it "doesn't include other modules' refs" do
63
+ refs = environment['nginx'].pushable_refs
64
+ deny { refs.include? 'refs/tags/vendor/cookbooks/nginx_simplecgi/0.1.0' }
65
+ end
66
+ end
67
+
68
+ describe '#included_in_list?' do
69
+ let(:segment) do
70
+ Vendor.new(basic_environment, 'test_name', :group => 'test_group').segment
71
+ end
72
+
73
+ it 'finds a module by name' do
74
+ assert { segment.included_in_list?(['test_name']) }
75
+ end
76
+
77
+ it 'finds a module by qualified name' do
78
+ assert { segment.included_in_list?(['test_group/test_name']) }
79
+ end
80
+
81
+ it 'finds a module by path' do
82
+ segment.stubs(:work_dir).returns('./vendor/test_group/test_name')
83
+
84
+ assert { segment.included_in_list?(['./vendor/test_group/test_name']) }
85
+ end
86
+
87
+ it 'finds a module by merge commit' do
88
+ segment.stubs(:merged_base).returns('foobar')
89
+ segment.stubs(:work_dir).returns('abc/def')
90
+
91
+ assert { segment.included_in_list?(['foobar']) }
92
+ end
93
+
94
+ it 'finds a module by branch name' do
95
+ segment.stubs(:merged_base).returns('abcdef')
96
+ segment.stubs(:work_dir).returns('abc/def')
97
+ segment.stubs(:branch_name).returns('foo/bar')
98
+
99
+ assert { segment.included_in_list?(['foo/bar']) }
100
+ end
101
+
102
+ end
103
+
104
+ end
105
+ end
106
+
@@ -37,22 +37,6 @@ module Vendorificator
37
37
  assert { Vendor::Categorized.new(basic_environment, 'test', :group => nil).group == nil }
38
38
  end
39
39
 
40
- it 'is inserted into paths and other names' do
41
- uncategorized = Vendor.new(basic_environment, 'test')
42
- categorized = Vendor.new(basic_environment, 'test', :group => :cat)
43
-
44
- deny { uncategorized.branch_name.include? 'cat' }
45
- assert { categorized.branch_name.include? 'cat' }
46
-
47
- deny { uncategorized.path.include? 'cat' }
48
- assert { categorized.path.include? 'cat' }
49
-
50
- uncategorized.stubs(:version).returns(:foo)
51
- categorized.stubs(:version).returns(:foo)
52
- deny { uncategorized.tag_name.include? 'cat' }
53
- assert { categorized.tag_name.include? 'cat' }
54
- end
55
-
56
40
  it 'accepts a deprecated :category option' do
57
41
  vendor = Vendor.new(basic_environment, 'test', :category => 'foo')
58
42
 
@@ -101,79 +85,6 @@ module Vendorificator
101
85
  end
102
86
  end
103
87
 
104
- describe '#pushable_refs' do
105
- before do
106
- environment.git.capturing.stubs(:show_ref).returns <<EOF
107
- a2745fdf2d7e51f139f9417c5ca045b389fa939f refs/heads/master
108
- 127eb134185e2bf34c79321819b81f8464392d45 refs/heads/vendor/cookbooks/nginx
109
- 0448bfa569d3d94dcb3e485c8da60fdb33d365f6 refs/heads/vendor/cookbooks/nginx_simplecgi
110
- a2745fdf2d7e51f139f9417c5ca045b389fa939f refs/remotes/origin/master
111
- 127eb134185e2bf34c79321819b81f8464392d45 refs/remotes/origin/vendor/cookbooks/nginx
112
- 0448bfa569d3d94dcb3e485c8da60fdb33d365f6 refs/remotes/origin/vendor/cookbooks/nginx_simplecgi
113
- e4646a83e6d24322958e1d7a2ed922dae034accd refs/tags/vendor/cookbooks/nginx/1.2.0
114
- fa0293b914420f59f8eb4c347fb628dcb953aad3 refs/tags/vendor/cookbooks/nginx/1.3.0
115
- 680dee5e56a0d49ba2ae299bb82189b6f2660c9b refs/tags/vendor/cookbooks/nginx_simplecgi/0.1.0
116
- EOF
117
- environment.load_vendorfile
118
- end
119
-
120
- let(:environment) do
121
- Environment.new(Thor::Shell::Basic.new) do
122
- vendor :nginx, :group => :cookbooks
123
- vendor :nginx_simplecgi, :group => :cookbooks
124
- end
125
- end
126
-
127
- it 'includes all own refs' do
128
- refs = environment['nginx'].pushable_refs
129
- assert { refs.include? 'refs/heads/vendor/cookbooks/nginx' }
130
- assert { refs.include? 'refs/tags/vendor/cookbooks/nginx/1.2.0' }
131
- assert { refs.include? 'refs/tags/vendor/cookbooks/nginx/1.3.0' }
132
-
133
- refs = environment['nginx_simplecgi'].pushable_refs
134
- assert { refs.include? 'refs/heads/vendor/cookbooks/nginx_simplecgi' }
135
- assert { refs.include? 'refs/tags/vendor/cookbooks/nginx_simplecgi/0.1.0' }
136
- end
137
-
138
- it "doesn't include other modules' refs" do
139
- refs = environment['nginx'].pushable_refs
140
- deny { refs.include? 'refs/tags/vendor/cookbooks/nginx_simplecgi/0.1.0' }
141
- end
142
- end
143
-
144
- describe '#included_in_list?' do
145
- let(:vendor) { Vendor.new(basic_environment, 'test_name', :group => 'test_group') }
146
-
147
- it 'finds a module by name' do
148
- assert { vendor.included_in_list?(['test_name']) }
149
- end
150
-
151
- it 'finds a module by qualified name' do
152
- assert { vendor.included_in_list?(['test_group/test_name']) }
153
- end
154
-
155
- it 'finds a module by path' do
156
- vendor.stubs(:work_dir).returns('./vendor/test_group/test_name')
157
-
158
- assert { vendor.included_in_list?(['./vendor/test_group/test_name']) }
159
- end
160
-
161
- it 'finds a module by merge commit' do
162
- vendor.stubs(:merged).returns('foobar')
163
- vendor.stubs(:work_dir).returns('abc/def')
164
-
165
- assert { vendor.included_in_list?(['foobar']) }
166
- end
167
-
168
- it 'finds a module by branch name' do
169
- vendor.stubs(:merged).returns('abcdef')
170
- vendor.stubs(:work_dir).returns('abc/def')
171
-
172
- vendor.stubs(:branch_name).returns('foo/bar')
173
- assert { vendor.included_in_list?(['foo/bar']) }
174
- end
175
-
176
- end
177
88
  end
178
89
 
179
90
  module Hooks
@@ -29,15 +29,15 @@ Gem::Specification.new do |gem|
29
29
  gem.add_dependency 'minigit', '>= 0.0.3'
30
30
  gem.add_dependency 'awesome_print'
31
31
 
32
- gem.add_development_dependency 'aruba', '0.5.3'
33
- gem.add_development_dependency 'cucumber', '~> 2.0'
32
+ gem.add_development_dependency 'aruba', '~> 0.5.3'
33
+ gem.add_development_dependency 'cucumber', '~> 1.3.10'
34
34
  gem.add_development_dependency 'mocha', '>= 0.14.0'
35
- gem.add_development_dependency 'chef', '>= 10.16.0' unless is_jruby
36
35
  gem.add_development_dependency 'berkshelf' unless is_jruby || !is_1_9_plus
37
36
  gem.add_development_dependency 'vcr'
38
37
  gem.add_development_dependency 'webmock'
39
- gem.add_development_dependency 'wrong', '>= 0.7.0'
38
+ gem.add_development_dependency 'wrong', '~> 0.7'
40
39
  gem.add_development_dependency 'rake'
41
40
  gem.add_development_dependency 'simplecov'
42
- gem.add_development_dependency 'minitest', '~> 5.0.0'
41
+ gem.add_development_dependency 'tee', '~> 1.0'
42
+ gem.add_development_dependency 'minitest', '~> 5.2'
43
43
  end