r10k 1.4.2 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (244) hide show
  1. data/.travis.yml +2 -0
  2. data/CHANGELOG.mkd +192 -0
  3. data/CONTRIBUTING.mkd +3 -3
  4. data/Gemfile +4 -0
  5. data/README.mkd +13 -6
  6. data/doc/dynamic-environments/configuration.mkd +77 -8
  7. data/doc/dynamic-environments/git-environments.mkd +12 -2
  8. data/doc/dynamic-environments/quickstart.mkd +6 -0
  9. data/doc/faq.mkd +6 -6
  10. data/doc/git/cloning-and-mirroring.mkd +60 -0
  11. data/doc/git/providers.mkd +68 -0
  12. data/integration/Gemfile +3 -0
  13. data/integration/README.mkd +29 -0
  14. data/integration/configs/README.mkd +7 -0
  15. data/integration/configs/pe/centos-6-64mda +25 -0
  16. data/integration/configs/pe/centos-7-64mda +25 -0
  17. data/integration/configs/pe/debian-6-64mda +25 -0
  18. data/integration/configs/pe/debian-7-64mda +25 -0
  19. data/integration/configs/pe/redhat-6-64mda +25 -0
  20. data/integration/configs/pe/redhat-7-64mda +25 -0
  21. data/integration/configs/pe/sles-11-64mda +25 -0
  22. data/integration/configs/pe/ubuntu-1004-64mda +25 -0
  23. data/integration/configs/pe/ubuntu-1204-64mda +25 -0
  24. data/integration/configs/pe/ubuntu-1404-64mda +25 -0
  25. data/integration/files/README.mkd +4 -0
  26. data/integration/files/hiera.yaml +8 -0
  27. data/integration/files/modules/helloworld/manifests/init.pp +3 -0
  28. data/integration/files/modules/hieratest/manifests/init.pp +3 -0
  29. data/integration/files/modules/unicode/files/pretend_unicode +1 -0
  30. data/integration/files/modules/unicode/manifests/init.pp +6 -0
  31. data/integration/files/pre-suite/prod_env.config +3 -0
  32. data/integration/files/r10k_conf.yaml.erb +9 -0
  33. data/integration/lib/README.mkd +4 -0
  34. data/integration/lib/git_utils.rb +205 -0
  35. data/integration/lib/master_manipulator.rb +205 -0
  36. data/integration/lib/r10k_utils.rb +166 -0
  37. data/integration/manifests/README.mkd +4 -0
  38. data/integration/pre-suite/00_pe_install.rb +4 -0
  39. data/integration/pre-suite/01_git_config.rb +59 -0
  40. data/integration/pre-suite/02_pe_r10k.rb +60 -0
  41. data/integration/pre-suite/03_test_utils.rb +17 -0
  42. data/integration/pre-suite/README.mkd +5 -0
  43. data/integration/test_run_scripts/README.mkd +5 -0
  44. data/integration/test_run_scripts/all_tests-rugged-pe-centos6.sh +20 -0
  45. data/integration/test_run_scripts/all_tests-rugged-pe-rhel7.sh +20 -0
  46. data/integration/test_run_scripts/all_tests-rugged-pe-sles11.sh +20 -0
  47. data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1204.sh +20 -0
  48. data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1404.sh +20 -0
  49. data/integration/test_run_scripts/all_tests-shellgit-pe-centos6.sh +20 -0
  50. data/integration/test_run_scripts/all_tests-shellgit-pe-rhel7.sh +20 -0
  51. data/integration/test_run_scripts/all_tests-shellgit-pe-sles11.sh +20 -0
  52. data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1204.sh +20 -0
  53. data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1404.sh +20 -0
  54. data/integration/test_run_scripts/basic_functionality/all_tests-pe-centos6.sh +20 -0
  55. data/integration/test_run_scripts/command_line/all_tests-pe-centos6.sh +20 -0
  56. data/integration/test_run_scripts/git_source/all_tests-pe-centos6.sh +20 -0
  57. data/integration/test_run_scripts/user_scenario/basic_workflow/all_tests-pe-centos6.sh +20 -0
  58. data/integration/test_run_scripts/user_scenario/complex_workflow/all_tests-pe-centos6.sh +20 -0
  59. data/integration/tests/README.mkd +4 -0
  60. data/integration/tests/basic_functionality/negative/neg_deploy_with_invalid_r10k_yaml.rb +46 -0
  61. data/integration/tests/basic_functionality/negative/neg_deploy_with_missing_r10k_yaml.rb +27 -0
  62. data/integration/tests/command_line/deploy_env_without_mod_update.rb +75 -0
  63. data/integration/tests/command_line/negative/neg_deploy_env_with_module_update.rb +76 -0
  64. data/integration/tests/command_line/negative/neg_invalid_cli_dep_flag.rb +22 -0
  65. data/integration/tests/command_line/negative/neg_invalid_cli_env_flag.rb +22 -0
  66. data/integration/tests/command_line/negative/neg_invalid_cmd_line_arg.rb +24 -0
  67. data/integration/tests/git_source/git_source_git.rb +123 -0
  68. data/integration/tests/git_source/git_source_ssh.rb +84 -0
  69. data/integration/tests/git_source/git_source_submodule.rb +69 -0
  70. data/integration/tests/git_source/negative/neg_git_broken_remote.rb +37 -0
  71. data/integration/tests/git_source/negative/neg_git_unauthorized_https.rb +45 -0
  72. data/integration/tests/git_source/negative/neg_git_unauthorized_ssh.rb +72 -0
  73. data/integration/tests/git_source/negative/neg_git_unicode_branch.rb +34 -0
  74. data/integration/tests/user_scenario/basic_workflow/multi_env_1000_branches.rb +66 -0
  75. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module.rb +110 -0
  76. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module_static.rb +113 -0
  77. data/integration/tests/user_scenario/basic_workflow/multi_env_hiera.rb +93 -0
  78. data/integration/tests/user_scenario/basic_workflow/multi_env_multi_source.rb +132 -0
  79. data/integration/tests/user_scenario/basic_workflow/multi_source_custom_forge_git_module.rb +160 -0
  80. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_basedir.rb +45 -0
  81. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_forge_module.rb +43 -0
  82. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module.rb +40 -0
  83. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module_ref.rb +42 -0
  84. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_remote.rb +44 -0
  85. data/integration/tests/user_scenario/basic_workflow/negative/neg_branch_name_collision.rb +63 -0
  86. data/integration/tests/user_scenario/basic_workflow/negative/neg_disk_full.rb +73 -0
  87. data/integration/tests/user_scenario/basic_workflow/negative/neg_duplicate_module_names.rb +45 -0
  88. data/integration/tests/user_scenario/basic_workflow/negative/neg_inaccessible_forge.rb +51 -0
  89. data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_env_name.rb +33 -0
  90. data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_puppet_file.rb +35 -0
  91. data/integration/tests/user_scenario/basic_workflow/negative/neg_module_specified_at_deleted_release.rb +44 -0
  92. data/integration/tests/user_scenario/basic_workflow/negative/neg_read_only.rb +57 -0
  93. data/integration/tests/user_scenario/basic_workflow/negative/neg_specify_deleted_forge_module.rb +44 -0
  94. data/integration/tests/user_scenario/basic_workflow/single_env_10000_files.rb +73 -0
  95. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_git_module.rb +103 -0
  96. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_module.rb +80 -0
  97. data/integration/tests/user_scenario/basic_workflow/single_env_custom_module.rb +48 -0
  98. data/integration/tests/user_scenario/basic_workflow/single_env_large_files.rb +73 -0
  99. data/integration/tests/user_scenario/basic_workflow/single_env_module_already_installed.rb +81 -0
  100. data/integration/tests/user_scenario/basic_workflow/single_env_module_last_release_deleted.rb +67 -0
  101. data/integration/tests/user_scenario/basic_workflow/single_env_non-existent_base_dir.rb +93 -0
  102. data/integration/tests/user_scenario/basic_workflow/single_env_purge_unmanaged_modules.rb +92 -0
  103. data/integration/tests/user_scenario/basic_workflow/single_env_switch_forge_git_module.rb +116 -0
  104. data/integration/tests/user_scenario/basic_workflow/single_env_unicode_paths.rb +59 -0
  105. data/integration/tests/user_scenario/basic_workflow/single_env_upgrade_forge_mod_revert_change.rb +165 -0
  106. data/integration/tests/user_scenario/complex_workflow/multi_env_add_change_remove.rb +162 -0
  107. data/integration/tests/user_scenario/complex_workflow/multi_env_remove_re-add.rb +110 -0
  108. data/lib/r10k/action/cri_runner.rb +10 -13
  109. data/lib/r10k/cli.rb +3 -8
  110. data/lib/r10k/cli/version.rb +10 -1
  111. data/lib/r10k/deployment/config.rb +26 -6
  112. data/lib/r10k/deployment/config/loader.rb +38 -29
  113. data/lib/r10k/deployment/source.rb +2 -4
  114. data/lib/r10k/environment/git.rb +10 -19
  115. data/lib/r10k/environment/name.rb +86 -0
  116. data/lib/r10k/errors.rb +8 -5
  117. data/lib/r10k/feature.rb +35 -0
  118. data/lib/r10k/feature/collection.rb +23 -0
  119. data/lib/r10k/features.rb +18 -0
  120. data/lib/r10k/git.rb +106 -12
  121. data/lib/r10k/git/alternates.rb +2 -2
  122. data/lib/r10k/git/cache.rb +43 -26
  123. data/lib/r10k/git/errors.rb +12 -6
  124. data/lib/r10k/git/head.rb +3 -0
  125. data/lib/r10k/git/ref.rb +3 -0
  126. data/lib/r10k/git/remote_head.rb +6 -0
  127. data/lib/r10k/git/repository.rb +6 -0
  128. data/lib/r10k/git/rugged.rb +17 -0
  129. data/lib/r10k/git/rugged/bare_repository.rb +86 -0
  130. data/lib/r10k/git/rugged/base_repository.rb +90 -0
  131. data/lib/r10k/git/rugged/cache.rb +11 -0
  132. data/lib/r10k/git/rugged/thin_repository.rb +72 -0
  133. data/lib/r10k/git/rugged/working_repository.rb +99 -0
  134. data/lib/r10k/git/shellgit.rb +9 -0
  135. data/lib/r10k/git/shellgit/bare_repository.rb +29 -0
  136. data/lib/r10k/git/shellgit/base_repository.rb +102 -0
  137. data/lib/r10k/git/shellgit/cache.rb +11 -0
  138. data/lib/r10k/git/shellgit/thin_repository.rb +56 -0
  139. data/lib/r10k/git/shellgit/working_repository.rb +73 -0
  140. data/lib/r10k/git/stateful_repository.rb +80 -0
  141. data/lib/r10k/git/tag.rb +3 -0
  142. data/lib/r10k/git/working_dir.rb +15 -2
  143. data/lib/r10k/logging.rb +73 -36
  144. data/lib/r10k/logging/terminaloutputter.rb +36 -0
  145. data/lib/r10k/module/forge.rb +10 -9
  146. data/lib/r10k/module/git.rb +14 -44
  147. data/lib/r10k/module/metadata_file.rb +31 -0
  148. data/lib/r10k/module/svn.rb +0 -1
  149. data/lib/r10k/module_repository/forge.rb +20 -7
  150. data/lib/r10k/puppetfile.rb +1 -1
  151. data/lib/r10k/settings/container.rb +6 -0
  152. data/lib/r10k/settings/mixin.rb +9 -0
  153. data/lib/r10k/source.rb +2 -3
  154. data/lib/r10k/source/base.rb +5 -5
  155. data/lib/r10k/source/git.rb +11 -86
  156. data/lib/r10k/source/svn.rb +8 -52
  157. data/lib/r10k/util/basedir.rb +4 -4
  158. data/lib/r10k/util/commands.rb +31 -0
  159. data/lib/r10k/util/exec_env.rb +36 -0
  160. data/lib/r10k/util/platform.rb +4 -0
  161. data/lib/r10k/util/purgeable.rb +2 -2
  162. data/lib/r10k/util/subprocess.rb +3 -7
  163. data/lib/r10k/util/subprocess/runner.rb +3 -28
  164. data/lib/r10k/util/subprocess/runner/posix.rb +103 -0
  165. data/lib/r10k/util/subprocess/runner/pump.rb +59 -0
  166. data/lib/r10k/util/subprocess/{windows/runner.rb → runner/windows.rb} +2 -11
  167. data/lib/r10k/util/symbolize_keys.rb +31 -0
  168. data/lib/r10k/version.rb +1 -1
  169. data/lib/shared/puppet/module_tool/metadata.rb +197 -0
  170. data/r10k.gemspec +7 -5
  171. data/spec/fixtures/integration/git/puppet-boolean-bare.tar +0 -0
  172. data/spec/fixtures/module/forge/bad_module/metadata.json +1 -0
  173. data/spec/fixtures/unit/util/subprocess/posix/runner/no-execute.sh +3 -0
  174. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/and_the_expected_version_is_latest/can_fetch_all_versions_of_a_given_module.yml +171 -26
  175. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/and_the_expected_version_is_latest/can_fetch_the_latest_version_of_a_given_module.yml +171 -26
  176. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/and_the_expected_version_is_latest/ignores_deleted_releases.yml +190 -0
  177. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/it_handles_errors_from_forgeapi_puppetlabs_com/raises_an_error_for_a_non-existant_module.yml +34 -0
  178. data/spec/fixtures/vcr/cassettes/R10K_Module_Forge/and_the_expected_version_is_latest/sets_the_expected_version_based_on_the_latest_forge_version.yml +87 -26
  179. data/spec/integration/git/rugged/bare_repository_spec.rb +13 -0
  180. data/spec/integration/git/rugged/thin_repository_spec.rb +14 -0
  181. data/spec/integration/git/rugged/working_repository_spec.rb +13 -0
  182. data/spec/integration/git/shellgit/bare_repository_spec.rb +13 -0
  183. data/spec/integration/git/shellgit/thin_repository_spec.rb +14 -0
  184. data/spec/integration/git/shellgit/working_repository_spec.rb +13 -0
  185. data/spec/integration/git/stateful_repository_spec.rb +104 -0
  186. data/spec/matchers/match_realpath.rb +18 -0
  187. data/spec/shared-contexts/git-fixtures.rb +55 -0
  188. data/spec/shared-examples/git-repository.rb +38 -0
  189. data/spec/shared-examples/git/bare_repository.rb +70 -0
  190. data/spec/shared-examples/git/thin_repository.rb +26 -0
  191. data/spec/shared-examples/git/working_repository.rb +115 -0
  192. data/spec/shared-examples/subprocess-runner.rb +83 -0
  193. data/spec/spec_helper.rb +13 -9
  194. data/spec/unit/action/cri_runner_spec.rb +0 -6
  195. data/spec/unit/action/puppetfile/{cri_action_spec.rb → cri_runner_spec.rb} +0 -0
  196. data/spec/unit/deployment/config/loader_spec.rb +48 -0
  197. data/spec/unit/deployment/config_spec.rb +49 -0
  198. data/spec/unit/environment/git_spec.rb +5 -39
  199. data/spec/unit/environment/name_spec.rb +135 -0
  200. data/spec/unit/feature_spec.rb +50 -0
  201. data/spec/unit/git/alternates_spec.rb +1 -1
  202. data/spec/unit/git/cache_spec.rb +32 -19
  203. data/spec/unit/git/commit_spec.rb +1 -0
  204. data/spec/unit/git/head_spec.rb +1 -6
  205. data/spec/unit/git/ref_spec.rb +0 -23
  206. data/spec/unit/git/rugged/cache_spec.rb +26 -0
  207. data/spec/unit/git/shellgit/cache_spec.rb +27 -0
  208. data/spec/unit/git/stateful_repository_spec.rb +43 -0
  209. data/spec/unit/git/tag_spec.rb +1 -0
  210. data/spec/unit/git/working_dir_spec.rb +1 -0
  211. data/spec/unit/git_spec.rb +74 -0
  212. data/spec/unit/logging/terminaloutputter_spec.rb +53 -0
  213. data/spec/unit/logging_spec.rb +68 -0
  214. data/spec/unit/module/forge_spec.rb +7 -38
  215. data/spec/unit/module/git_spec.rb +7 -38
  216. data/spec/unit/module/metadata_file_spec.rb +69 -0
  217. data/spec/unit/module/svn_spec.rb +0 -4
  218. data/spec/unit/module_repository/forge_spec.rb +22 -1
  219. data/spec/unit/puppet/module_tool/metadata_spec.rb +301 -0
  220. data/spec/unit/settings/container_spec.rb +17 -0
  221. data/spec/unit/source/git_spec.rb +0 -123
  222. data/spec/unit/source/svn_spec.rb +66 -0
  223. data/spec/unit/util/commands_spec.rb +61 -0
  224. data/spec/unit/util/exec_env_spec.rb +56 -0
  225. data/spec/unit/util/subprocess/runner/posix_spec.rb +7 -0
  226. data/spec/unit/util/subprocess/runner/pump_spec.rb +79 -0
  227. data/spec/unit/util/subprocess_spec.rb +3 -2
  228. data/spec/unit/util/symbolize_keys_spec.rb +51 -0
  229. metadata +226 -45
  230. data/lib/r10k/execution.rb +0 -47
  231. data/lib/r10k/module/metadata.rb +0 -47
  232. data/lib/r10k/util/core_ext/hash_ext.rb +0 -19
  233. data/lib/r10k/util/subprocess/io.rb +0 -7
  234. data/lib/r10k/util/subprocess/posix.rb +0 -4
  235. data/lib/r10k/util/subprocess/posix/io.rb +0 -7
  236. data/lib/r10k/util/subprocess/posix/runner.rb +0 -140
  237. data/lib/r10k/util/subprocess/windows.rb +0 -4
  238. data/lib/r10k/util/subprocess/windows/io.rb +0 -6
  239. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions.yml +0 -42
  240. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions/can_fetch_all_versions_of_a_given_module.yml +0 -42
  241. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions/can_fetch_the_latest_version_of_a_given_module.yml +0 -42
  242. data/spec/unit/deployment/source_spec.rb +0 -24
  243. data/spec/unit/module/metadata_spec.rb +0 -68
  244. data/spec/unit/util/core_ext/hash_ext_spec.rb +0 -63
