akerl-r10k 3.14.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitattributes +1 -0
- data/.github/pull_request_template.md +4 -0
- data/.github/workflows/docker.yml +64 -0
- data/.github/workflows/release.yml +37 -0
- data/.github/workflows/rspec_tests.yml +81 -0
- data/.github/workflows/stale.yml +21 -0
- data/.gitignore +10 -0
- data/.travis.yml +42 -0
- data/CHANGELOG.mkd +1879 -0
- data/CODEOWNERS +2 -0
- data/CONTRIBUTING.mkd +105 -0
- data/Gemfile +15 -0
- data/LICENSE +14 -0
- data/README.mkd +139 -0
- data/Rakefile +3 -0
- data/bin/r10k +17 -0
- data/doc/common-patterns.mkd +45 -0
- data/doc/dynamic-environments/configuration.mkd +850 -0
- data/doc/dynamic-environments/git-environments.mkd +75 -0
- data/doc/dynamic-environments/introduction.mkd +69 -0
- data/doc/dynamic-environments/master-configuration.mkd +40 -0
- data/doc/dynamic-environments/quickstart.mkd +201 -0
- data/doc/dynamic-environments/svn-environments.mkd +45 -0
- data/doc/dynamic-environments/usage.mkd +163 -0
- data/doc/dynamic-environments/workflow-guide.mkd +247 -0
- data/doc/dynamic-environments.mkd +31 -0
- data/doc/faq.mkd +164 -0
- data/doc/git/cloning-and-mirroring.mkd +60 -0
- data/doc/git/providers.mkd +133 -0
- data/doc/puppetfile.mkd +355 -0
- data/doc/updating-your-puppetfile.mkd +38 -0
- data/docker/.gitignore +1 -0
- data/docker/.rspec +4 -0
- data/docker/Gemfile +11 -0
- data/docker/Makefile +99 -0
- data/docker/README.md +28 -0
- data/docker/docker-compose.yml +18 -0
- data/docker/r10k/Dockerfile +68 -0
- data/docker/r10k/adduser.sh +13 -0
- data/docker/r10k/docker-entrypoint.d/10-analytics.sh +30 -0
- data/docker/r10k/docker-entrypoint.sh +10 -0
- data/docker/r10k/release.Dockerfile +55 -0
- data/docker/spec/dockerfile_spec.rb +37 -0
- data/docker/spec/fixtures/Puppetfile +2 -0
- data/integration/Gemfile +19 -0
- data/integration/README.mkd +29 -0
- data/integration/Rakefile +79 -0
- data/integration/component/pre-suite/05_install_dev_r10k.rb +12 -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/git_config.pp.erb +19 -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 +222 -0
- data/integration/manifests/README.mkd +4 -0
- data/integration/pre-suite/00_pe_install.rb +6 -0
- data/integration/pre-suite/10_git_config.rb +48 -0
- data/integration/pre-suite/20_pe_r10k.rb +55 -0
- data/integration/pre-suite/README.mkd +5 -0
- data/integration/tests/Puppetfile/HTTP_PROXY_affects_forge_source.rb +72 -0
- data/integration/tests/Puppetfile/HTTP_PROXY_affects_git_source.rb +70 -0
- data/integration/tests/README.mkd +4 -0
- data/integration/tests/basic_functionality/basic_deployment.rb +176 -0
- data/integration/tests/basic_functionality/install_pe_only_module_with_puppetfile.rb +83 -0
- data/integration/tests/basic_functionality/negative/neg_deploy_with_invalid_r10k_yaml.rb +51 -0
- data/integration/tests/basic_functionality/negative/neg_deploy_with_missing_r10k_yaml.rb +28 -0
- data/integration/tests/basic_functionality/negative/neg_invalid_git_provider.rb +45 -0
- data/integration/tests/basic_functionality/negative/negative_bad_proxy.rb +34 -0
- data/integration/tests/basic_functionality/proxy_specified_in_configuration.rb +103 -0
- data/integration/tests/basic_functionality/proxy_with_pe_only_module.rb +128 -0
- data/integration/tests/basic_functionality/proxy_with_puppetfile.rb +61 -0
- data/integration/tests/basic_functionality/rugged_git_provider_with_ssh.rb +109 -0
- data/integration/tests/basic_functionality/rugged_git_provider_without_ssh.rb +108 -0
- data/integration/tests/command_line/deploy_env_without_mod_update.rb +76 -0
- data/integration/tests/command_line/negative/neg_deploy_env_with_module_update.rb +77 -0
- data/integration/tests/command_line/negative/neg_invalid_cmd_line_arg.rb +23 -0
- data/integration/tests/git_source/HTTP_proxy_and_git_source.rb +70 -0
- data/integration/tests/git_source/git_source_git.rb +128 -0
- data/integration/tests/git_source/git_source_repeated_remote.rb +68 -0
- data/integration/tests/git_source/git_source_ssh.rb +87 -0
- data/integration/tests/git_source/git_source_submodule.rb +70 -0
- data/integration/tests/git_source/negative/neg_git_broken_remote.rb +38 -0
- data/integration/tests/git_source/negative/neg_git_unauthorized_https.rb +46 -0
- data/integration/tests/git_source/negative/neg_git_unauthorized_ssh.rb +73 -0
- data/integration/tests/git_source/negative/neg_git_unicode_branch.rb +35 -0
- data/integration/tests/i18n/deploy_module_with_unicode_in_file_name.rb +64 -0
- data/integration/tests/purging/content_not_purged_at_root.rb +89 -0
- data/integration/tests/purging/default_purging.rb +125 -0
- data/integration/tests/purging/does_not_purge_files_on_white_list.rb +93 -0
- data/integration/tests/purging/invalid_whitelist_types.rb +63 -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 +112 -0
- data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module_static.rb +118 -0
- data/integration/tests/user_scenario/basic_workflow/multi_env_hiera.rb +100 -0
- data/integration/tests/user_scenario/basic_workflow/multi_env_multi_source.rb +133 -0
- data/integration/tests/user_scenario/basic_workflow/multi_source_custom_forge_git_module.rb +161 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_basedir.rb +46 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_forge_module.rb +48 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module.rb +45 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module_ref.rb +43 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_remote.rb +45 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_branch_name_collision.rb +64 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_disk_full.rb +75 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_duplicate_module_names.rb +44 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_inaccessible_forge.rb +58 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_env_name.rb +34 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_puppet_file.rb +36 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_module_specified_at_deleted_release.rb +49 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_read_only.rb +58 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_specify_deleted_forge_module.rb +45 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_10000_files.rb +75 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_git_module.rb +105 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_module.rb +81 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_custom_module.rb +49 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_large_files.rb +75 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_module_already_installed.rb +82 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_module_last_release_deleted.rb +68 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_non-existent_base_dir.rb +94 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_purge_unmanaged_modules.rb +89 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_switch_forge_git_module.rb +117 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_unicode_paths.rb +60 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_upgrade_forge_mod_revert_change.rb +166 -0
- data/integration/tests/user_scenario/complex_workflow/multi_env_add_change_remove.rb +163 -0
- data/integration/tests/user_scenario/complex_workflow/multi_env_remove_re-add.rb +111 -0
- data/integration/tests/user_scenario/complex_workflow/multi_env_unamanaged.rb +78 -0
- data/integration/tests/user_scenario/complex_workflow/single_env_git_module_update.rb +100 -0
- data/lib/r10k/action/base.rb +41 -0
- data/lib/r10k/action/cri_runner.rb +72 -0
- data/lib/r10k/action/deploy/deploy_helpers.rb +38 -0
- data/lib/r10k/action/deploy/display.rb +128 -0
- data/lib/r10k/action/deploy/environment.rb +260 -0
- data/lib/r10k/action/deploy/module.rb +139 -0
- data/lib/r10k/action/deploy.rb +9 -0
- data/lib/r10k/action/puppetfile/check.rb +35 -0
- data/lib/r10k/action/puppetfile/cri_runner.rb +26 -0
- data/lib/r10k/action/puppetfile/install.rb +48 -0
- data/lib/r10k/action/puppetfile/purge.rb +37 -0
- data/lib/r10k/action/puppetfile.rb +10 -0
- data/lib/r10k/action/runner.rb +171 -0
- data/lib/r10k/action/visitor.rb +34 -0
- data/lib/r10k/cli/deploy.rb +126 -0
- data/lib/r10k/cli/ext/logging.rb +15 -0
- data/lib/r10k/cli/help.rb +7 -0
- data/lib/r10k/cli/puppetfile.rb +73 -0
- data/lib/r10k/cli/version.rb +31 -0
- data/lib/r10k/cli.rb +51 -0
- data/lib/r10k/content_synchronizer.rb +95 -0
- data/lib/r10k/deployment/config.rb +56 -0
- data/lib/r10k/deployment.rb +132 -0
- data/lib/r10k/environment/bare.rb +13 -0
- data/lib/r10k/environment/base.rb +230 -0
- data/lib/r10k/environment/git.rb +93 -0
- data/lib/r10k/environment/name.rb +109 -0
- data/lib/r10k/environment/plain.rb +16 -0
- data/lib/r10k/environment/svn.rb +98 -0
- data/lib/r10k/environment/tarball.rb +78 -0
- data/lib/r10k/environment/with_modules.rb +174 -0
- data/lib/r10k/environment.rb +39 -0
- data/lib/r10k/errors/formatting.rb +28 -0
- data/lib/r10k/errors.rb +66 -0
- data/lib/r10k/feature/collection.rb +23 -0
- data/lib/r10k/feature.rb +56 -0
- data/lib/r10k/features.rb +20 -0
- data/lib/r10k/forge/module_release.rb +229 -0
- data/lib/r10k/git/alternates.rb +63 -0
- data/lib/r10k/git/cache.rb +107 -0
- data/lib/r10k/git/errors.rb +34 -0
- data/lib/r10k/git/rugged/bare_repository.rb +85 -0
- data/lib/r10k/git/rugged/base_repository.rb +104 -0
- data/lib/r10k/git/rugged/cache.rb +19 -0
- data/lib/r10k/git/rugged/credentials.rb +205 -0
- data/lib/r10k/git/rugged/thin_repository.rb +96 -0
- data/lib/r10k/git/rugged/working_repository.rb +149 -0
- data/lib/r10k/git/rugged.rb +17 -0
- data/lib/r10k/git/shellgit/bare_repository.rb +43 -0
- data/lib/r10k/git/shellgit/base_repository.rb +137 -0
- data/lib/r10k/git/shellgit/cache.rb +11 -0
- data/lib/r10k/git/shellgit/thin_repository.rb +73 -0
- data/lib/r10k/git/shellgit/working_repository.rb +112 -0
- data/lib/r10k/git/shellgit.rb +9 -0
- data/lib/r10k/git/stateful_repository.rb +109 -0
- data/lib/r10k/git.rb +200 -0
- data/lib/r10k/initializers.rb +93 -0
- data/lib/r10k/instance_cache.rb +32 -0
- data/lib/r10k/keyed_factory.rb +39 -0
- data/lib/r10k/logging/terminaloutputter.rb +36 -0
- data/lib/r10k/logging.rb +186 -0
- data/lib/r10k/module/base.rb +182 -0
- data/lib/r10k/module/definition.rb +64 -0
- data/lib/r10k/module/forge.rb +208 -0
- data/lib/r10k/module/git.rb +156 -0
- data/lib/r10k/module/local.rb +40 -0
- data/lib/r10k/module/metadata_file.rb +31 -0
- data/lib/r10k/module/svn.rb +129 -0
- data/lib/r10k/module/tarball.rb +101 -0
- data/lib/r10k/module.rb +57 -0
- data/lib/r10k/module_loader/puppetfile/dsl.rb +42 -0
- data/lib/r10k/module_loader/puppetfile.rb +290 -0
- data/lib/r10k/puppetfile.rb +211 -0
- data/lib/r10k/settings/collection.rb +123 -0
- data/lib/r10k/settings/container.rb +97 -0
- data/lib/r10k/settings/definition.rb +124 -0
- data/lib/r10k/settings/enum_definition.rb +30 -0
- data/lib/r10k/settings/helpers.rb +38 -0
- data/lib/r10k/settings/list.rb +107 -0
- data/lib/r10k/settings/loader.rb +99 -0
- data/lib/r10k/settings/mixin.rb +54 -0
- data/lib/r10k/settings/uri_definition.rb +19 -0
- data/lib/r10k/settings.rb +312 -0
- data/lib/r10k/source/base.rb +93 -0
- data/lib/r10k/source/exec.rb +51 -0
- data/lib/r10k/source/git.rb +178 -0
- data/lib/r10k/source/hash.rb +182 -0
- data/lib/r10k/source/svn.rb +142 -0
- data/lib/r10k/source/yaml.rb +20 -0
- data/lib/r10k/source/yamldir.rb +32 -0
- data/lib/r10k/source.rb +42 -0
- data/lib/r10k/svn/remote.rb +68 -0
- data/lib/r10k/svn/working_dir.rb +125 -0
- data/lib/r10k/svn.rb +6 -0
- data/lib/r10k/tarball.rb +183 -0
- data/lib/r10k/util/attempt.rb +84 -0
- data/lib/r10k/util/basedir.rb +65 -0
- data/lib/r10k/util/cacheable.rb +31 -0
- data/lib/r10k/util/cleaner.rb +21 -0
- data/lib/r10k/util/commands.rb +31 -0
- data/lib/r10k/util/downloader.rb +134 -0
- data/lib/r10k/util/exec_env.rb +36 -0
- data/lib/r10k/util/license.rb +24 -0
- data/lib/r10k/util/platform.rb +42 -0
- data/lib/r10k/util/purgeable.rb +154 -0
- data/lib/r10k/util/setopts.rb +78 -0
- data/lib/r10k/util/subprocess/result.rb +56 -0
- data/lib/r10k/util/subprocess/runner/jruby.rb +23 -0
- 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/runner/windows.rb +23 -0
- data/lib/r10k/util/subprocess/runner.rb +26 -0
- data/lib/r10k/util/subprocess/subprocess_error.rb +24 -0
- data/lib/r10k/util/subprocess.rb +85 -0
- data/lib/r10k/util/symbolize_keys.rb +35 -0
- data/lib/r10k/version.rb +6 -0
- data/lib/r10k.rb +11 -0
- data/locales/config.yaml +21 -0
- data/locales/r10k.pot +693 -0
- data/r10k.gemspec +52 -0
- data/r10k.yaml.example +140 -0
- data/spec/fixtures/empty/.empty +0 -0
- 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/module/forge/eight_hundred/Modulefile +8 -0
- data/spec/fixtures/module/forge/eight_hundred/metadata.json +19 -0
- data/spec/fixtures/tarball/tarball.tar.gz +0 -0
- data/spec/fixtures/unit/action/r10k.yaml +5 -0
- data/spec/fixtures/unit/action/r10k_cachedir.yaml +2 -0
- data/spec/fixtures/unit/action/r10k_creds.yaml +9 -0
- data/spec/fixtures/unit/action/r10k_forge_auth.yaml +4 -0
- data/spec/fixtures/unit/action/r10k_forge_auth_no_url.yaml +3 -0
- data/spec/fixtures/unit/action/r10k_generate_types.yaml +3 -0
- data/spec/fixtures/unit/action/r10k_logging.yaml +12 -0
- data/spec/fixtures/unit/action/r10k_puppet_path.yaml +3 -0
- data/spec/fixtures/unit/puppetfile/argument-error/Puppetfile +1 -0
- data/spec/fixtures/unit/puppetfile/default-branch-override/Puppetfile +5 -0
- data/spec/fixtures/unit/puppetfile/duplicate-module-error/Puppetfile +10 -0
- data/spec/fixtures/unit/puppetfile/forge-override/Puppetfile +8 -0
- data/spec/fixtures/unit/puppetfile/invalid-syntax/Puppetfile +1 -0
- data/spec/fixtures/unit/puppetfile/load-error/Puppetfile +1 -0
- data/spec/fixtures/unit/puppetfile/name-error/Puppetfile +1 -0
- data/spec/fixtures/unit/puppetfile/valid-forge-with-version/Puppetfile +1 -0
- data/spec/fixtures/unit/puppetfile/valid-forge-without-version/Puppetfile +1 -0
- data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile +10 -0
- data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile.new +10 -0
- data/spec/fixtures/unit/puppetfile/various-modules/modules/apt/.gitkeep +1 -0
- data/spec/fixtures/unit/puppetfile/various-modules/modules/baz/.gitkeep +1 -0
- data/spec/fixtures/unit/puppetfile/various-modules/modules/buzz/.gitkeep +1 -0
- data/spec/fixtures/unit/puppetfile/various-modules/modules/canary/.gitkeep +1 -0
- data/spec/fixtures/unit/puppetfile/various-modules/modules/fizz/.gitkeep +1 -0
- data/spec/fixtures/unit/puppetfile/various-modules/modules/rpm/.gitkeep +1 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/expected_1 +0 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/managed_symlink_file +1 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/subdir_allowlisted_2/ignored_1 +0 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/subdir_expected_1 +0 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/subdir_unmanaged_1 +0 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/unmanaged_symlink_dir +1 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/managed_symlink_dir +1 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/unmanaged_1 +0 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/unmanaged_symlink_file +1 -0
- data/spec/fixtures/unit/util/purgeable/managed_two/.hidden/unmanaged_3 +0 -0
- data/spec/fixtures/unit/util/purgeable/managed_two/expected_2 +0 -0
- data/spec/fixtures/unit/util/purgeable/managed_two/unmanaged_2 +0 -0
- data/spec/fixtures/unit/util/subprocess/runner/no-execute.sh +3 -0
- data/spec/integration/git/rugged/bare_repository_spec.rb +13 -0
- data/spec/integration/git/rugged/cache_spec.rb +33 -0
- data/spec/integration/git/rugged/thin_repository_spec.rb +14 -0
- data/spec/integration/git/rugged/working_repository_spec.rb +48 -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 +175 -0
- data/spec/integration/util/purageable_spec.rb +41 -0
- data/spec/matchers/exit_with.rb +28 -0
- data/spec/matchers/match_realpath.rb +18 -0
- data/spec/r10k-mocks/mock_config.rb +33 -0
- data/spec/r10k-mocks/mock_env.rb +18 -0
- data/spec/r10k-mocks/mock_source.rb +17 -0
- data/spec/r10k-mocks.rb +3 -0
- data/spec/shared-contexts/git-fixtures.rb +55 -0
- data/spec/shared-contexts/tarball.rb +32 -0
- data/spec/shared-examples/deploy-actions.rb +69 -0
- data/spec/shared-examples/git/bare_repository.rb +132 -0
- data/spec/shared-examples/git/thin_repository.rb +26 -0
- data/spec/shared-examples/git/working_repository.rb +207 -0
- data/spec/shared-examples/git-repository.rb +38 -0
- data/spec/shared-examples/puppetfile-action.rb +39 -0
- data/spec/shared-examples/settings/ancestry.rb +44 -0
- data/spec/shared-examples/subprocess-runner.rb +89 -0
- data/spec/spec_helper.rb +41 -0
- data/spec/unit/action/cri_runner_spec.rb +72 -0
- data/spec/unit/action/deploy/deploy_helpers_spec.rb +38 -0
- data/spec/unit/action/deploy/display_spec.rb +61 -0
- data/spec/unit/action/deploy/environment_spec.rb +640 -0
- data/spec/unit/action/deploy/module_spec.rb +476 -0
- data/spec/unit/action/puppetfile/check_spec.rb +53 -0
- data/spec/unit/action/puppetfile/cri_runner_spec.rb +47 -0
- data/spec/unit/action/puppetfile/install_spec.rb +112 -0
- data/spec/unit/action/puppetfile/purge_spec.rb +60 -0
- data/spec/unit/action/runner_spec.rb +407 -0
- data/spec/unit/action/visitor_spec.rb +39 -0
- data/spec/unit/cli_spec.rb +9 -0
- data/spec/unit/deployment/config_spec.rb +33 -0
- data/spec/unit/deployment_spec.rb +162 -0
- data/spec/unit/environment/bare_spec.rb +13 -0
- data/spec/unit/environment/base_spec.rb +122 -0
- data/spec/unit/environment/git_spec.rb +114 -0
- data/spec/unit/environment/name_spec.rb +181 -0
- data/spec/unit/environment/plain_spec.rb +8 -0
- data/spec/unit/environment/svn_spec.rb +146 -0
- data/spec/unit/environment/tarball_spec.rb +45 -0
- data/spec/unit/environment/with_modules_spec.rb +122 -0
- data/spec/unit/errors/formatting_spec.rb +84 -0
- data/spec/unit/feature_spec.rb +50 -0
- data/spec/unit/forge/module_release_spec.rb +213 -0
- data/spec/unit/git/alternates_spec.rb +116 -0
- data/spec/unit/git/cache_spec.rb +66 -0
- data/spec/unit/git/rugged/cache_spec.rb +48 -0
- data/spec/unit/git/rugged/credentials_spec.rb +215 -0
- data/spec/unit/git/shellgit/cache_spec.rb +27 -0
- data/spec/unit/git/stateful_repository_spec.rb +45 -0
- data/spec/unit/git_spec.rb +102 -0
- data/spec/unit/initializers_spec.rb +68 -0
- data/spec/unit/instance_cache_spec.rb +78 -0
- data/spec/unit/keyed_factory_spec.rb +51 -0
- data/spec/unit/logging/terminaloutputter_spec.rb +53 -0
- data/spec/unit/logging_spec.rb +68 -0
- data/spec/unit/module/base_spec.rb +118 -0
- data/spec/unit/module/forge_spec.rb +271 -0
- data/spec/unit/module/git_spec.rb +387 -0
- data/spec/unit/module/metadata_file_spec.rb +68 -0
- data/spec/unit/module/svn_spec.rb +208 -0
- data/spec/unit/module/tarball_spec.rb +70 -0
- data/spec/unit/module_loader/puppetfile_spec.rb +421 -0
- data/spec/unit/module_spec.rb +114 -0
- data/spec/unit/puppetfile_spec.rb +304 -0
- data/spec/unit/settings/collection_spec.rb +123 -0
- data/spec/unit/settings/container_spec.rb +92 -0
- data/spec/unit/settings/definition_spec.rb +79 -0
- data/spec/unit/settings/enum_definition_spec.rb +20 -0
- data/spec/unit/settings/inheritance_spec.rb +38 -0
- data/spec/unit/settings/list_spec.rb +88 -0
- data/spec/unit/settings/loader_spec.rb +110 -0
- data/spec/unit/settings/uri_definition_spec.rb +23 -0
- data/spec/unit/settings_spec.rb +303 -0
- data/spec/unit/source/base_spec.rb +31 -0
- data/spec/unit/source/exec_spec.rb +81 -0
- data/spec/unit/source/git_spec.rb +233 -0
- data/spec/unit/source/hash_spec.rb +54 -0
- data/spec/unit/source/svn_spec.rb +196 -0
- data/spec/unit/source/yaml_spec.rb +42 -0
- data/spec/unit/source_spec.rb +10 -0
- data/spec/unit/svn/remote_spec.rb +21 -0
- data/spec/unit/svn/working_dir_spec.rb +56 -0
- data/spec/unit/tarball_spec.rb +57 -0
- data/spec/unit/util/attempt_spec.rb +82 -0
- data/spec/unit/util/cacheable_spec.rb +23 -0
- data/spec/unit/util/commands_spec.rb +61 -0
- data/spec/unit/util/downloader_spec.rb +98 -0
- data/spec/unit/util/exec_env_spec.rb +56 -0
- data/spec/unit/util/purgeable_spec.rb +267 -0
- data/spec/unit/util/setopts_spec.rb +83 -0
- data/spec/unit/util/subprocess/result_spec.rb +36 -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/runner/windows_spec.rb +7 -0
- data/spec/unit/util/subprocess/subprocess_error_spec.rb +26 -0
- data/spec/unit/util/subprocess_spec.rb +65 -0
- data/spec/unit/util/symbolize_keys_spec.rb +67 -0
- metadata +637 -0
@@ -0,0 +1,205 @@
|
|
1
|
+
require 'r10k/git/rugged'
|
2
|
+
require 'r10k/git/errors'
|
3
|
+
require 'r10k/logging'
|
4
|
+
require 'json'
|
5
|
+
require 'jwt'
|
6
|
+
require 'net/http'
|
7
|
+
require 'openssl'
|
8
|
+
|
9
|
+
# Generate credentials for secured remote connections.
|
10
|
+
#
|
11
|
+
# @api private
|
12
|
+
class R10K::Git::Rugged::Credentials
|
13
|
+
|
14
|
+
include R10K::Logging
|
15
|
+
|
16
|
+
# @param repository [R10K::Git::Rugged::BaseRepository]
|
17
|
+
def initialize(repository)
|
18
|
+
@repository = repository
|
19
|
+
@called = 0
|
20
|
+
end
|
21
|
+
|
22
|
+
def call(url, username_from_url, allowed_types)
|
23
|
+
@called += 1
|
24
|
+
|
25
|
+
# Break out of infinite HTTP auth retry loop introduced in libgit2/rugged 0.24.0, libssh
|
26
|
+
# auth seems to already abort after ~50 attempts.
|
27
|
+
if @called > 50
|
28
|
+
raise R10K::Git::GitError.new(_("Authentication failed for Git remote %{url}.") % {url: url.inspect} )
|
29
|
+
end
|
30
|
+
|
31
|
+
if allowed_types.include?(:ssh_key)
|
32
|
+
get_ssh_key_credentials(url, username_from_url)
|
33
|
+
elsif allowed_types.include?(:plaintext)
|
34
|
+
get_plaintext_credentials(url, username_from_url)
|
35
|
+
else
|
36
|
+
get_default_credentials(url, username_from_url)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_ssh_key_credentials(url, username_from_url)
|
41
|
+
user = get_git_username(url, username_from_url)
|
42
|
+
|
43
|
+
per_repo_private_key = nil
|
44
|
+
if per_repo_settings = R10K::Git.get_repo_settings(url)
|
45
|
+
per_repo_private_key = per_repo_settings[:private_key]
|
46
|
+
end
|
47
|
+
|
48
|
+
global_private_key = R10K::Git.settings[:private_key]
|
49
|
+
|
50
|
+
if per_repo_private_key
|
51
|
+
private_key = per_repo_private_key
|
52
|
+
logger.debug2 _("Using per-repository private key %{key} for URL %{url}") % {key: private_key, url: url.inspect}
|
53
|
+
elsif global_private_key
|
54
|
+
private_key = global_private_key
|
55
|
+
logger.debug2 _("URL %{url} has no per-repository private key using '%{key}'." ) % {key: private_key, url: url.inspect}
|
56
|
+
else
|
57
|
+
raise R10K::Git::GitError.new(_("Git remote %{url} uses the SSH protocol but no private key was given") % {url: url.inspect}, :git_dir => @repository.path.to_s)
|
58
|
+
end
|
59
|
+
|
60
|
+
if !File.readable?(private_key)
|
61
|
+
raise R10K::Git::GitError.new(_("Unable to use SSH key auth for %{url}: private key %{private_key} is missing or unreadable") % {url: url.inspect, private_key: private_key.inspect}, :git_dir => @repository.path.to_s)
|
62
|
+
end
|
63
|
+
|
64
|
+
Rugged::Credentials::SshKey.new(:username => user, :privatekey => private_key)
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_plaintext_credentials(url, username_from_url)
|
68
|
+
per_repo_oauth_token = nil
|
69
|
+
per_repo_github_app_id = nil
|
70
|
+
per_repo_github_app_key = nil
|
71
|
+
per_repo_github_app_ttl = nil
|
72
|
+
|
73
|
+
if per_repo_settings = R10K::Git.get_repo_settings(url)
|
74
|
+
per_repo_oauth_token = per_repo_settings[:oauth_token]
|
75
|
+
per_repo_github_app_id = per_repo_settings[:github_app_id]
|
76
|
+
per_repo_github_app_key = per_repo_settings[:github_app_key]
|
77
|
+
per_repo_github_app_ttl = per_repo_settings[:github_app_ttl]
|
78
|
+
end
|
79
|
+
|
80
|
+
app_id = per_repo_github_app_id || R10K::Git.settings[:github_app_id]
|
81
|
+
app_key = per_repo_github_app_key || R10K::Git.settings[:github_app_key]
|
82
|
+
app_ttl = per_repo_github_app_ttl || R10K::Git.settings[:github_app_ttl]
|
83
|
+
|
84
|
+
if token_path = per_repo_oauth_token || R10K::Git.settings[:oauth_token]
|
85
|
+
@oauth_token ||= extract_token(token_path, url)
|
86
|
+
|
87
|
+
user = 'x-oauth-token'
|
88
|
+
password = @oauth_token
|
89
|
+
elsif app_id && app_key && app_ttl
|
90
|
+
user = 'x-access-token'
|
91
|
+
password = github_app_token(app_id, app_key, app_ttl)
|
92
|
+
else
|
93
|
+
user = get_git_username(url, username_from_url)
|
94
|
+
password = URI.parse(url).password || ''
|
95
|
+
end
|
96
|
+
Rugged::Credentials::UserPassword.new(username: user, password: password)
|
97
|
+
end
|
98
|
+
|
99
|
+
def extract_token(token_path, url)
|
100
|
+
if token_path == '-'
|
101
|
+
token = $stdin.read.strip
|
102
|
+
logger.debug2 _("Using OAuth token from stdin for URL %{url}") % { url: url }
|
103
|
+
elsif File.readable?(token_path)
|
104
|
+
token = File.read(token_path).strip
|
105
|
+
logger.debug2 _("Using OAuth token from %{token_path} for URL %{url}") % { token_path: token_path, url: url }
|
106
|
+
else
|
107
|
+
raise R10K::Git::GitError, _("%{path} is missing or unreadable, cannot load OAuth token") % { path: token_path }
|
108
|
+
end
|
109
|
+
|
110
|
+
unless valid_token?(token)
|
111
|
+
raise R10K::Git::GitError, _("Supplied OAuth token contains invalid characters.")
|
112
|
+
end
|
113
|
+
|
114
|
+
token
|
115
|
+
end
|
116
|
+
|
117
|
+
# This regex is the only real requirement for OAuth token format,
|
118
|
+
# per https://www.oauth.com/oauth2-servers/access-tokens/access-token-response/
|
119
|
+
# Bitbucket's tokens also can include an underscore, so that is added here.
|
120
|
+
def valid_token?(token)
|
121
|
+
return token =~ /^[\w\-\.~_\+\/]+$/
|
122
|
+
end
|
123
|
+
|
124
|
+
def get_default_credentials(url, username_from_url)
|
125
|
+
Rugged::Credentials::Default.new
|
126
|
+
end
|
127
|
+
|
128
|
+
def get_git_username(url, username_from_url)
|
129
|
+
git_user = R10K::Git.settings[:username]
|
130
|
+
|
131
|
+
user = nil
|
132
|
+
|
133
|
+
if !username_from_url.nil? && !username_from_url.empty?
|
134
|
+
user = username_from_url
|
135
|
+
logger.debug2 _("URL %{url} includes the username %{username}, using that user for authentication.") % {url: url.inspect, username: username_from_url}
|
136
|
+
elsif git_user
|
137
|
+
user = git_user
|
138
|
+
logger.debug2 _("URL %{url} did not specify a user, using %{user} from configuration") % {url: url.inspect, user: user.inspect}
|
139
|
+
else
|
140
|
+
user = Etc.getlogin
|
141
|
+
logger.debug2 _("URL %{url} did not specify a user, using current user %{user}") % {url: url.inspect, user: user.inspect}
|
142
|
+
end
|
143
|
+
|
144
|
+
user
|
145
|
+
end
|
146
|
+
|
147
|
+
def github_app_token(app_id, private_key, ttl)
|
148
|
+
raise R10K::Git::GitError, _('Github App id contains invalid characters.') unless app_id =~ /^\d+$/
|
149
|
+
raise R10K::Git::GitError, _('Github App token ttl contains invalid characters.') unless ttl =~ /^\d+$/
|
150
|
+
raise R10K::Git::GitError, _('Github App key is missing or unreadable') unless File.readable?(private_key)
|
151
|
+
|
152
|
+
begin
|
153
|
+
ssl_key = OpenSSL::PKey::RSA.new(File.read(private_key).strip)
|
154
|
+
unless ssl_key.private?
|
155
|
+
raise R10K::Git::GitError, _('Github App key is not a valid SSL private key')
|
156
|
+
end
|
157
|
+
rescue OpenSSL::PKey::RSAError
|
158
|
+
raise R10K::Git::GitError, _('Github App key is not a valid SSL key')
|
159
|
+
end
|
160
|
+
|
161
|
+
logger.debug2 _("Using Github App id %{app_id} with SSL key from %{key_path}") % { key_path: private_key, app_id: app_id }
|
162
|
+
|
163
|
+
jwt_issue_time = Time.now.to_i - 60
|
164
|
+
jwt_exp_time = (jwt_issue_time + 60) + ttl.to_i
|
165
|
+
payload = { iat: jwt_issue_time, exp: jwt_exp_time, iss: app_id }
|
166
|
+
jwt = JWT.encode(payload, ssl_key, "RS256")
|
167
|
+
|
168
|
+
get = URI.parse("https://api.github.com/app/installations")
|
169
|
+
get_request = Net::HTTP::Get.new(get)
|
170
|
+
get_request["Authorization"] = "Bearer #{jwt}"
|
171
|
+
get_request["Accept"] = "application/vnd.github.v3+json"
|
172
|
+
get_req_options = { use_ssl: get.scheme == "https", }
|
173
|
+
get_response = Net::HTTP.start(get.hostname, get.port, get_req_options) do |http|
|
174
|
+
http.request(get_request)
|
175
|
+
end
|
176
|
+
|
177
|
+
unless (get_response.class < Net::HTTPSuccess)
|
178
|
+
logger.debug2 _("Unexpected response code: #{get_response.code}\nResponse body: #{get_response.body}")
|
179
|
+
raise R10K::Git::GitError, _("Error using private key to get Github App access token from url")
|
180
|
+
end
|
181
|
+
|
182
|
+
access_tokens_url = JSON.parse(get_response.body)[0]['access_tokens_url']
|
183
|
+
|
184
|
+
post = URI.parse(access_tokens_url)
|
185
|
+
post_request = Net::HTTP::Post.new(post)
|
186
|
+
post_request["Authorization"] = "Bearer #{jwt}"
|
187
|
+
post_request["Accept"] = "application/vnd.github.v3+json"
|
188
|
+
post_req_options = { use_ssl: post.scheme == "https", }
|
189
|
+
post_response = Net::HTTP.start(post.hostname, post.port, post_req_options) do |http|
|
190
|
+
http.request(post_request)
|
191
|
+
end
|
192
|
+
|
193
|
+
unless (post_response.class < Net::HTTPSuccess)
|
194
|
+
logger.debug2 _("Unexpected response code: #{post_response.code}\nResponse body: #{post_response.body}")
|
195
|
+
raise R10K::Git::GitError, _("Error using private key to generate access token from #{access_token_url}")
|
196
|
+
end
|
197
|
+
|
198
|
+
token = JSON.parse(post_response.body)['token']
|
199
|
+
|
200
|
+
raise R10K::Git::GitError, _("Github App token contains invalid characters.") unless valid_token?(token)
|
201
|
+
|
202
|
+
logger.debug2 _("Github App token generated, expires at: %{expire}") % {expire: JSON.parse(post_response.body)['expires_at']}
|
203
|
+
token
|
204
|
+
end
|
205
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'r10k/git'
|
2
|
+
require 'r10k/git/rugged/working_repository'
|
3
|
+
require 'r10k/git/rugged/cache'
|
4
|
+
|
5
|
+
class R10K::Git::Rugged::ThinRepository < R10K::Git::Rugged::WorkingRepository
|
6
|
+
def initialize(basedir, dirname, cache_repo)
|
7
|
+
@cache_repo = cache_repo
|
8
|
+
|
9
|
+
super(basedir, dirname)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Clone this git repository
|
13
|
+
#
|
14
|
+
# @param remote [String] The Git remote to clone
|
15
|
+
# @param opts [Hash]
|
16
|
+
#
|
17
|
+
# @options opts [String] :ref The git ref to check out on clone
|
18
|
+
#
|
19
|
+
# @return [void]
|
20
|
+
def clone(remote, opts = {})
|
21
|
+
logger.debug1 { "Cloning '#{remote}' into #{@path}" }
|
22
|
+
@cache_repo.sync
|
23
|
+
|
24
|
+
cache_objects_dir = @cache_repo.objects_dir.to_s
|
25
|
+
|
26
|
+
# {Rugged::Repository.clone_at} doesn't support :alternates, which
|
27
|
+
# completely breaks how thin repositories need to work. To circumvent
|
28
|
+
# this we manually create a Git repository, set up git remotes, and
|
29
|
+
# update 'objects/info/alternates' with the path. We don't actually
|
30
|
+
# fetch any objects because we don't need them, and we don't actually
|
31
|
+
# use any refs in this repository so we skip all those steps.
|
32
|
+
::Rugged::Repository.init_at(@path.to_s, false)
|
33
|
+
@_rugged_repo = ::Rugged::Repository.new(@path.to_s, :alternates => [cache_objects_dir])
|
34
|
+
alternates << cache_objects_dir
|
35
|
+
|
36
|
+
with_repo do |repo|
|
37
|
+
config = repo.config
|
38
|
+
config['remote.origin.url'] = remote
|
39
|
+
config['remote.origin.fetch'] = '+refs/heads/*:refs/remotes/origin/*'
|
40
|
+
config['remote.cache.url'] = @cache_repo.git_dir.to_s
|
41
|
+
config['remote.cache.fetch'] = '+refs/heads/*:refs/remotes/cache/*'
|
42
|
+
end
|
43
|
+
|
44
|
+
checkout(opts.fetch(:ref, 'HEAD'))
|
45
|
+
end
|
46
|
+
|
47
|
+
def checkout(ref, opts = {})
|
48
|
+
super(@cache_repo.resolve(ref), opts)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Fetch refs and objects from one of the Git remotes
|
52
|
+
#
|
53
|
+
# @param remote [String] The remote to fetch, defaults to 'cache'
|
54
|
+
# @return [void]
|
55
|
+
def fetch(remote = 'cache')
|
56
|
+
super(remote)
|
57
|
+
end
|
58
|
+
|
59
|
+
# @return [String] The cache remote URL
|
60
|
+
def cache
|
61
|
+
with_repo { |repo| repo.config['remote.cache.url'] }
|
62
|
+
end
|
63
|
+
|
64
|
+
def tracked_paths(ref="HEAD")
|
65
|
+
with_repo do |repo|
|
66
|
+
commit = repo.rev_parse(ref)
|
67
|
+
|
68
|
+
unless commit && commit.tree
|
69
|
+
raise R10K::Error.new("Unable to resolve '#{ref}' to a valid commit in repo #{@path}")
|
70
|
+
end
|
71
|
+
|
72
|
+
commit.tree.walk(:postorder).collect do |root, entry|
|
73
|
+
root.empty? ? entry[:name] : File.join(root, entry[:name])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def stage_files(files=['.'])
|
79
|
+
with_repo do |repo|
|
80
|
+
index = repo.index
|
81
|
+
files.each { |p| index.add( :path => p ) }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
# Override the parent class repo setup so that we can make sure the alternates file is up to date
|
88
|
+
# before we create the Rugged::Repository object, which reads from the alternates file.
|
89
|
+
def setup_rugged_repo
|
90
|
+
entry_added = alternates.add?(@cache_repo.objects_dir.to_s)
|
91
|
+
if entry_added
|
92
|
+
logger.debug2 { _("Updated repo %{path} to include alternate object db path %{objects_dir}") % {path: @path, objects_dir: @cache_repo.objects_dir} }
|
93
|
+
end
|
94
|
+
super
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'r10k/git/rugged'
|
2
|
+
require 'r10k/git/rugged/base_repository'
|
3
|
+
require 'r10k/git/errors'
|
4
|
+
|
5
|
+
class R10K::Git::Rugged::WorkingRepository < R10K::Git::Rugged::BaseRepository
|
6
|
+
|
7
|
+
# @return [Pathname] The path to the Git repository inside of this directory
|
8
|
+
def git_dir
|
9
|
+
@path + '.git'
|
10
|
+
end
|
11
|
+
|
12
|
+
# @param basedir [String] The base directory of the Git repository
|
13
|
+
# @param dirname [String] The directory name of the Git repository
|
14
|
+
def initialize(basedir, dirname)
|
15
|
+
@path = Pathname.new(File.join(basedir, dirname))
|
16
|
+
end
|
17
|
+
|
18
|
+
# Clone this git repository
|
19
|
+
#
|
20
|
+
# @param remote [String] The Git remote to clone
|
21
|
+
# @param opts [Hash]
|
22
|
+
#
|
23
|
+
# @options opts [String] :ref The git ref to check out on clone
|
24
|
+
# @options opts [String] :reference A Git repository to use as an alternate object database
|
25
|
+
#
|
26
|
+
# @return [void]
|
27
|
+
def clone(remote, opts = {})
|
28
|
+
logger.debug1 { _("Cloning '%{remote}' into %{path}") % {remote: remote, path: @path } }
|
29
|
+
|
30
|
+
# libgit2/rugged doesn't support cloning a repository and providing an
|
31
|
+
# alternate object database, making the handling of :alternates a noop.
|
32
|
+
# Unfortunately this means that this method can't really use alternates
|
33
|
+
# and running the clone will duplicate all objects in the specified
|
34
|
+
# repository. However alternate databases can be handled when an existing
|
35
|
+
# repository is loaded, so loading a cloned repo will correctly use
|
36
|
+
# alternate object database.
|
37
|
+
options = {:credentials => credentials}
|
38
|
+
options.merge!(:alternates => [File.join(opts[:reference], 'objects')]) if opts[:reference]
|
39
|
+
|
40
|
+
proxy = R10K::Git.get_proxy_for_remote(remote)
|
41
|
+
|
42
|
+
R10K::Git.with_proxy(proxy) do
|
43
|
+
@_rugged_repo = ::Rugged::Repository.clone_at(remote, @path.to_s, options)
|
44
|
+
end
|
45
|
+
|
46
|
+
if opts[:reference]
|
47
|
+
alternates << File.join(opts[:reference], 'objects')
|
48
|
+
end
|
49
|
+
|
50
|
+
if opts[:ref]
|
51
|
+
# todo: always check out something; since we're fetching a repository we
|
52
|
+
# won't populate the working directory.
|
53
|
+
checkout(opts[:ref])
|
54
|
+
end
|
55
|
+
rescue Rugged::SshError, Rugged::NetworkError => e
|
56
|
+
raise R10K::Git::GitError.new(e.message, :git_dir => git_dir, :backtrace => e.backtrace)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Check out the given Git ref
|
60
|
+
#
|
61
|
+
# @param ref [String] The git reference to check out
|
62
|
+
# @return [void]
|
63
|
+
def checkout(ref, opts = {})
|
64
|
+
sha = resolve(ref)
|
65
|
+
|
66
|
+
if sha
|
67
|
+
logger.debug2 { _("Checking out ref '%{ref}' (resolved to SHA '%{sha}') in repository %{path}") % {ref: ref, sha: sha, path: @path} }
|
68
|
+
else
|
69
|
+
raise R10K::Git::GitError.new("Unable to check out unresolvable ref '#{ref}'", git_dir: git_dir)
|
70
|
+
end
|
71
|
+
|
72
|
+
# :force defaults to true
|
73
|
+
force = !opts.has_key?(:force) || opts[:force]
|
74
|
+
|
75
|
+
with_repo do |repo|
|
76
|
+
# rugged/libgit2 will not update (at least) the execute bit a file if the SHA is already at
|
77
|
+
# the value being reset to, so this is now changed to an if ... else
|
78
|
+
if force
|
79
|
+
repo.reset(sha, :hard)
|
80
|
+
else
|
81
|
+
repo.checkout(sha)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def fetch(remote_name = 'origin')
|
87
|
+
logger.debug1 { _("Fetching remote '%{remote}' at %{path}") % {remote: remote_name, path: @path} }
|
88
|
+
options = {:credentials => credentials}
|
89
|
+
refspecs = ["+refs/heads/*:refs/remotes/#{remote_name}/*"]
|
90
|
+
|
91
|
+
remote = remotes[remote_name]
|
92
|
+
proxy = R10K::Git.get_proxy_for_remote(remote)
|
93
|
+
results = nil
|
94
|
+
|
95
|
+
R10K::Git.with_proxy(proxy) do
|
96
|
+
results = with_repo { |repo| repo.fetch(remote_name, refspecs, **options) }
|
97
|
+
end
|
98
|
+
|
99
|
+
report_transfer(results, remote)
|
100
|
+
rescue Rugged::SshError, Rugged::NetworkError => e
|
101
|
+
raise R10K::Git::GitError.new(e.message, :git_dir => git_dir, :backtrace => e.backtrace)
|
102
|
+
end
|
103
|
+
|
104
|
+
def exist?
|
105
|
+
@path.exist?
|
106
|
+
end
|
107
|
+
|
108
|
+
def head
|
109
|
+
resolve('HEAD')
|
110
|
+
end
|
111
|
+
|
112
|
+
def alternates
|
113
|
+
R10K::Git::Alternates.new(git_dir)
|
114
|
+
end
|
115
|
+
|
116
|
+
def origin
|
117
|
+
with_repo { |repo| repo.config['remote.origin.url'] }
|
118
|
+
end
|
119
|
+
|
120
|
+
def dirty?(exclude_spec=false)
|
121
|
+
with_repo do |repo|
|
122
|
+
if exclude_spec
|
123
|
+
diff = repo.diff_workdir('HEAD').filter { |d| ! d.delta.old_file[:path].start_with?('spec/') }
|
124
|
+
else
|
125
|
+
diff = repo.diff_workdir('HEAD').to_a
|
126
|
+
end
|
127
|
+
|
128
|
+
diff.each do |p|
|
129
|
+
logger.debug(_("Found local modifications in %{file_path}" % {file_path: File.join(@path, p.delta.old_file[:path])}))
|
130
|
+
logger.debug1(p.to_s)
|
131
|
+
end
|
132
|
+
|
133
|
+
return diff.size > 0
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
private
|
138
|
+
|
139
|
+
def with_repo
|
140
|
+
if @_rugged_repo.nil? && git_dir.exist?
|
141
|
+
setup_rugged_repo
|
142
|
+
end
|
143
|
+
super
|
144
|
+
end
|
145
|
+
|
146
|
+
def setup_rugged_repo
|
147
|
+
@_rugged_repo = ::Rugged::Repository.new(@path.to_s, :alternates => alternates.to_a)
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'r10k/git'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rugged'
|
5
|
+
rescue LoadError
|
6
|
+
end
|
7
|
+
|
8
|
+
module R10K
|
9
|
+
module Git
|
10
|
+
module Rugged
|
11
|
+
require 'r10k/git/rugged/bare_repository'
|
12
|
+
require 'r10k/git/rugged/working_repository'
|
13
|
+
require 'r10k/git/rugged/cache'
|
14
|
+
require 'r10k/git/rugged/thin_repository'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'r10k/git/shellgit'
|
2
|
+
require 'r10k/git/shellgit/base_repository'
|
3
|
+
|
4
|
+
# Create and manage Git bare repositories.
|
5
|
+
class R10K::Git::ShellGit::BareRepository < R10K::Git::ShellGit::BaseRepository
|
6
|
+
|
7
|
+
# @param basedir [String] The base directory of the Git repository
|
8
|
+
# @param dirname [String] The directory name of the Git repository
|
9
|
+
def initialize(basedir, dirname)
|
10
|
+
@path = Pathname.new(File.join(basedir, dirname))
|
11
|
+
end
|
12
|
+
|
13
|
+
# @return [Pathname] The path to this Git repository
|
14
|
+
def git_dir
|
15
|
+
@path
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [Pathname] The path to the objects directory in this Git repository
|
19
|
+
def objects_dir
|
20
|
+
@path + "objects"
|
21
|
+
end
|
22
|
+
|
23
|
+
def clone(remote)
|
24
|
+
proxy = R10K::Git.get_proxy_for_remote(remote)
|
25
|
+
|
26
|
+
R10K::Git.with_proxy(proxy) do
|
27
|
+
git ['clone', '--mirror', remote, git_dir.to_s]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def fetch(remote_name='origin')
|
32
|
+
remote = remotes[remote_name]
|
33
|
+
proxy = R10K::Git.get_proxy_for_remote(remote)
|
34
|
+
|
35
|
+
R10K::Git.with_proxy(proxy) do
|
36
|
+
git ['fetch', remote_name, '--prune'], :git_dir => git_dir.to_s
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def exist?
|
41
|
+
@path.exist?
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'r10k/git/shellgit'
|
2
|
+
require 'r10k/util/subprocess'
|
3
|
+
require 'r10k/logging'
|
4
|
+
|
5
|
+
class R10K::Git::ShellGit::BaseRepository
|
6
|
+
|
7
|
+
# @abstract
|
8
|
+
# @return [Pathname] The path to the Git directory
|
9
|
+
def git_dir
|
10
|
+
raise NotImplementedError
|
11
|
+
end
|
12
|
+
|
13
|
+
# Resolve the given Git ref to a commit
|
14
|
+
#
|
15
|
+
# @param pattern [String] The git ref to resolve
|
16
|
+
# @return [String, nil] The commit SHA if the ref could be resolved, nil otherwise.
|
17
|
+
def resolve(pattern)
|
18
|
+
result = git ['rev-parse', "#{pattern}^{commit}"], :git_dir => git_dir.to_s, :raise_on_fail => false
|
19
|
+
if result.success?
|
20
|
+
result.stdout
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# For compatibility with R10K::Git::Ref
|
25
|
+
# @todo remove alias
|
26
|
+
alias rev_parse resolve
|
27
|
+
|
28
|
+
# @return [Array<String>] All local branches in this repository
|
29
|
+
def branches
|
30
|
+
for_each_ref('refs/heads')
|
31
|
+
end
|
32
|
+
|
33
|
+
def is_branch?(pattern)
|
34
|
+
result = git ['rev-parse', '-q', '--verify', "refs/heads/#{pattern}"], :git_dir => git_dir.to_s, :raise_on_fail => false
|
35
|
+
|
36
|
+
result.success?
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [Array<String>] All tags in this repository
|
40
|
+
def tags
|
41
|
+
for_each_ref('refs/tags')
|
42
|
+
end
|
43
|
+
|
44
|
+
def is_tag?(pattern)
|
45
|
+
result = git ['rev-parse', '-q', '--verify', "refs/tags/#{pattern}"], :git_dir => git_dir.to_s, :raise_on_fail => false
|
46
|
+
|
47
|
+
result.success?
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [Symbol] The type of the given ref, one of :branch, :tag, :commit, or :unknown
|
51
|
+
def ref_type(pattern)
|
52
|
+
@_ref_type_cache ||= {}
|
53
|
+
|
54
|
+
@_ref_type_cache[pattern] ||= begin
|
55
|
+
# Try to match and resolve SHA refs as quickly as possible.
|
56
|
+
if pattern =~ /^[0-9a-f]{5,40}$/i && resolve(pattern)
|
57
|
+
:commit
|
58
|
+
elsif is_tag? pattern
|
59
|
+
:tag
|
60
|
+
elsif is_branch? pattern
|
61
|
+
:branch
|
62
|
+
elsif resolve(pattern)
|
63
|
+
:commit
|
64
|
+
else
|
65
|
+
:unknown
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# @return [Hash] Collection of remotes for this repo, keys are the remote name and values are the remote URL.
|
71
|
+
def remotes
|
72
|
+
result = git ['config', '--local', '--get-regexp', '^remote\..*\.url$'], :git_dir => git_dir.to_s, :raise_on_fail => false
|
73
|
+
|
74
|
+
if result.success?
|
75
|
+
Hash[
|
76
|
+
result.stdout.split("\n").collect do |remote|
|
77
|
+
matches = /^remote\.(.*)\.url (.*)$/.match(remote)
|
78
|
+
|
79
|
+
[matches[1], matches[2]]
|
80
|
+
end
|
81
|
+
]
|
82
|
+
else
|
83
|
+
{}
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
include R10K::Logging
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
# @param pattern [String]
|
92
|
+
def for_each_ref(pattern)
|
93
|
+
matcher = %r[#{pattern}/(.*)$]
|
94
|
+
output = git ['for-each-ref', pattern, '--format', '%(refname)'], :git_dir => git_dir.to_s
|
95
|
+
output.stdout.scan(matcher).flatten
|
96
|
+
end
|
97
|
+
|
98
|
+
# Wrap git commands
|
99
|
+
#
|
100
|
+
# @param cmd [Array<String>] cmd The arguments for the git prompt
|
101
|
+
# @param opts [Hash] opts
|
102
|
+
#
|
103
|
+
# @option opts [String] :path
|
104
|
+
# @option opts [String] :git_dir
|
105
|
+
# @option opts [String] :work_tree
|
106
|
+
# @option opts [String] :raise_on_fail
|
107
|
+
#
|
108
|
+
# @raise [R10K::ExecutionFailure] If the executed command exited with a
|
109
|
+
# nonzero exit code.
|
110
|
+
#
|
111
|
+
# @return [String] The git command output
|
112
|
+
def git(cmd, opts = {})
|
113
|
+
raise_on_fail = opts.fetch(:raise_on_fail, true)
|
114
|
+
|
115
|
+
argv = %w{git}
|
116
|
+
|
117
|
+
if opts[:path]
|
118
|
+
argv << "--git-dir" << File.join(opts[:path], '.git')
|
119
|
+
argv << "--work-tree" << opts[:path]
|
120
|
+
else
|
121
|
+
if opts[:git_dir]
|
122
|
+
argv << "--git-dir" << opts[:git_dir]
|
123
|
+
end
|
124
|
+
if opts[:work_tree]
|
125
|
+
argv << "--work-tree" << opts[:work_tree]
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
argv.concat(cmd)
|
130
|
+
|
131
|
+
subproc = R10K::Util::Subprocess.new(argv)
|
132
|
+
subproc.raise_on_fail = raise_on_fail
|
133
|
+
subproc.logger = self.logger
|
134
|
+
|
135
|
+
subproc.execute
|
136
|
+
end
|
137
|
+
end
|