poise-git 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.kitchen.yml +3 -0
  4. data/.travis.yml +54 -0
  5. data/.yardopts +7 -0
  6. data/CHANGELOG.md +5 -0
  7. data/Gemfile +36 -0
  8. data/LICENSE +201 -0
  9. data/README.md +151 -0
  10. data/Rakefile +17 -0
  11. data/chef/attributes/default.rb +26 -0
  12. data/chef/recipes/default.rb +22 -0
  13. data/lib/poise_git.rb +24 -0
  14. data/lib/poise_git/cheftie.rb +18 -0
  15. data/lib/poise_git/git_client_providers.rb +36 -0
  16. data/lib/poise_git/git_client_providers/base.rb +93 -0
  17. data/lib/poise_git/git_client_providers/dummy.rb +79 -0
  18. data/lib/poise_git/git_client_providers/system.rb +73 -0
  19. data/lib/poise_git/git_command_mixin.rb +37 -0
  20. data/lib/poise_git/resources.rb +27 -0
  21. data/lib/poise_git/resources/poise_git.rb +252 -0
  22. data/lib/poise_git/resources/poise_git_client.rb +82 -0
  23. data/lib/poise_git/safe_string.rb +25 -0
  24. data/lib/poise_git/version.rb +20 -0
  25. data/poise-git.gemspec +42 -0
  26. data/test/cookbook/metadata.rb +18 -0
  27. data/test/cookbook/recipes/default.rb +96 -0
  28. data/test/gemfiles/chef-12.1.gemfile +23 -0
  29. data/test/gemfiles/chef-12.10.gemfile +23 -0
  30. data/test/gemfiles/chef-12.11.gemfile +23 -0
  31. data/test/gemfiles/chef-12.12.gemfile +22 -0
  32. data/test/gemfiles/chef-12.13.gemfile +22 -0
  33. data/test/gemfiles/chef-12.14.gemfile +19 -0
  34. data/test/gemfiles/chef-12.15.gemfile +19 -0
  35. data/test/gemfiles/chef-12.16.gemfile +19 -0
  36. data/test/gemfiles/chef-12.17.gemfile +19 -0
  37. data/test/gemfiles/chef-12.18.gemfile +19 -0
  38. data/test/gemfiles/chef-12.19.gemfile +19 -0
  39. data/test/gemfiles/chef-12.2.gemfile +23 -0
  40. data/test/gemfiles/chef-12.3.gemfile +23 -0
  41. data/test/gemfiles/chef-12.4.gemfile +24 -0
  42. data/test/gemfiles/chef-12.5.gemfile +23 -0
  43. data/test/gemfiles/chef-12.6.gemfile +23 -0
  44. data/test/gemfiles/chef-12.7.gemfile +23 -0
  45. data/test/gemfiles/chef-12.8.gemfile +23 -0
  46. data/test/gemfiles/chef-12.9.gemfile +23 -0
  47. data/test/gemfiles/chef-12.gemfile +19 -0
  48. data/test/gemfiles/master.gemfile +25 -0
  49. data/test/integration/default/serverspec/default_spec.rb +49 -0
  50. data/test/spec/git_client_providers/dummy_spec.rb +76 -0
  51. data/test/spec/git_client_providers/system_spec.rb +64 -0
  52. data/test/spec/recipe_spec.rb +35 -0
  53. data/test/spec/resources/poise_git_client.rb +64 -0
  54. data/test/spec/resources/poise_git_spec.rb +153 -0
  55. data/test/spec/spec_helper.rb +19 -0
  56. metadata +208 -0