@@ -2,11 +2,6 @@ require 'r10k'
2
2
 
3
3
  module R10K
4
4
 
5
- # @deprecated
6
- class ExecutionFailure < StandardError
7
- attr_accessor :exit_code, :stdout, :stderr
8
- end
9
-
10
5
  # An error class that accepts an optional hash and wrapped error message
11
6
  #
12
7
  class Error < StandardError
@@ -32,8 +27,16 @@ module R10K
32
27
  # @overload initialize(mesg, options)
33
28
  # @param mesg [String] The exception mesg
34
29
  # @param options [Hash] A set of options to store on the exception
30
+ #
31
+ # @options options [Array<String>] :backtrace
35
32
  def initialize(mesg, options = {})
36
33
  super(mesg)
34
+
35
+ bt = options.delete(:backtrace)
36
+ if bt
37
+ set_backtrace(bt)
38
+ end
39
+
37
40
  @options = options
38
41
  end
39
42
  end
@@ -0,0 +1,35 @@
1
+ module R10K
2
+ # Detect whether a given feature is present or absent
3
+ class Feature
4
+
5
+ # @attribute [r] name
6
+ # @return [Symbol] The name of this feature
7
+ attr_reader :name
8
+
9
+ # @param name [Symbol] The name of this feature
10
+ # @param opts [Hash]
11
+ # @param block [Proc] An optional block to detect if this feature is available
12
+ #
13
+ # @option opts [String, Array<String>] :libraries One or more libraries to
14
+ # require to make sure this feature is present.
15
+ def initialize(name, opts = {}, &block)
16
+ @name = name
17
+ @libraries = Array(opts.delete(:libraries))
18
+ @block = block || lambda { true }
19
+ end
20
+
21
+ # @return [true, false] Is this feature available?
22
+ def available?
23
+ @libraries.all? { |lib| library_available?(lib) } && !!@block.call
24
+ end
25
+
26
+ private
27
+
28
+ def library_available?(lib)
29
+ require lib
30
+ true
31
+ rescue ScriptError
32
+ false
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,23 @@
1
+ require 'r10k/feature'
2
+
3
+ # Store all features and indicate if they're available.
4
+ class R10K::Feature::Collection
5
+ def initialize
6
+ @features = {}
7
+ end
8
+
9
+ # @param name [Symbol] The feature to add
10
+ # @param opts [Hash] Additional options for the feature, see {R10K::Feature}
11
+ # @param block [Proc] An optional block to detect if this feature is present
12
+ # @return [void]
13
+ def add(name, opts = {}, &block)
14
+ @features[name] = R10K::Feature.new(name, opts, &block)
15
+ end
16
+
17
+ # @return [true, false] Does a feature by this name exist and is it available?
18
+ def available?(name)
19
+ if @features.key?(name)
20
+ @features[name].available?
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ require 'r10k/feature/collection'
2
+ require 'forwardable'
3
+ require 'r10k/util/commands'
4
+
5
+ module R10K
6
+ module Features
7
+ @features = R10K::Feature::Collection.new
8
+
9
+ class << self
10
+ extend Forwardable
11
+ def_delegators :@features, :add, :available?
12
+ end
13
+ end
14
+ end
15
+
16
+ R10K::Features.add(:shellgit) { R10K::Util::Commands.which('git') }
17
+
18
+ R10K::Features.add(:rugged, :libraries => 'rugged')
@@ -1,16 +1,110 @@
1
+ require 'r10k/features'
2
+ require 'r10k/errors'
3
+ require 'r10k/settings'
4
+
1
5
  module R10K
