r10k 1.4.2 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (244) hide show
  1. data/.travis.yml +2 -0
  2. data/CHANGELOG.mkd +192 -0
  3. data/CONTRIBUTING.mkd +3 -3
  4. data/Gemfile +4 -0
  5. data/README.mkd +13 -6
  6. data/doc/dynamic-environments/configuration.mkd +77 -8
  7. data/doc/dynamic-environments/git-environments.mkd +12 -2
  8. data/doc/dynamic-environments/quickstart.mkd +6 -0
  9. data/doc/faq.mkd +6 -6
  10. data/doc/git/cloning-and-mirroring.mkd +60 -0
  11. data/doc/git/providers.mkd +68 -0
  12. data/integration/Gemfile +3 -0
  13. data/integration/README.mkd +29 -0
  14. data/integration/configs/README.mkd +7 -0
  15. data/integration/configs/pe/centos-6-64mda +25 -0
  16. data/integration/configs/pe/centos-7-64mda +25 -0
  17. data/integration/configs/pe/debian-6-64mda +25 -0
  18. data/integration/configs/pe/debian-7-64mda +25 -0
  19. data/integration/configs/pe/redhat-6-64mda +25 -0
  20. data/integration/configs/pe/redhat-7-64mda +25 -0
  21. data/integration/configs/pe/sles-11-64mda +25 -0
  22. data/integration/configs/pe/ubuntu-1004-64mda +25 -0
  23. data/integration/configs/pe/ubuntu-1204-64mda +25 -0
  24. data/integration/configs/pe/ubuntu-1404-64mda +25 -0
  25. data/integration/files/README.mkd +4 -0
  26. data/integration/files/hiera.yaml +8 -0
  27. data/integration/files/modules/helloworld/manifests/init.pp +3 -0
  28. data/integration/files/modules/hieratest/manifests/init.pp +3 -0
  29. data/integration/files/modules/unicode/files/pretend_unicode +1 -0
  30. data/integration/files/modules/unicode/manifests/init.pp +6 -0
  31. data/integration/files/pre-suite/prod_env.config +3 -0
  32. data/integration/files/r10k_conf.yaml.erb +9 -0
  33. data/integration/lib/README.mkd +4 -0
  34. data/integration/lib/git_utils.rb +205 -0
  35. data/integration/lib/master_manipulator.rb +205 -0
  36. data/integration/lib/r10k_utils.rb +166 -0
  37. data/integration/manifests/README.mkd +4 -0
  38. data/integration/pre-suite/00_pe_install.rb +4 -0
  39. data/integration/pre-suite/01_git_config.rb +59 -0
  40. data/integration/pre-suite/02_pe_r10k.rb +60 -0
  41. data/integration/pre-suite/03_test_utils.rb +17 -0
  42. data/integration/pre-suite/README.mkd +5 -0
  43. data/integration/test_run_scripts/README.mkd +5 -0
  44. data/integration/test_run_scripts/all_tests-rugged-pe-centos6.sh +20 -0
  45. data/integration/test_run_scripts/all_tests-rugged-pe-rhel7.sh +20 -0
  46. data/integration/test_run_scripts/all_tests-rugged-pe-sles11.sh +20 -0
  47. data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1204.sh +20 -0
  48. data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1404.sh +20 -0
  49. data/integration/test_run_scripts/all_tests-shellgit-pe-centos6.sh +20 -0
  50. data/integration/test_run_scripts/all_tests-shellgit-pe-rhel7.sh +20 -0
  51. data/integration/test_run_scripts/all_tests-shellgit-pe-sles11.sh +20 -0
  52. data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1204.sh +20 -0
  53. data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1404.sh +20 -0
  54. data/integration/test_run_scripts/basic_functionality/all_tests-pe-centos6.sh +20 -0
  55. data/integration/test_run_scripts/command_line/all_tests-pe-centos6.sh +20 -0
  56. data/integration/test_run_scripts/git_source/all_tests-pe-centos6.sh +20 -0
  57. data/integration/test_run_scripts/user_scenario/basic_workflow/all_tests-pe-centos6.sh +20 -0
  58. data/integration/test_run_scripts/user_scenario/complex_workflow/all_tests-pe-centos6.sh +20 -0
  59. data/integration/tests/README.mkd +4 -0
  60. data/integration/tests/basic_functionality/negative/neg_deploy_with_invalid_r10k_yaml.rb +46 -0
  61. data/integration/tests/basic_functionality/negative/neg_deploy_with_missing_r10k_yaml.rb +27 -0
  62. data/integration/tests/command_line/deploy_env_without_mod_update.rb +75 -0
  63. data/integration/tests/command_line/negative/neg_deploy_env_with_module_update.rb +76 -0
  64. data/integration/tests/command_line/negative/neg_invalid_cli_dep_flag.rb +22 -0
  65. data/integration/tests/command_line/negative/neg_invalid_cli_env_flag.rb +22 -0
  66. data/integration/tests/command_line/negative/neg_invalid_cmd_line_arg.rb +24 -0
  67. data/integration/tests/git_source/git_source_git.rb +123 -0
  68. data/integration/tests/git_source/git_source_ssh.rb +84 -0
  69. data/integration/tests/git_source/git_source_submodule.rb +69 -0
  70. data/integration/tests/git_source/negative/neg_git_broken_remote.rb +37 -0
  71. data/integration/tests/git_source/negative/neg_git_unauthorized_https.rb +45 -0
  72. data/integration/tests/git_source/negative/neg_git_unauthorized_ssh.rb +72 -0
  73. data/integration/tests/git_source/negative/neg_git_unicode_branch.rb +34 -0
  74. data/integration/tests/user_scenario/basic_workflow/multi_env_1000_branches.rb +66 -0
  75. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module.rb +110 -0
  76. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module_static.rb +113 -0
  77. data/integration/tests/user_scenario/basic_workflow/multi_env_hiera.rb +93 -0
  78. data/integration/tests/user_scenario/basic_workflow/multi_env_multi_source.rb +132 -0
  79. data/integration/tests/user_scenario/basic_workflow/multi_source_custom_forge_git_module.rb +160 -0
  80. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_basedir.rb +45 -0
  81. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_forge_module.rb +43 -0
  82. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module.rb +40 -0
  83. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module_ref.rb +42 -0
  84. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_remote.rb +44 -0
  85. data/integration/tests/user_scenario/basic_workflow/negative/neg_branch_name_collision.rb +63 -0
  86. data/integration/tests/user_scenario/basic_workflow/negative/neg_disk_full.rb +73 -0
  87. data/integration/tests/user_scenario/basic_workflow/negative/neg_duplicate_module_names.rb +45 -0
  88. data/integration/tests/user_scenario/basic_workflow/negative/neg_inaccessible_forge.rb +51 -0
  89. data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_env_name.rb +33 -0
  90. data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_puppet_file.rb +35 -0
  91. data/integration/tests/user_scenario/basic_workflow/negative/neg_module_specified_at_deleted_release.rb +44 -0
  92. data/integration/tests/user_scenario/basic_workflow/negative/neg_read_only.rb +57 -0
  93. data/integration/tests/user_scenario/basic_workflow/negative/neg_specify_deleted_forge_module.rb +44 -0
  94. data/integration/tests/user_scenario/basic_workflow/single_env_10000_files.rb +73 -0
  95. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_git_module.rb +103 -0
  96. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_module.rb +80 -0
  97. data/integration/tests/user_scenario/basic_workflow/single_env_custom_module.rb +48 -0
  98. data/integration/tests/user_scenario/basic_workflow/single_env_large_files.rb +73 -0
  99. data/integration/tests/user_scenario/basic_workflow/single_env_module_already_installed.rb +81 -0
  100. data/integration/tests/user_scenario/basic_workflow/single_env_module_last_release_deleted.rb +67 -0
  101. data/integration/tests/user_scenario/basic_workflow/single_env_non-existent_base_dir.rb +93 -0
  102. data/integration/tests/user_scenario/basic_workflow/single_env_purge_unmanaged_modules.rb +92 -0
  103. data/integration/tests/user_scenario/basic_workflow/single_env_switch_forge_git_module.rb +116 -0
  104. data/integration/tests/user_scenario/basic_workflow/single_env_unicode_paths.rb +59 -0
  105. data/integration/tests/user_scenario/basic_workflow/single_env_upgrade_forge_mod_revert_change.rb +165 -0
  106. data/integration/tests/user_scenario/complex_workflow/multi_env_add_change_remove.rb +162 -0
  107. data/integration/tests/user_scenario/complex_workflow/multi_env_remove_re-add.rb +110 -0
  108. data/lib/r10k/action/cri_runner.rb +10 -13
  109. data/lib/r10k/cli.rb +3 -8
  110. data/lib/r10k/cli/version.rb +10 -1
  111. data/lib/r10k/deployment/config.rb +26 -6
  112. data/lib/r10k/deployment/config/loader.rb +38 -29
  113. data/lib/r10k/deployment/source.rb +2 -4
  114. data/lib/r10k/environment/git.rb +10 -19
  115. data/lib/r10k/environment/name.rb +86 -0
  116. data/lib/r10k/errors.rb +8 -5
  117. data/lib/r10k/feature.rb +35 -0
  118. data/lib/r10k/feature/collection.rb +23 -0
  119. data/lib/r10k/features.rb +18 -0
  120. data/lib/r10k/git.rb +106 -12
  121. data/lib/r10k/git/alternates.rb +2 -2
  122. data/lib/r10k/git/cache.rb +43 -26
  123. data/lib/r10k/git/errors.rb +12 -6
  124. data/lib/r10k/git/head.rb +3 -0
  125. data/lib/r10k/git/ref.rb +3 -0
  126. data/lib/r10k/git/remote_head.rb +6 -0
  127. data/lib/r10k/git/repository.rb +6 -0
  128. data/lib/r10k/git/rugged.rb +17 -0
  129. data/lib/r10k/git/rugged/bare_repository.rb +86 -0
  130. data/lib/r10k/git/rugged/base_repository.rb +90 -0
  131. data/lib/r10k/git/rugged/cache.rb +11 -0
  132. data/lib/r10k/git/rugged/thin_repository.rb +72 -0
  133. data/lib/r10k/git/rugged/working_repository.rb +99 -0
  134. data/lib/r10k/git/shellgit.rb +9 -0
  135. data/lib/r10k/git/shellgit/bare_repository.rb +29 -0
  136. data/lib/r10k/git/shellgit/base_repository.rb +102 -0
  137. data/lib/r10k/git/shellgit/cache.rb +11 -0
  138. data/lib/r10k/git/shellgit/thin_repository.rb +56 -0
  139. data/lib/r10k/git/shellgit/working_repository.rb +73 -0
  140. data/lib/r10k/git/stateful_repository.rb +80 -0
  141. data/lib/r10k/git/tag.rb +3 -0
  142. data/lib/r10k/git/working_dir.rb +15 -2
  143. data/lib/r10k/logging.rb +73 -36
  144. data/lib/r10k/logging/terminaloutputter.rb +36 -0
  145. data/lib/r10k/module/forge.rb +10 -9
  146. data/lib/r10k/module/git.rb +14 -44
  147. data/lib/r10k/module/metadata_file.rb +31 -0
  148. data/lib/r10k/module/svn.rb +0 -1
  149. data/lib/r10k/module_repository/forge.rb +20 -7
  150. data/lib/r10k/puppetfile.rb +1 -1
  151. data/lib/r10k/settings/container.rb +6 -0
  152. data/lib/r10k/settings/mixin.rb +9 -0
  153. data/lib/r10k/source.rb +2 -3
  154. data/lib/r10k/source/base.rb +5 -5
  155. data/lib/r10k/source/git.rb +11 -86
  156. data/lib/r10k/source/svn.rb +8 -52
  157. data/lib/r10k/util/basedir.rb +4 -4
  158. data/lib/r10k/util/commands.rb +31 -0
  159. data/lib/r10k/util/exec_env.rb +36 -0
  160. data/lib/r10k/util/platform.rb +4 -0
  161. data/lib/r10k/util/purgeable.rb +2 -2
  162. data/lib/r10k/util/subprocess.rb +3 -7
  163. data/lib/r10k/util/subprocess/runner.rb +3 -28
  164. data/lib/r10k/util/subprocess/runner/posix.rb +103 -0
  165. data/lib/r10k/util/subprocess/runner/pump.rb +59 -0
  166. data/lib/r10k/util/subprocess/{windows/runner.rb → runner/windows.rb} +2 -11
  167. data/lib/r10k/util/symbolize_keys.rb +31 -0
  168. data/lib/r10k/version.rb +1 -1
  169. data/lib/shared/puppet/module_tool/metadata.rb +197 -0
  170. data/r10k.gemspec +7 -5
  171. data/spec/fixtures/integration/git/puppet-boolean-bare.tar +0 -0
  172. data/spec/fixtures/module/forge/bad_module/metadata.json +1 -0
  173. data/spec/fixtures/unit/util/subprocess/posix/runner/no-execute.sh +3 -0
  174. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/and_the_expected_version_is_latest/can_fetch_all_versions_of_a_given_module.yml +171 -26
  175. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/and_the_expected_version_is_latest/can_fetch_the_latest_version_of_a_given_module.yml +171 -26
  176. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/and_the_expected_version_is_latest/ignores_deleted_releases.yml +190 -0
  177. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/it_handles_errors_from_forgeapi_puppetlabs_com/raises_an_error_for_a_non-existant_module.yml +34 -0
  178. data/spec/fixtures/vcr/cassettes/R10K_Module_Forge/and_the_expected_version_is_latest/sets_the_expected_version_based_on_the_latest_forge_version.yml +87 -26
  179. data/spec/integration/git/rugged/bare_repository_spec.rb +13 -0
  180. data/spec/integration/git/rugged/thin_repository_spec.rb +14 -0
  181. data/spec/integration/git/rugged/working_repository_spec.rb +13 -0
  182. data/spec/integration/git/shellgit/bare_repository_spec.rb +13 -0
  183. data/spec/integration/git/shellgit/thin_repository_spec.rb +14 -0
  184. data/spec/integration/git/shellgit/working_repository_spec.rb +13 -0
  185. data/spec/integration/git/stateful_repository_spec.rb +104 -0
  186. data/spec/matchers/match_realpath.rb +18 -0
  187. data/spec/shared-contexts/git-fixtures.rb +55 -0
  188. data/spec/shared-examples/git-repository.rb +38 -0
  189. data/spec/shared-examples/git/bare_repository.rb +70 -0
  190. data/spec/shared-examples/git/thin_repository.rb +26 -0
  191. data/spec/shared-examples/git/working_repository.rb +115 -0
  192. data/spec/shared-examples/subprocess-runner.rb +83 -0
  193. data/spec/spec_helper.rb +13 -9
  194. data/spec/unit/action/cri_runner_spec.rb +0 -6
  195. data/spec/unit/action/puppetfile/{cri_action_spec.rb → cri_runner_spec.rb} +0 -0
  196. data/spec/unit/deployment/config/loader_spec.rb +48 -0
  197. data/spec/unit/deployment/config_spec.rb +49 -0
  198. data/spec/unit/environment/git_spec.rb +5 -39
  199. data/spec/unit/environment/name_spec.rb +135 -0
  200. data/spec/unit/feature_spec.rb +50 -0
  201. data/spec/unit/git/alternates_spec.rb +1 -1
  202. data/spec/unit/git/cache_spec.rb +32 -19
  203. data/spec/unit/git/commit_spec.rb +1 -0
  204. data/spec/unit/git/head_spec.rb +1 -6
  205. data/spec/unit/git/ref_spec.rb +0 -23
  206. data/spec/unit/git/rugged/cache_spec.rb +26 -0
  207. data/spec/unit/git/shellgit/cache_spec.rb +27 -0
  208. data/spec/unit/git/stateful_repository_spec.rb +43 -0
  209. data/spec/unit/git/tag_spec.rb +1 -0
  210. data/spec/unit/git/working_dir_spec.rb +1 -0
  211. data/spec/unit/git_spec.rb +74 -0
  212. data/spec/unit/logging/terminaloutputter_spec.rb +53 -0
  213. data/spec/unit/logging_spec.rb +68 -0
  214. data/spec/unit/module/forge_spec.rb +7 -38
  215. data/spec/unit/module/git_spec.rb +7 -38
  216. data/spec/unit/module/metadata_file_spec.rb +69 -0
  217. data/spec/unit/module/svn_spec.rb +0 -4
  218. data/spec/unit/module_repository/forge_spec.rb +22 -1
  219. data/spec/unit/puppet/module_tool/metadata_spec.rb +301 -0
  220. data/spec/unit/settings/container_spec.rb +17 -0
  221. data/spec/unit/source/git_spec.rb +0 -123
  222. data/spec/unit/source/svn_spec.rb +66 -0
  223. data/spec/unit/util/commands_spec.rb +61 -0
  224. data/spec/unit/util/exec_env_spec.rb +56 -0
  225. data/spec/unit/util/subprocess/runner/posix_spec.rb +7 -0
  226. data/spec/unit/util/subprocess/runner/pump_spec.rb +79 -0
  227. data/spec/unit/util/subprocess_spec.rb +3 -2
  228. data/spec/unit/util/symbolize_keys_spec.rb +51 -0
  229. metadata +226 -45
  230. data/lib/r10k/execution.rb +0 -47
  231. data/lib/r10k/module/metadata.rb +0 -47
  232. data/lib/r10k/util/core_ext/hash_ext.rb +0 -19
  233. data/lib/r10k/util/subprocess/io.rb +0 -7
  234. data/lib/r10k/util/subprocess/posix.rb +0 -4
  235. data/lib/r10k/util/subprocess/posix/io.rb +0 -7
  236. data/lib/r10k/util/subprocess/posix/runner.rb +0 -140
  237. data/lib/r10k/util/subprocess/windows.rb +0 -4
  238. data/lib/r10k/util/subprocess/windows/io.rb +0 -6
  239. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions.yml +0 -42
  240. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions/can_fetch_all_versions_of_a_given_module.yml +0 -42
  241. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions/can_fetch_the_latest_version_of_a_given_module.yml +0 -42
  242. data/spec/unit/deployment/source_spec.rb +0 -24
  243. data/spec/unit/module/metadata_spec.rb +0 -68
  244. data/spec/unit/util/core_ext/hash_ext_spec.rb +0 -63
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+ require 'r10k/git/rugged/bare_repository'
3
+
4
+ describe R10K::Git::Rugged::BareRepository, :if => R10K::Features.available?(:rugged) do
5
+ include_context 'Git integration'
6
+
7
+ let(:dirname) { 'bare-repo.git' }
8
+
9
+ subject { described_class.new(basedir, dirname) }
10
+
11
+ it_behaves_like 'a git repository'
12
+ it_behaves_like 'a git bare repository'
13
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'r10k/git/rugged/thin_repository'
3
+
4
+ describe R10K::Git::Rugged::ThinRepository, :if => R10K::Features.available?(:rugged) do
5
+ include_context 'Git integration'
6
+
7
+ let(:dirname) { 'working-repo' }
8
+
9
+ subject { described_class.new(basedir, dirname) }
10
+
11
+ let(:cacherepo) { R10K::Git::Rugged::Cache.generate(remote) }
12
+
13
+ it_behaves_like "a git thin repository"
14
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+ require 'r10k/git/rugged/working_repository'
3
+
4
+ describe R10K::Git::Rugged::WorkingRepository, :if => R10K::Features.available?(:rugged) do
5
+ include_context 'Git integration'
6
+
7
+ let(:dirname) { 'working-repo' }
8
+
9
+ subject { described_class.new(basedir, dirname) }
10
+
11
+ it_behaves_like 'a git repository'
12
+ it_behaves_like 'a git working repository'
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+ require 'r10k/git/shellgit/bare_repository'
3
+
4
+ describe R10K::Git::ShellGit::BareRepository do
5
+ include_context 'Git integration'
6
+
7
+ let(:dirname) { 'bare-repo.git' }
8
+
9
+ subject { described_class.new(basedir, dirname) }
10
+
11
+ it_behaves_like 'a git repository'
12
+ it_behaves_like 'a git bare repository'
13
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'r10k/git/shellgit/thin_repository'
3
+
4
+ describe R10K::Git::ShellGit::ThinRepository do
5
+ include_context 'Git integration'
6
+
7
+ let(:dirname) { 'working-repo' }
8
+
9
+ subject { described_class.new(basedir, dirname) }
10
+
11
+ let(:cacherepo) { R10K::Git::ShellGit::Cache.generate(remote) }
12
+
13
+ it_behaves_like "a git thin repository"
14
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+ require 'r10k/git/shellgit/working_repository'
3
+
4
+ describe R10K::Git::ShellGit::WorkingRepository do
5
+ include_context 'Git integration'
6
+
7
+ let(:dirname) { 'working-repo' }
8
+
9
+ subject { described_class.new(basedir, dirname) }
10
+
11
+ it_behaves_like 'a git repository'
12
+ it_behaves_like 'a git working repository'
13
+ end
@@ -0,0 +1,104 @@
1
+ require 'spec_helper'
2
+ require 'r10k/git'
3
+ require 'r10k/git/stateful_repository'
4
+
5
+ describe R10K::Git::StatefulRepository do
6
+ include_context 'Git integration'
7
+
8
+ let(:dirname) { 'working-repo' }
9
+
10
+ let(:thinrepo) { R10K::Git.thin_repository.new(basedir, dirname) }
11
+ let(:cacherepo) { R10K::Git.cache.generate(remote) }
12
+
13
+ subject { described_class.new('0.9.x', remote, basedir, dirname) }
14
+
15
+ describe 'status' do
16
+ describe "when the directory does not exist" do
17
+ it "is absent" do
18
+ expect(subject.status).to eq :absent
19
+ end
20
+ end
21
+
22
+ describe "when the directory is not a git repository" do
23
+ it "is mismatched" do
24
+ thinrepo.path.mkdir
25
+ expect(subject.status).to eq :mismatched
26
+ end
27
+ end
28
+
29
+ describe "when the repository doesn't match the desired remote" do
30
+ it "is mismatched" do
31
+ thinrepo.clone(remote, {:ref => '1.0.0'})
32
+ allow(subject.repo).to receive(:origin).and_return('http://some.site/repo.git')
33
+ expect(subject.status).to eq :mismatched
34
+ end
35
+ end
36
+
37
+ describe "when the wrong ref is checked out" do
38
+ it "is outdated" do
39
+ thinrepo.clone(remote, {:ref => '1.0.0'})
40
+ expect(subject.status).to eq :outdated
41
+ end
42
+ end
43
+
44
+ describe "when the ref is a branch and the cache is not synced" do
45
+ it "is outdated" do
46
+ thinrepo.clone(remote, {:ref => '0.9.x'})
47
+ cacherepo.reset!
48
+ expect(subject.status).to eq :outdated
49
+ end
50
+ end
51
+
52
+ describe "when the ref can't be resolved" do
53
+ subject { described_class.new('1.1.x', remote, basedir, dirname) }
54
+
55
+ it "is outdated" do
56
+ thinrepo.clone(remote, {:ref => '0.9.x'})
57
+ expect(subject.status).to eq :outdated
58
+ end
59
+ end
60
+
61
+ describe "if the right ref is checked out" do
62
+ it "is insync" do
63
+ thinrepo.clone(remote, {:ref => '0.9.x'})
64
+ expect(subject.status).to eq :insync
65
+ end
66
+ end
67
+ end
68
+
69
+ describe "syncing" do
70
+
71
+ describe "when the ref is unresolvable" do
72
+ subject { described_class.new('1.1.x', remote, basedir, dirname) }
73
+
74
+ it "raises an error" do
75
+ expect {
76
+ subject.sync
77
+ }.to raise_error(R10K::Git::UnresolvableRefError)
78
+ end
79
+ end
80
+
81
+ describe "when the repo is absent" do
82
+ it "creates the repo" do
83
+ subject.sync
84
+ expect(subject.status).to eq :insync
85
+ end
86
+ end
87
+
88
+ describe "when the repo is mismatched" do
89
+ it "removes and recreates the repo" do
90
+ thinrepo.path.mkdir
91
+ subject.sync
92
+ expect(subject.status).to eq :insync
93
+ end
94
+ end
95
+
96
+ describe "when the repo is out of date" do
97
+ it "updates the repository" do
98
+ thinrepo.clone(remote, {:ref => '1.0.0'})
99
+ subject.sync
100
+ expect(subject.status).to eq :insync
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,18 @@
1
+ RSpec::Matchers.define :match_realpath do |expected|
2
+
3
+ match do |actual|
4
+ actual == expected || realpath(actual) == realpath(expected)
5
+ end
6
+
7
+ failure_message do |actual|
8
+ "expected that #{actual} would have a real path of #{expected}"
9
+ end
10
+
11
+ failure_message_when_negated do |actual|
12
+ "expected that #{actual} would not have a real path of #{expected}"
13
+ end
14
+
15
+ def realpath(path)
16
+ Pathname.new(path).realpath.to_s
17
+ end
18
+ end
@@ -0,0 +1,55 @@
1
+ require 'archive/tar/minitar'
2
+ require 'tmpdir'
3
+
4
+ shared_context "Git integration" do
5
+
6
+ # Use tmpdir for cached git repositories
7
+
8
+ before(:all) do
9
+ @old_cache_root = R10K::Git::Cache.settings[:cache_root]
10
+ R10K::Git::Cache.settings[:cache_root] = Dir.mktmpdir
11
+ end
12
+
13
+ after(:all) do
14
+ FileUtils.remove_entry_secure(R10K::Git::Cache.settings[:cache_root])
15
+ R10K::Git::Cache.settings[:cache_root] = @old_cache_root
16
+ end
17
+
18
+ # Create a mutable path for remote repositories
19
+
20
+ def fixture_path
21
+ File.join(PROJECT_ROOT, 'spec', 'fixtures', 'integration', 'git')
22
+ end
23
+
24
+ def remote_path
25
+ @remote_path
26
+ end
27
+
28
+ def populate_remote_path
29
+ Archive::Tar::Minitar.unpack(File.join(fixture_path, 'puppet-boolean-bare.tar'), remote_path)
30
+ end
31
+
32
+ def clear_remote_path
33
+ FileUtils.remove_entry_secure(remote_path)
34
+ end
35
+
36
+ before(:all) do
37
+ @remote_path = Dir.mktmpdir
38
+ populate_remote_path
39
+ end
40
+
41
+ after(:all) do
42
+ clear_remote_path
43
+ @remote_path = nil
44
+ end
45
+
46
+ let(:remote) { Pathname.new(File.join(remote_path, 'puppet-boolean.git')).realpath.to_s }
47
+
48
+ # Create a temp path for the git basedir and clean it up when finished
49
+
50
+ let(:basedir) { Dir.mktmpdir }
51
+
52
+ after do
53
+ FileUtils.remove_entry_secure(basedir)
54
+ end
55
+ end
@@ -0,0 +1,38 @@
1
+ shared_examples_for "a git repository" do
2
+
3
+ it "does not exist if the repo is not present" do
4
+ expect(subject.exist?).to be_falsey
5
+ end
6
+
7
+ describe "listing tags" do
8
+ before do
9
+ subject.clone(remote)
10
+ end
11
+
12
+ it "lists all tags in alphabetical order" do
13
+ expect(subject.tags).to eq(%w[0.9.0 0.9.0-rc1 1.0.0 1.0.1])
14
+ end
15
+ end
16
+
17
+ describe "resolving refs" do
18
+ before do
19
+ subject.clone(remote)
20
+ end
21
+
22
+ it "can resolve branches" do
23
+ expect(subject.resolve('master')).to eq '157011a4eaa27f1202a9d94335ee4876b26d377e'
24
+ end
25
+
26
+ it "can resolve tags" do
27
+ expect(subject.resolve('1.0.0')).to eq '14cbb45ae3a5f764320b7e63f1a54a25a1ef6c9c'
28
+ end
29
+
30
+ it "can resolve commits" do
31
+ expect(subject.resolve('3084373e8d181cf2fea5b4ade2690ba22872bd67')).to eq '3084373e8d181cf2fea5b4ade2690ba22872bd67'
32
+ end
33
+
34
+ it "returns nil when the object cannot be resolved" do
35
+ expect(subject.resolve('1.2.3')).to be_nil
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,70 @@
1
+ RSpec.shared_examples "a git bare repository" do
2
+
3
+ describe "checking for the presence of the repo" do
4
+ it "exists if the repo is present" do
5
+ subject.clone(remote)
6
+ expect(subject.exist?).to be_truthy
7
+ end
8
+
9
+ it "doesn't exist if the repo is not present" do
10
+ expect(subject.exist?).to be_falsey
11
+ end
12
+ end
13
+
14
+ describe "cloning the repo" do
15
+ it "creates the repo at the expected location" do
16
+ subject.clone(remote)
17
+ config = File.read(File.join(basedir, dirname, 'config'))
18
+ expect(config).to match(remote)
19
+ end
20
+ end
21
+
22
+ describe "updating the repo" do
23
+ let(:tag_090) { subject.git_dir + 'refs' + 'tags' + '0.9.0' }
24
+ let(:packed_refs) { subject.git_dir + 'packed-refs' }
25
+
26
+ before do
27
+ subject.clone(remote)
28
+ tag_090.delete if tag_090.exist?
29
+ packed_refs.delete if packed_refs.exist?
30
+ end
31
+
32
+ it "fetches objects from the remote" do
33
+ expect(subject.tags).to_not include('0.9.0')
34
+ subject.fetch
35
+ expect(subject.tags).to include('0.9.0')
36
+ end
37
+ end
38
+
39
+ describe "listing branches" do
40
+ before do
41
+ subject.clone(remote)
42
+ end
43
+
44
+ it "lists all branches in alphabetical order" do
45
+ expect(subject.branches).to eq(%w[0.9.x master])
46
+ end
47
+ end
48
+
49
+ describe "determining ref type" do
50
+ before do
51
+ subject.clone(remote)
52
+ end
53
+
54
+ it "can infer the type of a branch ref" do
55
+ expect(subject.ref_type('master')).to eq :branch
56
+ end
57
+
58
+ it "can infer the type of a tag ref" do
59
+ expect(subject.ref_type('1.0.0')).to eq :tag
60
+ end
61
+
62
+ it "can infer the type of a commit" do
63
+ expect(subject.ref_type('3084373e8d181cf2fea5b4ade2690ba22872bd67')).to eq :commit
64
+ end
65
+
66
+ it "returns :unknown when the type cannot be inferred" do
67
+ expect(subject.ref_type('1.2.3')).to eq :unknown
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,26 @@
1
+ RSpec.shared_examples "a git thin repository" do
2
+ describe "cloning" do
3
+ it "creates a working copy of the repo" do
4
+ subject.clone(remote)
5
+ expect(subject.exist?).to be_truthy
6
+ end
7
+
8
+ it "sets the remote origin url to the provided url" do
9
+ subject.clone(remote)
10
+ expect(subject.origin).to eq remote
11
+ end
12
+
13
+ it "sets the remote cache url to the path to the cache repo" do
14
+ subject.clone(remote)
15
+ expect(subject.cache).to eq cacherepo.git_dir.to_s
16
+ end
17
+
18
+ it "adds the cache repo to the alternates file" do
19
+ subject.clone(remote)
20
+ objectpath = cacherepo.git_dir + 'objects'
21
+ alternates = subject.alternates.to_a
22
+ expect(alternates.size).to eq 1
23
+ expect(alternates[0]).to match_realpath objectpath
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,115 @@
1
+ RSpec.shared_examples "a git working repository" do
2
+ describe "cloning" do
3
+ it "creates a working copy of the repo" do
4
+ subject.clone(remote)
5
+ expect(subject.exist?).to be_truthy
6
+ end
7
+
8
+ describe "using the default branch" do
9
+ describe "and the remote HEAD is 'master'" do
10
+ it "checks out the default branch" do
11
+ subject.clone(remote)
12
+ expect(subject.head).to eq "157011a4eaa27f1202a9d94335ee4876b26d377e"
13
+ end
14
+ end
15
+
16
+ describe "and the remote HEAD is '0.9.x'" do
17
+ before do
18
+ File.open(File.join(remote, 'HEAD'), 'w') do |fh|
19
+ fh.write('ref: refs/heads/0.9.x')
20
+ end
21
+ end
22
+
23
+ after do
24
+ clear_remote_path
25
+ populate_remote_path
26
+ end
27
+
28
+ it "checks out the default branch" do
29
+ subject.clone(remote)
30
+ expect(subject.head).to eq "3084373e8d181cf2fea5b4ade2690ba22872bd67"
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "using an explicit ref" do
36
+ it "can check out tags" do
37
+ subject.clone(remote, {:ref => '1.0.0'})
38
+ expect(subject.head).to eq "14cbb45ae3a5f764320b7e63f1a54a25a1ef6c9c"
39
+ end
40
+
41
+ it "can check out remote branches" do
42
+ subject.clone(remote, {:ref => 'origin/0.9.x'})
43
+ expect(subject.head).to eq "3084373e8d181cf2fea5b4ade2690ba22872bd67"
44
+ end
45
+
46
+ it "can check out commits" do
47
+ subject.clone(remote, {:ref => '14cbb45ae3a5f764320b7e63f1a54a25a1ef6c9c'})
48
+ expect(subject.head).to eq "14cbb45ae3a5f764320b7e63f1a54a25a1ef6c9c"
49
+ end
50
+ end
51
+
52
+ describe "with a reference repository" do
53
+ it "adds the reference repository to the alternates directory" do
54
+ subject.clone(remote, {:reference => remote})
55
+ alternates = subject.alternates.to_a
56
+ expect(alternates.size).to eq 1
57
+ expect(alternates[0]).to match_realpath File.join(remote, 'objects')
58
+ end
59
+ end
60
+ end
61
+
62
+ describe "updating the repo" do
63
+ let(:tag_090) { subject.git_dir + 'refs' + 'tags' + '0.9.0' }
64
+ let(:packed_refs) { subject.git_dir + 'packed-refs' }
65
+
66
+ before do
67
+ subject.clone(remote)
68
+ tag_090.delete if tag_090.exist?
69
+ packed_refs.delete if packed_refs.exist?
70
+ end
71
+
72
+ it "fetches objects from the remote" do
73
+ subject.fetch
74
+ expect(subject.tags).to include('0.9.0')
75
+ end
76
+ end
77
+
78
+ describe "updating the repo" do
79
+ let(:tag_090) { subject.git_dir + 'refs' + 'tags' + '0.9.0' }
80
+ let(:packed_refs) { subject.git_dir + 'packed-refs' }
81
+
82
+ before do
83
+ subject.clone(remote)
84
+ tag_090.delete if tag_090.exist?
85
+ packed_refs.delete if packed_refs.exist?
86
+ end
87
+
88
+ it "fetches objects from the remote" do
89
+ expect(subject.tags).to_not include('0.9.0')
90
+ subject.fetch
91
+ expect(subject.tags).to include('0.9.0')
92
+ end
93
+ end
94
+
95
+ describe "listing branches" do
96
+ before do
97
+ subject.clone(remote)
98
+ end
99
+
100
+ it "lists the local branches" do
101
+ expect(subject.branches).to eq(%w[master])
102
+ end
103
+ end
104
+
105
+ describe "listing the origin" do
106
+ it "is nil if the remote is not set" do
107
+ expect(subject.origin).to be_nil
108
+ end
109
+
110
+ it "is the remote URL when set" do
111
+ subject.clone(remote)
112
+ expect(subject.origin).to eq remote
113
+ end
114
+ end
115
+ end