r10k 1.4.2 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -0
- data/CHANGELOG.mkd +192 -0
- data/CONTRIBUTING.mkd +3 -3
- data/Gemfile +4 -0
- data/README.mkd +13 -6
- data/doc/dynamic-environments/configuration.mkd +77 -8
- data/doc/dynamic-environments/git-environments.mkd +12 -2
- data/doc/dynamic-environments/quickstart.mkd +6 -0
- data/doc/faq.mkd +6 -6
- data/doc/git/cloning-and-mirroring.mkd +60 -0
- data/doc/git/providers.mkd +68 -0
- data/integration/Gemfile +3 -0
- data/integration/README.mkd +29 -0
- data/integration/configs/README.mkd +7 -0
- data/integration/configs/pe/centos-6-64mda +25 -0
- data/integration/configs/pe/centos-7-64mda +25 -0
- data/integration/configs/pe/debian-6-64mda +25 -0
- data/integration/configs/pe/debian-7-64mda +25 -0
- data/integration/configs/pe/redhat-6-64mda +25 -0
- data/integration/configs/pe/redhat-7-64mda +25 -0
- data/integration/configs/pe/sles-11-64mda +25 -0
- data/integration/configs/pe/ubuntu-1004-64mda +25 -0
- data/integration/configs/pe/ubuntu-1204-64mda +25 -0
- data/integration/configs/pe/ubuntu-1404-64mda +25 -0
- data/integration/files/README.mkd +4 -0
- data/integration/files/hiera.yaml +8 -0
- data/integration/files/modules/helloworld/manifests/init.pp +3 -0
- data/integration/files/modules/hieratest/manifests/init.pp +3 -0
- data/integration/files/modules/unicode/files/pretend_unicode +1 -0
- data/integration/files/modules/unicode/manifests/init.pp +6 -0
- data/integration/files/pre-suite/prod_env.config +3 -0
- data/integration/files/r10k_conf.yaml.erb +9 -0
- data/integration/lib/README.mkd +4 -0
- data/integration/lib/git_utils.rb +205 -0
- data/integration/lib/master_manipulator.rb +205 -0
- data/integration/lib/r10k_utils.rb +166 -0
- data/integration/manifests/README.mkd +4 -0
- data/integration/pre-suite/00_pe_install.rb +4 -0
- data/integration/pre-suite/01_git_config.rb +59 -0
- data/integration/pre-suite/02_pe_r10k.rb +60 -0
- data/integration/pre-suite/03_test_utils.rb +17 -0
- data/integration/pre-suite/README.mkd +5 -0
- data/integration/test_run_scripts/README.mkd +5 -0
- data/integration/test_run_scripts/all_tests-rugged-pe-centos6.sh +20 -0
- data/integration/test_run_scripts/all_tests-rugged-pe-rhel7.sh +20 -0
- data/integration/test_run_scripts/all_tests-rugged-pe-sles11.sh +20 -0
- data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1204.sh +20 -0
- data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1404.sh +20 -0
- data/integration/test_run_scripts/all_tests-shellgit-pe-centos6.sh +20 -0
- data/integration/test_run_scripts/all_tests-shellgit-pe-rhel7.sh +20 -0
- data/integration/test_run_scripts/all_tests-shellgit-pe-sles11.sh +20 -0
- data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1204.sh +20 -0
- data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1404.sh +20 -0
- data/integration/test_run_scripts/basic_functionality/all_tests-pe-centos6.sh +20 -0
- data/integration/test_run_scripts/command_line/all_tests-pe-centos6.sh +20 -0
- data/integration/test_run_scripts/git_source/all_tests-pe-centos6.sh +20 -0
- data/integration/test_run_scripts/user_scenario/basic_workflow/all_tests-pe-centos6.sh +20 -0
- data/integration/test_run_scripts/user_scenario/complex_workflow/all_tests-pe-centos6.sh +20 -0
- data/integration/tests/README.mkd +4 -0
- data/integration/tests/basic_functionality/negative/neg_deploy_with_invalid_r10k_yaml.rb +46 -0
- data/integration/tests/basic_functionality/negative/neg_deploy_with_missing_r10k_yaml.rb +27 -0
- data/integration/tests/command_line/deploy_env_without_mod_update.rb +75 -0
- data/integration/tests/command_line/negative/neg_deploy_env_with_module_update.rb +76 -0
- data/integration/tests/command_line/negative/neg_invalid_cli_dep_flag.rb +22 -0
- data/integration/tests/command_line/negative/neg_invalid_cli_env_flag.rb +22 -0
- data/integration/tests/command_line/negative/neg_invalid_cmd_line_arg.rb +24 -0
- data/integration/tests/git_source/git_source_git.rb +123 -0
- data/integration/tests/git_source/git_source_ssh.rb +84 -0
- data/integration/tests/git_source/git_source_submodule.rb +69 -0
- data/integration/tests/git_source/negative/neg_git_broken_remote.rb +37 -0
- data/integration/tests/git_source/negative/neg_git_unauthorized_https.rb +45 -0
- data/integration/tests/git_source/negative/neg_git_unauthorized_ssh.rb +72 -0
- data/integration/tests/git_source/negative/neg_git_unicode_branch.rb +34 -0
- data/integration/tests/user_scenario/basic_workflow/multi_env_1000_branches.rb +66 -0
- data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module.rb +110 -0
- data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module_static.rb +113 -0
- data/integration/tests/user_scenario/basic_workflow/multi_env_hiera.rb +93 -0
- data/integration/tests/user_scenario/basic_workflow/multi_env_multi_source.rb +132 -0
- data/integration/tests/user_scenario/basic_workflow/multi_source_custom_forge_git_module.rb +160 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_basedir.rb +45 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_forge_module.rb +43 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module.rb +40 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module_ref.rb +42 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_remote.rb +44 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_branch_name_collision.rb +63 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_disk_full.rb +73 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_duplicate_module_names.rb +45 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_inaccessible_forge.rb +51 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_env_name.rb +33 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_puppet_file.rb +35 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_module_specified_at_deleted_release.rb +44 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_read_only.rb +57 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_specify_deleted_forge_module.rb +44 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_10000_files.rb +73 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_git_module.rb +103 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_module.rb +80 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_custom_module.rb +48 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_large_files.rb +73 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_module_already_installed.rb +81 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_module_last_release_deleted.rb +67 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_non-existent_base_dir.rb +93 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_purge_unmanaged_modules.rb +92 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_switch_forge_git_module.rb +116 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_unicode_paths.rb +59 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_upgrade_forge_mod_revert_change.rb +165 -0
- data/integration/tests/user_scenario/complex_workflow/multi_env_add_change_remove.rb +162 -0
- data/integration/tests/user_scenario/complex_workflow/multi_env_remove_re-add.rb +110 -0
- data/lib/r10k/action/cri_runner.rb +10 -13
- data/lib/r10k/cli.rb +3 -8
- data/lib/r10k/cli/version.rb +10 -1
- data/lib/r10k/deployment/config.rb +26 -6
- data/lib/r10k/deployment/config/loader.rb +38 -29
- data/lib/r10k/deployment/source.rb +2 -4
- data/lib/r10k/environment/git.rb +10 -19
- data/lib/r10k/environment/name.rb +86 -0
- data/lib/r10k/errors.rb +8 -5
- data/lib/r10k/feature.rb +35 -0
- data/lib/r10k/feature/collection.rb +23 -0
- data/lib/r10k/features.rb +18 -0
- data/lib/r10k/git.rb +106 -12
- data/lib/r10k/git/alternates.rb +2 -2
- data/lib/r10k/git/cache.rb +43 -26
- data/lib/r10k/git/errors.rb +12 -6
- data/lib/r10k/git/head.rb +3 -0
- data/lib/r10k/git/ref.rb +3 -0
- data/lib/r10k/git/remote_head.rb +6 -0
- data/lib/r10k/git/repository.rb +6 -0
- data/lib/r10k/git/rugged.rb +17 -0
- data/lib/r10k/git/rugged/bare_repository.rb +86 -0
- data/lib/r10k/git/rugged/base_repository.rb +90 -0
- data/lib/r10k/git/rugged/cache.rb +11 -0
- data/lib/r10k/git/rugged/thin_repository.rb +72 -0
- data/lib/r10k/git/rugged/working_repository.rb +99 -0
- data/lib/r10k/git/shellgit.rb +9 -0
- data/lib/r10k/git/shellgit/bare_repository.rb +29 -0
- data/lib/r10k/git/shellgit/base_repository.rb +102 -0
- data/lib/r10k/git/shellgit/cache.rb +11 -0
- data/lib/r10k/git/shellgit/thin_repository.rb +56 -0
- data/lib/r10k/git/shellgit/working_repository.rb +73 -0
- data/lib/r10k/git/stateful_repository.rb +80 -0
- data/lib/r10k/git/tag.rb +3 -0
- data/lib/r10k/git/working_dir.rb +15 -2
- data/lib/r10k/logging.rb +73 -36
- data/lib/r10k/logging/terminaloutputter.rb +36 -0
- data/lib/r10k/module/forge.rb +10 -9
- data/lib/r10k/module/git.rb +14 -44
- data/lib/r10k/module/metadata_file.rb +31 -0
- data/lib/r10k/module/svn.rb +0 -1
- data/lib/r10k/module_repository/forge.rb +20 -7
- data/lib/r10k/puppetfile.rb +1 -1
- data/lib/r10k/settings/container.rb +6 -0
- data/lib/r10k/settings/mixin.rb +9 -0
- data/lib/r10k/source.rb +2 -3
- data/lib/r10k/source/base.rb +5 -5
- data/lib/r10k/source/git.rb +11 -86
- data/lib/r10k/source/svn.rb +8 -52
- data/lib/r10k/util/basedir.rb +4 -4
- data/lib/r10k/util/commands.rb +31 -0
- data/lib/r10k/util/exec_env.rb +36 -0
- data/lib/r10k/util/platform.rb +4 -0
- data/lib/r10k/util/purgeable.rb +2 -2
- data/lib/r10k/util/subprocess.rb +3 -7
- data/lib/r10k/util/subprocess/runner.rb +3 -28
- data/lib/r10k/util/subprocess/runner/posix.rb +103 -0
- data/lib/r10k/util/subprocess/runner/pump.rb +59 -0
- data/lib/r10k/util/subprocess/{windows/runner.rb → runner/windows.rb} +2 -11
- data/lib/r10k/util/symbolize_keys.rb +31 -0
- data/lib/r10k/version.rb +1 -1
- data/lib/shared/puppet/module_tool/metadata.rb +197 -0
- data/r10k.gemspec +7 -5
- data/spec/fixtures/integration/git/puppet-boolean-bare.tar +0 -0
- data/spec/fixtures/module/forge/bad_module/metadata.json +1 -0
- data/spec/fixtures/unit/util/subprocess/posix/runner/no-execute.sh +3 -0
- 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
- 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
- data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/and_the_expected_version_is_latest/ignores_deleted_releases.yml +190 -0
- 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
- 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
- data/spec/integration/git/rugged/bare_repository_spec.rb +13 -0
- data/spec/integration/git/rugged/thin_repository_spec.rb +14 -0
- data/spec/integration/git/rugged/working_repository_spec.rb +13 -0
- data/spec/integration/git/shellgit/bare_repository_spec.rb +13 -0
- data/spec/integration/git/shellgit/thin_repository_spec.rb +14 -0
- data/spec/integration/git/shellgit/working_repository_spec.rb +13 -0
- data/spec/integration/git/stateful_repository_spec.rb +104 -0
- data/spec/matchers/match_realpath.rb +18 -0
- data/spec/shared-contexts/git-fixtures.rb +55 -0
- data/spec/shared-examples/git-repository.rb +38 -0
- data/spec/shared-examples/git/bare_repository.rb +70 -0
- data/spec/shared-examples/git/thin_repository.rb +26 -0
- data/spec/shared-examples/git/working_repository.rb +115 -0
- data/spec/shared-examples/subprocess-runner.rb +83 -0
- data/spec/spec_helper.rb +13 -9
- data/spec/unit/action/cri_runner_spec.rb +0 -6
- data/spec/unit/action/puppetfile/{cri_action_spec.rb → cri_runner_spec.rb} +0 -0
- data/spec/unit/deployment/config/loader_spec.rb +48 -0
- data/spec/unit/deployment/config_spec.rb +49 -0
- data/spec/unit/environment/git_spec.rb +5 -39
- data/spec/unit/environment/name_spec.rb +135 -0
- data/spec/unit/feature_spec.rb +50 -0
- data/spec/unit/git/alternates_spec.rb +1 -1
- data/spec/unit/git/cache_spec.rb +32 -19
- data/spec/unit/git/commit_spec.rb +1 -0
- data/spec/unit/git/head_spec.rb +1 -6
- data/spec/unit/git/ref_spec.rb +0 -23
- data/spec/unit/git/rugged/cache_spec.rb +26 -0
- data/spec/unit/git/shellgit/cache_spec.rb +27 -0
- data/spec/unit/git/stateful_repository_spec.rb +43 -0
- data/spec/unit/git/tag_spec.rb +1 -0
- data/spec/unit/git/working_dir_spec.rb +1 -0
- data/spec/unit/git_spec.rb +74 -0
- data/spec/unit/logging/terminaloutputter_spec.rb +53 -0
- data/spec/unit/logging_spec.rb +68 -0
- data/spec/unit/module/forge_spec.rb +7 -38
- data/spec/unit/module/git_spec.rb +7 -38
- data/spec/unit/module/metadata_file_spec.rb +69 -0
- data/spec/unit/module/svn_spec.rb +0 -4
- data/spec/unit/module_repository/forge_spec.rb +22 -1
- data/spec/unit/puppet/module_tool/metadata_spec.rb +301 -0
- data/spec/unit/settings/container_spec.rb +17 -0
- data/spec/unit/source/git_spec.rb +0 -123
- data/spec/unit/source/svn_spec.rb +66 -0
- data/spec/unit/util/commands_spec.rb +61 -0
- data/spec/unit/util/exec_env_spec.rb +56 -0
- data/spec/unit/util/subprocess/runner/posix_spec.rb +7 -0
- data/spec/unit/util/subprocess/runner/pump_spec.rb +79 -0
- data/spec/unit/util/subprocess_spec.rb +3 -2
- data/spec/unit/util/symbolize_keys_spec.rb +51 -0
- metadata +226 -45
- data/lib/r10k/execution.rb +0 -47
- data/lib/r10k/module/metadata.rb +0 -47
- data/lib/r10k/util/core_ext/hash_ext.rb +0 -19
- data/lib/r10k/util/subprocess/io.rb +0 -7
- data/lib/r10k/util/subprocess/posix.rb +0 -4
- data/lib/r10k/util/subprocess/posix/io.rb +0 -7
- data/lib/r10k/util/subprocess/posix/runner.rb +0 -140
- data/lib/r10k/util/subprocess/windows.rb +0 -4
- data/lib/r10k/util/subprocess/windows/io.rb +0 -6
- data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions.yml +0 -42
- data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions/can_fetch_all_versions_of_a_given_module.yml +0 -42
- data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions/can_fetch_the_latest_version_of_a_given_module.yml +0 -42
- data/spec/unit/deployment/source_spec.rb +0 -24
- data/spec/unit/module/metadata_spec.rb +0 -68
- data/spec/unit/util/core_ext/hash_ext_spec.rb +0 -63
data/lib/r10k/errors.rb
CHANGED
@@ -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
|
data/lib/r10k/feature.rb
ADDED
@@ -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')
|
data/lib/r10k/git.rb
CHANGED
@@ -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/
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
data/lib/r10k/git/alternates.rb
CHANGED
@@ -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 [
|
12
|
+
# @param git_dir [Pathname] The path to the git repository
|
13
13
|
def initialize(git_dir)
|
14
|
-
@file =
|
14
|
+
@file = git_dir + File.join('objects', 'info', 'alternates')
|
15
15
|
end
|
16
16
|
|
17
17
|
def to_a
|
data/lib/r10k/git/cache.rb
CHANGED
@@ -1,22 +1,28 @@
|
|
1
1
|
require 'r10k/git'
|
2
|
-
require 'r10k/git/repository'
|
3
2
|
|
4
3
|
require 'r10k/settings'
|
5
|
-
require 'r10k/
|
4
|
+
require 'r10k/instance_cache'
|
5
|
+
require 'forwardable'
|
6
6
|
|
7
|
-
#
|
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
|
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
|
-
|
21
|
+
@instance_cache = R10K::InstanceCache.new(self)
|
22
|
+
|
17
23
|
# @api private
|
18
24
|
def self.instance_cache
|
19
|
-
@instance_cache
|
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
|
-
|
56
|
+
git_dir
|
40
57
|
end
|
41
58
|
|
42
|
-
#
|
43
|
-
#
|
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
|
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.
|
84
|
+
logger.debug1 "Creating new git cache for #{@remote.inspect}"
|
62
85
|
|
63
86
|
# TODO extract this to an initialization step
|
64
|
-
|
87
|
+
if !File.exist?(settings[:cache_root])
|
65
88
|
FileUtils.mkdir_p settings[:cache_root]
|
66
89
|
end
|
67
90
|
|
68
|
-
|
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
|
-
# @
|
75
|
-
def
|
76
|
-
|
77
|
-
output.stdout.scan(%r[refs/heads/(.*)$]).flatten
|
95
|
+
# @api private
|
96
|
+
def reset!
|
97
|
+
@synced = false
|
78
98
|
end
|
79
99
|
|
80
|
-
|
81
|
-
def cached?
|
82
|
-
File.exist? git_dir
|
83
|
-
end
|
100
|
+
alias cached? exist?
|
84
101
|
|
85
102
|
private
|
86
103
|
|
data/lib/r10k/git/errors.rb
CHANGED
@@ -3,16 +3,11 @@ require 'r10k/errors'
|
|
3
3
|
module R10K
|
4
4
|
module Git
|
5
5
|
|
6
|
-
class GitError < R10K::Error
|
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
|
data/lib/r10k/git/head.rb
CHANGED
@@ -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
|
data/lib/r10k/git/ref.rb
CHANGED
@@ -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
|
data/lib/r10k/git/remote_head.rb
CHANGED
@@ -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:
|
data/lib/r10k/git/repository.rb
CHANGED
@@ -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:
|