2
6
  module Git
3
- require 'r10k/git/errors'
4
-
5
- require 'r10k/git/ref'
6
- require 'r10k/git/tag'
7
- require 'r10k/git/head'
8
- require 'r10k/git/remote_head'
9
- require 'r10k/git/commit'
10
-
11
- require 'r10k/git/repository'
12
- require 'r10k/git/cache'
13
- require 'r10k/git/alternates'
14
- require 'r10k/git/working_dir'
7
+ require 'r10k/git/shellgit'
8
+ require 'r10k/git/rugged'
9
+
10
+ # A list of Git providers, sorted by priority. Providers have features that
11
+ # must be available for them to be used, and a module which is the namespace
12
+ # containing the implementation.
13
+ @providers = [
14
+ [:shellgit, {:feature => :shellgit, :module => R10K::Git::ShellGit}],
15
+ [:rugged, {:feature => :rugged, :module => R10K::Git::Rugged}],
16
+ ]
17
+
18
+ # Mark the current provider as invalid.
19
+ #
20
+ # If a provider is set to an invalid provider, we need to make sure that
21
+ # the provider doesn't fall back to the default value, thereby ignoring the
22
+ # explicit value and silently continuing. If the current provider is
23
+ # assigned to this value, no provider will be used until the provider is
24
+ # either reset or assigned a valid provider.
25
+ #
26
+ # @api private
27
+ NULL_PROVIDER = Object.new
28
+
29
+ # Mark the current provider as unset.
30
+ #
31
+ # If the provider has never been set we need to indicate that there is no
32
+ # current value but the default value can be used. If the current provider
33
+ # is assigned to this value and the provider is looked up, the default
34
+ # provider will be looked up and used.
35
+ #
36
+ # @api private
37
+ UNSET_PROVIDER = Object.new
38
+
39
+ # Return the first available Git provider.
40
+ #
41
+ # @raise [R10K::Error] if no Git providers are functional.
42
+ # @return [Module] The namespace of the first available Git implementation.
43
+ # Implementation classes should be looked up against this returned Module.
44
+ def self.default
45
+ _, attrs = @providers.find { |(_, hash)| R10K::Features.available?(hash[:feature]) }
46
+ if attrs.nil?
47
+ raise R10K::Error, "No Git providers are functional."
48
+ end
49
+ attrs[:module]
50
+ end
51
+
52
+ # Manually set the Git provider by name.
53
+ #
54
+ # @param name [Symbol] The name of the Git provider to use.
55
+ # @raise [R10K::Error] if the requested Git provider doesn't exist.
56
+ # @raise [R10K::Error] if the requested Git provider isn't functional.
57
+ # @return [void]
58
+ def self.provider=(name)
59
+ _, attrs = @providers.find { |(providername, _)| name == providername }
60
+ if attrs.nil?
61
+ @provider = NULL_PROVIDER
62
+ raise R10K::Error, "No Git provider named '#{name}'."
63
+ end
64
+ if !R10K::Features.available?(attrs[:feature])
65
+ @provider = NULL_PROVIDER
66
+ raise R10K::Error, "Git provider '#{name}' is not functional."
67
+ end
68
+ @provider = attrs[:module]
69
+ end
70
+
71
+ # @return [Module] The namespace of the first available Git implementation.
72
+ # Implementation classes should be looked up against this returned Module.
73
+ def self.provider
74
+ case @provider
75
+ when NULL_PROVIDER
76
+ raise R10K::Error, "No Git provider set."
77
+ when UNSET_PROVIDER
78
+ @provider = default
79
+ else
80
+ @provider
81
+ end
82
+ end
83
+
84
+ def self.cache
85
+ provider::Cache
86
+ end
87
+
88
+ def self.bare_repository
89
+ provider::BareRepository
90
+ end
91
+
92
+ def self.thin_repository
93
+ provider::ThinRepository
94
+ end
95
+
96
+ # Clear the currently set provider.
97
+ #
98
+ # @api private
99
+ def self.reset!
100
+ @provider = UNSET_PROVIDER
101
+ end
102
+
103
+ @provider = UNSET_PROVIDER
104
+
105
+ extend R10K::Settings::Mixin::ClassMethods
106
+
107
+ def_setting_attr :private_key
108
+ def_setting_attr :username
15
109
  end
