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
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'r10k/git/shellgit'
|
2
|
+
require 'r10k/git/shellgit/cache'
|
3
|
+
require 'r10k/git/shellgit/working_repository'
|
4
|
+
|
5
|
+
# Manage a Git working repository backed with cached bare repositories. Instead
|
6
|
+
# of duplicating all objects for new clones and updates, this uses Git
|
7
|
+
# alternate object databases to reuse objects from an existing repository,
|
8
|
+
# making new clones very lightweight.
|
9
|
+
class R10K::Git::ShellGit::ThinRepository < R10K::Git::ShellGit::WorkingRepository
|
10
|
+
|
11
|
+
def initialize(basedir, dirname)
|
12
|
+
super
|
13
|
+
|
14
|
+
if exist? && origin
|
15
|
+
set_cache(origin)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Clone this git repository
|
20
|
+
#
|
21
|
+
# @param remote [String] The Git remote to clone
|
22
|
+
# @param opts [Hash]
|
23
|
+
#
|
24
|
+
# @options opts [String] :ref The git ref to check out on clone
|
25
|
+
#
|
26
|
+
# @return [void]
|
27
|
+
def clone(remote, opts = {})
|
28
|
+
# todo check if opts[:reference] is set
|
29
|
+
set_cache(remote)
|
30
|
+
@cache_repo.sync
|
31
|
+
|
32
|
+
super(remote, opts.merge(:reference => @cache_repo.git_dir.to_s))
|
33
|
+
setup_cache_remote
|
34
|
+
end
|
35
|
+
|
36
|
+
# Fetch refs from the backing bare Git repository.
|
37
|
+
def fetch(remote = 'cache')
|
38
|
+
git ['fetch', remote], :path => @path.to_s
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [String] The origin remote URL
|
42
|
+
def cache
|
43
|
+
git(['config', '--get', 'remote.cache.url'], :path => @path.to_s, :raise_on_fail => false).stdout
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def set_cache(remote)
|
49
|
+
@cache_repo = R10K::Git::ShellGit::Cache.generate(remote)
|
50
|
+
end
|
51
|
+
|
52
|
+
def setup_cache_remote
|
53
|
+
git ["remote", "add", "cache", @cache_repo.git_dir.to_s], :path => @path.to_s
|
54
|
+
fetch
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'r10k/git'
|
2
|
+
require 'r10k/git/alternates'
|
3
|
+
require 'r10k/git/shellgit/base_repository'
|
4
|
+
|
5
|
+
# Manage a non-bare Git repository
|
6
|
+
class R10K::Git::ShellGit::WorkingRepository < R10K::Git::ShellGit::BaseRepository
|
7
|
+
|
8
|
+
# @attribute [r] path
|
9
|
+
# @return [Pathname]
|
10
|
+
attr_reader :path
|
11
|
+
|
12
|
+
# @return [Pathname] The path to the Git directory inside of this repository
|
13
|
+
def git_dir
|
14
|
+
@path + '.git'
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(basedir, dirname)
|
18
|
+
@path = Pathname.new(File.join(basedir, dirname))
|
19
|
+
end
|
20
|
+
|
21
|
+
# Clone this git repository
|
22
|
+
#
|
23
|
+
# @param remote [String] The Git remote to clone
|
24
|
+
# @param opts [Hash]
|
25
|
+
#
|
26
|
+
# @options opts [String] :ref The git ref to check out on clone
|
27
|
+
# @options opts [String] :reference A Git repository to use as an alternate object database
|
28
|
+
#
|
29
|
+
# @return [void]
|
30
|
+
def clone(remote, opts = {})
|
31
|
+
argv = ['clone', remote, @path.to_s]
|
32
|
+
if opts[:reference]
|
33
|
+
argv += ['--reference', opts[:reference]]
|
34
|
+
end
|
35
|
+
git argv
|
36
|
+
|
37
|
+
if opts[:ref]
|
38
|
+
checkout(opts[:ref])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Check out the given Git ref
|
43
|
+
#
|
44
|
+
# @param ref [String] The git reference to check out
|
45
|
+
def checkout(ref)
|
46
|
+
git ['checkout', ref], :path => @path.to_s
|
47
|
+
end
|
48
|
+
|
49
|
+
def fetch
|
50
|
+
git ['fetch'], :path => @path.to_s
|
51
|
+
end
|
52
|
+
|
53
|
+
def exist?
|
54
|
+
@path.exist?
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [String] The currently checked out ref
|
58
|
+
def head
|
59
|
+
resolve('HEAD')
|
60
|
+
end
|
61
|
+
|
62
|
+
def alternates
|
63
|
+
R10K::Git::Alternates.new(git_dir)
|
64
|
+
end
|
65
|
+
|
66
|
+
# @return [String] The origin remote URL
|
67
|
+
def origin
|
68
|
+
result = git(['config', '--get', 'remote.origin.url'], :path => @path.to_s, :raise_on_fail => false)
|
69
|
+
if result.success?
|
70
|
+
result.stdout
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'r10k/git'
|
2
|
+
require 'r10k/git/errors'
|
3
|
+
require 'forwardable'
|
4
|
+
require 'r10k/logging'
|
5
|
+
|
6
|
+
# Manage how Git repositories are created and set to specific refs
|
7
|
+
class R10K::Git::StatefulRepository
|
8
|
+
|
9
|
+
include R10K::Logging
|
10
|
+
|
11
|
+
# @!attribute [r] repo
|
12
|
+
# @api private
|
13
|
+
attr_reader :repo
|
14
|
+
|
15
|
+
extend Forwardable
|
16
|
+
def_delegators :@repo, :head
|
17
|
+
|
18
|
+
# Create a new shallow git working directory
|
19
|
+
#
|
20
|
+
# @param ref [String] The git ref to check out
|
21
|
+
# @param remote [String] The git remote to use for the repo
|
22
|
+
# @param basedir [String] The path containing the Git repo
|
23
|
+
# @param dirname [String] The directory name of the Git repo
|
24
|
+
def initialize(ref, remote, basedir, dirname)
|
25
|
+
@ref = ref
|
26
|
+
@remote = remote
|
27
|
+
|
28
|
+
@repo = R10K::Git.thin_repository.new(basedir, dirname)
|
29
|
+
@cache = R10K::Git.cache.generate(remote)
|
30
|
+
end
|
31
|
+
|
32
|
+
def sync
|
33
|
+
@cache.sync if sync_cache?
|
34
|
+
|
35
|
+
sha = @cache.resolve(@ref)
|
36
|
+
|
37
|
+
if sha.nil?
|
38
|
+
raise R10K::Git::UnresolvableRefError.new("Unable to sync repo to unresolvable ref '#{@ref}'", :git_dir => @repo.git_dir)
|
39
|
+
end
|
40
|
+
|
41
|
+
case status
|
42
|
+
when :absent
|
43
|
+
logger.debug { "Cloning #{@repo.path} and checking out #{@ref}" }
|
44
|
+
@repo.clone(@remote, {:ref => sha})
|
45
|
+
when :mismatched
|
46
|
+
logger.debug { "Replacing #{@repo.path} and checking out #{@ref}" }
|
47
|
+
@repo.path.rmtree
|
48
|
+
@repo.clone(@remote, {:ref => sha})
|
49
|
+
when :outdated
|
50
|
+
logger.debug { "Updating #{@repo.path} to #{@ref}" }
|
51
|
+
@repo.checkout(sha)
|
52
|
+
else
|
53
|
+
logger.debug { "#{@repo.path} is already at Git ref #{@ref}" }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def status
|
58
|
+
if !@repo.exist?
|
59
|
+
:absent
|
60
|
+
elsif !@repo.git_dir.exist?
|
61
|
+
:mismatched
|
62
|
+
elsif !(@repo.origin == @remote)
|
63
|
+
:mismatched
|
64
|
+
elsif !(@repo.head == @cache.resolve(@ref))
|
65
|
+
:outdated
|
66
|
+
elsif @cache.ref_type(@ref) == :branch && !@cache.synced?
|
67
|
+
:outdated
|
68
|
+
else
|
69
|
+
:insync
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# @api private
|
74
|
+
def sync_cache?
|
75
|
+
return true if !@cache.exist?
|
76
|
+
return true if !@cache.resolve(@ref)
|
77
|
+
return true if !([:commit, :tag].include? @cache.ref_type(@ref))
|
78
|
+
return false
|
79
|
+
end
|
80
|
+
end
|
data/lib/r10k/git/tag.rb
CHANGED
@@ -6,6 +6,9 @@ require 'r10k/git/repository'
|
|
6
6
|
# In contrast to a head, a tag is not updated by the commit command. A tag is
|
7
7
|
# most typically used to mark a particular point in the commit ancestry chain.
|
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::Tag < R10K::Git::Ref
|
data/lib/r10k/git/working_dir.rb
CHANGED
@@ -2,11 +2,23 @@ require 'forwardable'
|
|
2
2
|
require 'r10k/git'
|
3
3
|
require 'r10k/git/cache'
|
4
4
|
|
5
|
+
require 'r10k/git/working_dir'
|
6
|
+
require 'r10k/git/ref'
|
7
|
+
require 'r10k/git/tag'
|
8
|
+
require 'r10k/git/head'
|
9
|
+
require 'r10k/git/remote_head'
|
10
|
+
require 'r10k/git/commit'
|
11
|
+
|
5
12
|
# Implements sparse git repositories with shared objects
|
6
13
|
#
|
7
14
|
# Working directory instances use the git alternatives object store, so that
|
8
15
|
# working directories only contain checked out files and all object files are
|
9
16
|
# shared.
|
17
|
+
#
|
18
|
+
# @deprecated This has been replaced by the ShellGit provider and the
|
19
|
+
# StatefulRepository class and will be removed in 2.0.0
|
20
|
+
#
|
21
|
+
# :nocov:
|
10
22
|
class R10K::Git::WorkingDir < R10K::Git::Repository
|
11
23
|
|
12
24
|
include R10K::Logging
|
@@ -40,8 +52,8 @@ class R10K::Git::WorkingDir < R10K::Git::Repository
|
|
40
52
|
@full_path = File.join(@basedir, @dirname)
|
41
53
|
@git_dir = File.join(@full_path, '.git')
|
42
54
|
|
43
|
-
@alternates = R10K::Git::Alternates.new(@git_dir)
|
44
|
-
@cache = R10K::Git::Cache.generate(@remote)
|
55
|
+
@alternates = R10K::Git::Alternates.new(Pathname.new(@git_dir))
|
56
|
+
@cache = R10K::Git::ShellGit::Cache.generate(@remote)
|
45
57
|
|
46
58
|
if ref.is_a? String
|
47
59
|
@ref = R10K::Git::Ref.new(ref, self)
|
@@ -171,3 +183,4 @@ class R10K::Git::WorkingDir < R10K::Git::Repository
|
|
171
183
|
end
|
172
184
|
end
|
173
185
|
end
|
186
|
+
# :nocov:
|
data/lib/r10k/logging.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'r10k'
|
2
|
+
require 'forwardable'
|
2
3
|
|
3
4
|
require 'log4r'
|
4
5
|
require 'log4r/configurator'
|
6
|
+
require 'r10k/logging/terminaloutputter'
|
5
7
|
|
6
8
|
module R10K::Logging
|
7
9
|
|
8
|
-
include Log4r
|
9
|
-
|
10
10
|
LOG_LEVELS = %w{DEBUG2 DEBUG1 DEBUG INFO NOTICE WARN ERROR FATAL}
|
11
11
|
|
12
12
|
def logger_name
|
@@ -14,59 +14,96 @@ module R10K::Logging
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def logger
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
if @logger.nil?
|
18
|
+
name = logger_name
|
19
|
+
if Log4r::Logger[name]
|
20
|
+
@logger = Log4r::Logger[name]
|
21
|
+
else
|
22
|
+
@logger = Log4r::Logger.new(name)
|
23
|
+
@logger.add(R10K::Logging.outputter)
|
24
|
+
end
|
20
25
|
end
|
21
26
|
@logger
|
22
27
|
end
|
23
28
|
|
24
29
|
class << self
|
25
|
-
include Log4r
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
+
# Convert the input to a valid Log4r log level
|
32
|
+
#
|
33
|
+
# @param input [String, TrueClass] The level to parse. If TrueClass then
|
34
|
+
# Log4r::INFO will be returned (indicating a generic raised verbosity),
|
35
|
+
# if a string it will be parsed either as a numeric value or a textual
|
36
|
+
# log level.
|
37
|
+
# @api private
|
38
|
+
# @return [Integer, NilClass] The numeric log level, or nil if the log
|
39
|
+
# level is invalid.
|
40
|
+
def parse_level(input)
|
41
|
+
case input
|
42
|
+
when TrueClass
|
43
|
+
Log4r::INFO
|
44
|
+
when /\A\d+\Z/
|
45
|
+
Integer(input)
|
46
|
+
when String
|
47
|
+
const_name = input.upcase
|
48
|
+
if LOG_LEVELS.include?(const_name)
|
49
|
+
begin
|
50
|
+
Log4r.const_get(const_name.to_sym)
|
51
|
+
rescue NameError
|
52
|
+
end
|
53
|
+
end
|
31
54
|
end
|
32
55
|
end
|
33
56
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
levels[val.upcase]
|
57
|
+
def level=(val)
|
58
|
+
level = parse_level(val)
|
59
|
+
if level.nil?
|
60
|
+
raise ArgumentError, "Invalid log level '#{val}'. Valid levels are #{LOG_LEVELS.map(&:downcase).inspect}"
|
39
61
|
end
|
40
|
-
|
62
|
+
outputter.level = level
|
63
|
+
@level = level
|
41
64
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
@log4r_loaded = true
|
65
|
+
if level < Log4r::INFO
|
66
|
+
outputter.formatter = debug_formatter
|
67
|
+
else
|
68
|
+
outputter.formatter = default_formatter
|
47
69
|
end
|
48
70
|
end
|
49
71
|
|
50
|
-
|
51
|
-
|
52
|
-
end
|
72
|
+
extend Forwardable
|
73
|
+
def_delegators :@outputter, :use_color, :use_color=
|
53
74
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
75
|
+
# @!attribute [r] level
|
76
|
+
# @return [Integer] The current log level. Lower numbers correspond
|
77
|
+
# to more verbose log levels.
|
78
|
+
attr_reader :level
|
79
|
+
|
80
|
+
# @!attribute [r] formatter
|
81
|
+
# @api private
|
82
|
+
# @return [Log4r::Formatter]
|
83
|
+
attr_reader :formatter
|
84
|
+
|
85
|
+
# @!attribute [r] outputter
|
86
|
+
# @api private
|
87
|
+
# @return [Log4r::Outputter]
|
88
|
+
attr_reader :outputter
|
89
|
+
|
90
|
+
def default_formatter
|
91
|
+
Log4r::PatternFormatter.new(:pattern => '%l\t -> %m')
|
59
92
|
end
|
60
93
|
|
61
|
-
def
|
62
|
-
|
94
|
+
def debug_formatter
|
95
|
+
Log4r::PatternFormatter.new(:pattern => '[%d - %l] %m')
|
63
96
|
end
|
64
97
|
|
65
|
-
def
|
66
|
-
|
67
|
-
:level => self.level,
|
68
|
-
:formatter => formatter
|
69
|
-
)
|
98
|
+
def default_outputter
|
99
|
+
R10K::Logging::TerminalOutputter.new('terminal', $stderr, :level => self.level, :formatter => formatter)
|
70
100
|
end
|
71
101
|
end
|
102
|
+
|
103
|
+
Log4r::Configurator.custom_levels(*LOG_LEVELS)
|
104
|
+
Log4r::Logger.global.level = Log4r::ALL
|
105
|
+
|
106
|
+
@level = Log4r::WARN
|
107
|
+
@formatter = default_formatter
|
108
|
+
@outputter = default_outputter
|
72
109
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'colored'
|
2
|
+
require 'r10k/logging'
|
3
|
+
require 'log4r/outputter/iooutputter'
|
4
|
+
|
5
|
+
module R10K
|
6
|
+
module Logging
|
7
|
+
class TerminalOutputter < Log4r::IOOutputter
|
8
|
+
|
9
|
+
COLORS = [
|
10
|
+
nil,
|
11
|
+
:cyan,
|
12
|
+
:cyan,
|
13
|
+
:green,
|
14
|
+
nil,
|
15
|
+
nil,
|
16
|
+
:yellow,
|
17
|
+
:red,
|
18
|
+
:red,
|
19
|
+
]
|
20
|
+
|
21
|
+
attr_accessor :use_color
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def format(logevent)
|
26
|
+
string = super
|
27
|
+
if @use_color
|
28
|
+
color = COLORS[logevent.level]
|
29
|
+
color ? string.send(color) : string
|
30
|
+
else
|
31
|
+
string
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|