@@ -0,0 +1,17 @@
1
+ #
2
+ # Copyright 2015-2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'poise_boiler/rakefile'
@@ -0,0 +1,26 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ # Default recipe to use to install git.
18
+ default['poise-git']['default_recipe'] = 'poise-git'
19
+
20
+ # Default inversion options.
21
+ default['poise-git']['provider'] = 'auto'
22
+ default['poise-git']['options'] = {}
23
+
24
+ # Attributes for recipe[poise-git]. All values are nil because the actual
25
+ # defaults live in the resource.
26
+ default['poise-git']['recipe']['version'] = nil
@@ -0,0 +1,22 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ poise_git_client 'git' do
18
+ node['poise-git']['recipe'].each do |key, value|
19
+ # Skip nils, use false if you want to disable something.
20
+ send(key, value) unless value.nil?
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ #
2
+ # Copyright 2015-2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+
18
+ module PoiseGit
19
+ autoload :GitClientProviders, 'poise_git/git_client_providers'
20
+ autoload :GitCommandMixin, 'poise_git/git_command_mixin'
21
+ autoload :Resources, 'poise_git/resources'
22
+ autoload :SafeString, 'poise_git/safe_string'
23
+ autoload :VERSION, 'poise_git/version'
24
+ end
@@ -0,0 +1,18 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'poise_git/resources'
18
+ require 'poise_git/git_client_providers'
@@ -0,0 +1,36 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'chef/platform/provider_priority_map'
18
+
19
+ require 'poise_git/git_client_providers/dummy'
20
+ require 'poise_git/git_client_providers/system'
21
+
22
+
23
+ module PoiseGit
24
+ # Inversion providers for the poise_git resource.
25
+ #
26
+ # @since 1.0.0
27
+ module GitClientProviders
28
+ autoload :Base, 'poise_git/git_client_providers/base'
29
+
30
+ # Set up priority maps
31
+ Chef::Platform::ProviderPriorityMap.instance.priority(:poise_git_client, [
32
+ PoiseGit::GitClientProviders::Dummy,
33
+ PoiseGit::GitClientProviders::System,
34
+ ])
35
+ end
36
+ end
@@ -0,0 +1,93 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'chef/provider'
18
+ require 'poise'
19
+
20
+
21
+ module PoiseGit
22
+ module GitClientProviders
23
+ # The provider base class for `poise_git_client`.
24
+ #
25
+ # @see PoiseGit::Resources::PoiseGitClient::Resource
26
+ # @provides poise_git_client
27
+ class Base < Chef::Provider
28
+ include Poise(inversion: :poise_git_client)
29
+ provides(:poise_git_client)
30
+
31
+ # Set default inversion options.
32
+ #
33
+ # @api private
34
+ def self.default_inversion_options(node, new_resource)
35
+ super.merge({
36
+ version: new_resource.version,
37
+ })
38
+ end
39
+
40
+ # The `install` action for the `poise_git_client` resource.
41
+ #
42
+ # @return [void]
43
+ def action_install
44
+ notifying_block do
45
+ install_git
46
+ end
47
+ end
48
+
49
+ # The `uninstall` action for the `poise_git_client` resource.
50
+ #
51
+ # @return [void]
52
+ def action_uninstall
53
+ notifying_block do
54
+ uninstall_git
55
+ end
56
+ end
57
+
58
+ # The path to the `git` binary. This is an output property.
59
+ #
60
+ # @abstract
61
+ # @return [String]
62
+ def git_binary
63
+ raise NotImplementedError
64
+ end
65
+
66
+ # The environment variables for this Git. This is an output property.
67
+ #
68
+ # @return [Hash<String, String>]
69
+ def git_environment
70
+ {}
71
+ end
72
+
73
+ private
74
+
75
+ # Install git.
76
+ #
77
+ # @abstract
78
+ # @return [void]
79
+ def install_git
80
+ raise NotImplementedError
81
+ end
82
+
83
+ # Uninstall git.
84
+ #
85
+ # @abstract
86
+ # @return [void]
87
+ def uninstall_git
88
+ raise NotImplementedError
89
+ end
90
+
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,79 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'poise_git/git_client_providers/base'
18
+
19
+
20
+ module PoiseGit
21
+ module GitClientProviders
22
+ # Inversion provider for the `poise_git_client` resource to use a fake Git,
23
+ # for use in unit tests.
24
+ #
25
+ # @since 1.0.0
26
+ # @see PoiseGit::Resources::PoiseGitClient::Resource
27
+ # @provides poise_git_client
28
+ class Dummy < Base
29
+ provides(:dummy)
30
+
31
+ # Enable by default on ChefSpec.
32
+ #
33
+ # @api private
34
+ def self.provides_auto?(node, _resource)
35
+ node.platform?('chefspec')
36
+ end
37
+
38
+ # Manual overrides for dummy data.
39
+ #
40
+ # @api private
41
+ def self.default_inversion_options(node, resource)
42
+ super.merge({
43
+ git_binary: '/git',
44
+ git_environment: nil,
45
+ })
46
+ end
47
+
48
+ # The `install` action for the `poise_git_client` resource.
49
+ #
50
+ # @return [void]
51
+ def action_install
52
+ # This space left intentionally blank.
53
+ end
54
+
55
+ # The `uninstall` action for the `poise_git_client` resource.
56
+ #
57
+ # @return [void]
58
+ def action_uninstall
59
+ # This space left intentionally blank.
60
+ end
61
+
62
+ # Path to the non-existent Git.
63
+ #
64
+ # @return [String]
65
+ def git_binary
66
+ options['git_binary']
67
+ end
68
+
69
+ # Environment for the non-existent Git.
70
+ #
71
+ # @return [String]
72
+ def git_environment
73
+ options['git_environment'] || super
74
+ end
75
+
76
+ end
77
+ end
78
+ end
79
+
@@ -0,0 +1,73 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'poise_languages'
18
+
19
+ require 'poise_git/git_client_providers/base'
20
+
21
+
22
+ module PoiseGit
23
+ module GitClientProviders
24
+ # A provider for `poise_git_client` to install from distro packages.
25
+ #
26
+ # @since 1.0.0
27
+ # @see PoiseGit::Resources::PoiseGitClient::Resource
28
+ # @provides poise_git_client
29
+ class System < Base
30
+ include PoiseLanguages::System::Mixin
31
+ provides(:system)
32
+ packages('git', {
33
+ omnios: {default: %w{developer/versioning/git}},
34
+ smartos: {default: %w{scmgit}},
35
+ })
36
+
37
+ # Output value for the Git binary we are installing.
38
+ def git_binary
39
+ # What should this be for OmniOS and SmartOS?
40
+ "/usr/bin/git"
41
+ end
42
+
43
+ private
44
+
45
+ # Install git from system packages.
46
+ #
47
+ # @return [void]
48
+ def install_git
49
+ install_system_packages do
50
+ # Unlike language-ish packages, we don't need a headers package.
51
+ dev_package false
52
+ end
53
+ end
54
+
55
+ # Remove git from system packages.
56
+ #
57
+ # @return [void]
58
+ def uninstall_git
59
+ uninstall_system_packages do
60
+ # Unlike language-ish packages, we don't need a headers package.
61
+ dev_package false
62
+ end
63
+ end
64
+
65
+ def system_package_candidates(version)
66
+ # This is kind of silly, could use a refactor in the mixin but just
67
+ # moving on for right now.
68
+ node.value_for_platform(self.class.packages) || %w{git}
69
+ end
70
+
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,37 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'poise/utils'
18
+ require 'poise_languages'
19
+
20
+
21
+ module PoiseGit
22
+ # Mixin for resources and providers which run Git commands.
23
+ #
24
+ # @since 1.0.0
25
+ module GitCommandMixin
26
+ include Poise::Utils::ResourceProviderMixin
27
+
28
+ # Mixin for resources which run Git commands.
29
+ module Resource
30
+ include PoiseLanguages::Command::Mixin::Resource(:git, runtime: :poise_git_client)
31
+ end
32
+
33
+ module Provider
34
+ include PoiseLanguages::Command::Mixin::Provider(:git)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,27 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'poise_git/resources/poise_git_client'
18
+ require 'poise_git/resources/poise_git'
19
+
20
+
21
+ module PoiseGit
22
+ # Chef resources and providers for poise-git.
23
+ #
24
+ # @since 1.0.0
25
+ module Resources
26
+ end
27
+ end