16
110
  end
@@ -9,9 +9,9 @@ class R10K::Git::Alternates
9
9
  # @return [Pathname] The alternates file
10
10
  attr_reader :file
11
11
 
12
- # @param git_dir [String] The path to the git repository
12
+ # @param git_dir [Pathname] The path to the git repository
13
13
  def initialize(git_dir)
14
- @file = Pathname.new(File.join(git_dir, 'objects', 'info', 'alternates'))
14
+ @file = git_dir + File.join('objects', 'info', 'alternates')
15
15
  end
16
16
 
17
17
  def to_a
@@ -1,22 +1,28 @@
1
1
  require 'r10k/git'
2
- require 'r10k/git/repository'
3
2
 
4
3
  require 'r10k/settings'
5
- require 'r10k/registry'
4
+ require 'r10k/instance_cache'
5
+ require 'forwardable'
6
6
 
7
- # Mirror a git repository for use shared git object repositories
7
+ # Cache Git repository mirrors for object database reuse.
8
8
  #
9
+ # This implements most of the behavior needed for Git repo caching, but needs
10
+ # to have a specific Git bare repository provided. Subclasses should implement
11
+ # the {bare_repository} method.
12
+ #
13
+ # @abstract
9
14
  # @see man git-clone(1)
10
- class R10K::Git::Cache < R10K::Git::Repository
15
+ class R10K::Git::Cache
11
16
 
12
17
  include R10K::Settings::Mixin
13
18
 
14
19
  def_setting_attr :cache_root, File.expand_path(ENV['HOME'] ? '~/.r10k/git': '/root/.r10k/git')
15
20
 
16
- # Lazily construct an instance cache for R10K::Git::Cache objects
21
+ @instance_cache = R10K::InstanceCache.new(self)
22
+
17
23
  # @api private
18
24
  def self.instance_cache
19
- @instance_cache ||= R10K::InstanceCache.new(self)
25
+ @instance_cache
20
26
  end
21
27
 
22
28
  # Generate a new instance with the given remote or return an existing object
@@ -29,58 +35,69 @@ class R10K::Git::Cache < R10K::Git::Repository
29
35
  instance_cache.generate(remote)
30
36
  end
31
37
 
38
+ # @abstract
39
+ # @return [Object] The concrete bare repository implementation to use for
40
+ # interacting with the cached Git repository.
41
+ def self.bare_repository
42
+ raise NotImplementedError
43
+ end
44
+
32
45
  include R10K::Logging
33
46
 
47
+ extend Forwardable
48
+
49
+ def_delegators :@repo, :git_dir, :branches, :tags, :exist?, :resolve, :ref_type
50
+
34
51
  # @!attribute [r] path
35
52
  # @deprecated
36
53
  # @return [String] The path to the git cache repository
37
54
  def path
38
55
  logger.warn "#{self.class}#path is deprecated; use #git_dir"
39
- @git_dir
56
+ git_dir
40
57
  end
41
58
 
42
- # @param [String] remote
43
- # @param [String] cache_root
59
+ # @!attribute [r] repo
60
+ # @api private
61
+ attr_reader :repo
62
+
63
+ # @param remote [String] The URL of the Git remote URL to cache.
44
64
  def initialize(remote)
45
65
  @remote = remote
46
-
47
- @git_dir = File.join(settings[:cache_root], sanitized_dirname)
66
+ @repo = self.class.bare_repository.new(settings[:cache_root], sanitized_dirname)
48
67
  end
49
68
 
50
69
  def sync
51
- if not @synced
70
+ if !@synced
52
71
  sync!
53
72
  @synced = true
54
73
  end
55
74
  end
56
75
 
76
+ def synced?
77
+ @synced
78
+ end
79
+
57
80
  def sync!
58
81
  if cached?
59
- fetch
82
+ @repo.fetch
60
83
  else
61
- logger.debug "Creating new git cache for #{@remote.inspect}"
84
+ logger.debug1 "Creating new git cache for #{@remote.inspect}"
62
85
 
63
86
  # TODO extract this to an initialization step
64
- unless File.exist? settings[:cache_root]
87
+ if !File.exist?(settings[:cache_root])
65
88
  FileUtils.mkdir_p settings[:cache_root]
66
89
  end
67
90
 
68
- git ['clone', '--mirror', @remote, git_dir]
91
+ @repo.clone(@remote)
69
92
  end
70
- rescue R10K::Util::Subprocess::SubprocessError => e
71
- raise R10K::Git::GitError.wrap(e, "Couldn't update git cache for #{@remote}")
72
93
  end
73
94
 
74
- # @return [Array<String>] A list the branches for the git repository
75
- def branches
76
- output = git %w[for-each-ref refs/heads --format %(refname)], :git_dir => git_dir
77
- output.stdout.scan(%r[refs/heads/(.*)$]).flatten
95
+ # @api private
96
+ def reset!
97
+ @synced = false
78
98
  end
79
99
 
80
- # @return [true, false] If the repository has been locally cached
81
- def cached?
82
- File.exist? git_dir
83
- end
100
+ alias cached? exist?
84
101
 
85
102
  private
86
103
 
@@ -3,16 +3,11 @@ require 'r10k/errors'
3
3
  module R10K
4
4
  module Git
5
5
 
6
- class GitError < R10K::Error; end
7
-
8
- class UnresolvableRefError < GitError
9
-
10
- attr_reader :ref
6
+ class GitError < R10K::Error
11
7
  attr_reader :git_dir
12
8
 
13
9
  def initialize(mesg, options = {})
14
10
  super
15
- @ref = @options[:ref]
16
11
  @git_dir = @options[:git_dir]
17
12
  end
18
13
 
@@ -24,5 +19,16 @@ module R10K
24
19
  msg
25
20
  end
26
21
  end
22
+
23
+
24
+ class UnresolvableRefError < GitError
25
+
26
+ attr_reader :ref
27
+
28
+ def initialize(mesg, options = {})
29
+ super
30
+ @ref = @options[:ref]
31
+ end
32
+ end
27
33
  end
28
34
  end
@@ -6,6 +6,9 @@ require 'r10k/git/repository'
6
6
  # head: A named reference to the commit at the tip of a branch. Heads are
7
7
  # stored in a file in $GIT_DIR/refs/heads/ directory. except when using packed
8
8
  #
9
+ # @deprecated This has been replaced by the ShellGit provider and the
10
+ # StatefulRepository class and will be removed in 2.0.0
11
+ #
9
12
  # @see https://www.kernel.org/pub/software/scm/git/docs/gitglossary.html
10
13
  # @api private
11
14
  class R10K::Git::Head < R10K::Git::Ref
@@ -5,6 +5,9 @@ require 'r10k/git/repository'
5
5
  # particular object. They may be stored in a file under $GIT_DIR/refs/
6
6
  # directory, or in the $GIT_DIR/packed-refs file.
7
7
  #
8
+ # @deprecated This has been replaced by the ShellGit provider and the
9
+ # StatefulRepository class and will be removed in 2.0.0
10
+ #
8
11
  # @see https://www.kernel.org/pub/software/scm/git/docs/gitglossary.html
9
12
  # @api private
10
13
  class R10K::Git::Ref
@@ -1,5 +1,10 @@
1
1
  require 'r10k/git'
2
2
 
3
+ # :nocov:
4
+ #
5
+ # @deprecated This has been replaced by the ShellGit provider and the
6
+ # StatefulRepository class and will be removed in 2.0.0
7
+ #
3
8
  # @api private
4
9
  class R10K::Git::RemoteHead < R10K::Git::Head
5
10
 
@@ -11,3 +16,4 @@ class R10K::Git::RemoteHead < R10K::Git::Head
11
16
  end
12
17
  end
13
18
  end
19
+ # :nocov:
@@ -2,6 +2,11 @@ require 'r10k/git'
2
2
  require 'r10k/util/subprocess'
3
3
 
4
4
  # Define an abstract base class for git repositories.
5
+ #
6
+ # @deprecated This has been replaced by the ShellGit provider and the
7
+ # StatefulRepository class and will be removed in 2.0.0
8
+ #
9
+ # :nocov:
5
10
  class R10K::Git::Repository
6
11
 
7
12
  # @!attribute [r] remote
@@ -150,3 +155,4 @@ class R10K::Git::Repository
150
155
  result
151
156
  end
152
157
  end
158
+ # :nocov: