r10k 2.3.1 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.mkd +40 -13
- data/Gemfile +1 -2
- data/README.mkd +25 -0
- data/Rakefile +3 -0
- data/doc/dynamic-environments/configuration.mkd +91 -14
- data/doc/dynamic-environments/workflow-guide.mkd +3 -3
- data/doc/puppetfile.mkd +89 -40
- data/integration/Gemfile +2 -0
- data/integration/Rakefile +41 -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/user_scenario/basic_workflow/negative/neg_bad_git_module_ref.rb +1 -1
- data/lib/r10k.rb +8 -1
- data/lib/r10k/action/deploy/deploy_helpers.rb +3 -3
- data/lib/r10k/action/deploy/environment.rb +35 -14
- data/lib/r10k/action/deploy/module.rb +4 -4
- data/lib/r10k/action/puppetfile/check.rb +1 -1
- data/lib/r10k/action/puppetfile/install.rb +1 -1
- data/lib/r10k/action/runner.rb +3 -3
- data/lib/r10k/deployment.rb +8 -4
- data/lib/r10k/deployment/config.rb +1 -1
- data/lib/r10k/environment/base.rb +32 -3
- data/lib/r10k/environment/git.rb +19 -6
- data/lib/r10k/feature.rb +6 -6
- data/lib/r10k/forge/module_release.rb +4 -6
- data/lib/r10k/git.rb +7 -7
- data/lib/r10k/git/alternates.rb +1 -1
- data/lib/r10k/git/cache.rb +2 -2
- data/lib/r10k/git/rugged/bare_repository.rb +29 -9
- data/lib/r10k/git/rugged/credentials.rb +8 -8
- data/lib/r10k/git/rugged/thin_repository.rb +17 -3
- data/lib/r10k/git/rugged/working_repository.rb +12 -5
- data/lib/r10k/git/shellgit/thin_repository.rb +5 -1
- data/lib/r10k/git/shellgit/working_repository.rb +16 -2
- data/lib/r10k/git/stateful_repository.rb +33 -23
- data/lib/r10k/initializers.rb +1 -1
- data/lib/r10k/keyed_factory.rb +2 -2
- data/lib/r10k/logging.rb +1 -1
- data/lib/r10k/module.rb +4 -3
- data/lib/r10k/module/base.rb +3 -2
- data/lib/r10k/module/forge.rb +9 -4
- data/lib/r10k/module/git.rb +39 -22
- data/lib/r10k/module/local.rb +1 -1
- data/lib/r10k/module/metadata_file.rb +1 -1
- data/lib/r10k/module/svn.rb +3 -1
- data/lib/r10k/puppetfile.rb +72 -11
- data/lib/r10k/settings.rb +20 -0
- data/lib/r10k/settings/collection.rb +2 -2
- data/lib/r10k/settings/container.rb +1 -1
- data/lib/r10k/settings/enum_definition.rb +11 -3
- data/lib/r10k/settings/helpers.rb +2 -2
- data/lib/r10k/settings/list.rb +1 -1
- data/lib/r10k/settings/loader.rb +6 -6
- data/lib/r10k/settings/uri_definition.rb +1 -1
- data/lib/r10k/source/base.rb +2 -2
- data/lib/r10k/source/git.rb +4 -4
- data/lib/r10k/svn/working_dir.rb +1 -1
- data/lib/r10k/util/basedir.rb +9 -9
- data/lib/r10k/util/license.rb +3 -3
- data/lib/r10k/util/purgeable.rb +50 -24
- data/lib/r10k/util/setopts.rb +1 -1
- data/lib/r10k/util/subprocess.rb +3 -3
- data/lib/r10k/util/symbolize_keys.rb +1 -1
- data/lib/r10k/version.rb +1 -1
- data/locales/config.yaml +21 -0
- data/r10k.gemspec +3 -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/util/purgeable/managed_one/expected_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/unmanaged_1 +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/integration/git/stateful_repository_spec.rb +39 -21
- data/spec/r10k-mocks/mock_config.rb +4 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/unit/action/deploy/environment_spec.rb +71 -13
- data/spec/unit/environment/base_spec.rb +71 -0
- data/spec/unit/forge/module_release_spec.rb +7 -10
- data/spec/unit/git/stateful_repository_spec.rb +6 -6
- data/spec/unit/module/git_spec.rb +156 -5
- data/spec/unit/module_spec.rb +3 -3
- data/spec/unit/puppetfile_spec.rb +115 -0
- data/spec/unit/util/purgeable_spec.rb +230 -0
- metadata +45 -18
- data/integration/test_run_scripts/README.mkd +0 -5
- data/integration/test_run_scripts/all_tests-rugged-pe-centos6.sh +0 -20
- data/integration/test_run_scripts/all_tests-rugged-pe-rhel7.sh +0 -20
- data/integration/test_run_scripts/all_tests-rugged-pe-sles11.sh +0 -20
- data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1204.sh +0 -20
- data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1404.sh +0 -20
- data/integration/test_run_scripts/all_tests-shellgit-pe-centos6.sh +0 -20
- data/integration/test_run_scripts/all_tests-shellgit-pe-rhel7.sh +0 -20
- data/integration/test_run_scripts/all_tests-shellgit-pe-sles11.sh +0 -20
- data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1204.sh +0 -20
- data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1404.sh +0 -20
- data/integration/test_run_scripts/basic_functionality/all_tests-pe-centos6.sh +0 -20
- data/integration/test_run_scripts/command_line/all_tests-pe-centos6.sh +0 -20
- data/integration/test_run_scripts/git_source/all_tests-pe-centos6.sh +0 -20
- data/integration/test_run_scripts/user_scenario/basic_workflow/all_tests-pe-centos6.sh +0 -20
- data/integration/test_run_scripts/user_scenario/complex_workflow/all_tests-pe-centos6.sh +0 -20
@@ -25,7 +25,7 @@ class R10K::Git::Rugged::WorkingRepository < R10K::Git::Rugged::BaseRepository
|
|
25
25
|
#
|
26
26
|
# @return [void]
|
27
27
|
def clone(remote, opts = {})
|
28
|
-
logger.debug1 { "Cloning '
|
28
|
+
logger.debug1 { _("Cloning '%{remote}' into %{path}") % {remote: remote, path: @path } }
|
29
29
|
|
30
30
|
# libgit2/rugged doesn't support cloning a repository and providing an
|
31
31
|
# alternate object database, making the handling of :alternates a noop.
|
@@ -60,23 +60,26 @@ class R10K::Git::Rugged::WorkingRepository < R10K::Git::Rugged::BaseRepository
|
|
60
60
|
#
|
61
61
|
# @param ref [String] The git reference to check out
|
62
62
|
# @return [void]
|
63
|
-
def checkout(ref)
|
63
|
+
def checkout(ref, opts = {})
|
64
64
|
sha = resolve(ref)
|
65
65
|
|
66
66
|
if sha
|
67
|
-
logger.debug2 { "Checking out ref '
|
67
|
+
logger.debug2 { _("Checking out ref '%{ref}' (resolved to SHA '%{sha}') in repository %{path}") % {ref: ref, sha: sha, path: @path} }
|
68
68
|
else
|
69
69
|
raise R10K::Git::GitError.new("Unable to check out unresolvable ref '#{ref}'", git_dir: git_dir)
|
70
70
|
end
|
71
71
|
|
72
|
+
# :force defaults to true
|
73
|
+
force = !opts.has_key?(:force) || opts[:force]
|
74
|
+
|
72
75
|
with_repo do |repo|
|
73
76
|
repo.checkout(sha)
|
74
|
-
repo.reset(sha, :hard)
|
77
|
+
repo.reset(sha, :hard) if force
|
75
78
|
end
|
76
79
|
end
|
77
80
|
|
78
81
|
def fetch(remote_name = 'origin')
|
79
|
-
logger.debug1 { "Fetching remote '
|
82
|
+
logger.debug1 { _("Fetching remote '%{remote}' at %{path}") % {remote: remote_name, path: @path} }
|
80
83
|
options = {:credentials => credentials}
|
81
84
|
refspecs = ["+refs/heads/*:refs/remotes/#{remote_name}/*"]
|
82
85
|
|
@@ -109,6 +112,10 @@ class R10K::Git::Rugged::WorkingRepository < R10K::Git::Rugged::BaseRepository
|
|
109
112
|
with_repo { |repo| repo.config['remote.origin.url'] }
|
110
113
|
end
|
111
114
|
|
115
|
+
def dirty?
|
116
|
+
with_repo { |repo| repo.diff_workdir('HEAD').size > 0 }
|
117
|
+
end
|
118
|
+
|
112
119
|
private
|
113
120
|
|
114
121
|
def with_repo
|
@@ -39,6 +39,10 @@ class R10K::Git::ShellGit::ThinRepository < R10K::Git::ShellGit::WorkingReposito
|
|
39
39
|
git(['config', '--get', 'remote.cache.url'], :path => @path.to_s, :raise_on_fail => false).stdout
|
40
40
|
end
|
41
41
|
|
42
|
+
def tracked_paths(ref="HEAD")
|
43
|
+
git(['ls-tree', '-t', '-r', '--name-only', ref], :path => @path.to_s).stdout.split("\n")
|
44
|
+
end
|
45
|
+
|
42
46
|
private
|
43
47
|
|
44
48
|
def setup_cache_remote
|
@@ -58,7 +62,7 @@ class R10K::Git::ShellGit::ThinRepository < R10K::Git::ShellGit::WorkingReposito
|
|
58
62
|
if git_dir.exist?
|
59
63
|
entry_added = alternates.add?(@cache_repo.objects_dir.to_s)
|
60
64
|
if entry_added
|
61
|
-
logger.debug2 { "Updated repo
|
65
|
+
logger.debug2 { _("Updated repo %{path} to include alternate object db path %{objects_dir}") % {path: @path, objects_dir: @cache_repo.objects_dir} }
|
62
66
|
end
|
63
67
|
end
|
64
68
|
end
|
@@ -47,8 +47,16 @@ class R10K::Git::ShellGit::WorkingRepository < R10K::Git::ShellGit::BaseReposito
|
|
47
47
|
# Check out the given Git ref
|
48
48
|
#
|
49
49
|
# @param ref [String] The git reference to check out
|
50
|
-
|
51
|
-
|
50
|
+
# @param opts [Hash] Optional hash of additional options.
|
51
|
+
def checkout(ref, opts = {})
|
52
|
+
# :force defaults to true
|
53
|
+
if !opts.has_key?(:force) || opts[:force]
|
54
|
+
force_opt = '--force'
|
55
|
+
else
|
56
|
+
force_opt = ''
|
57
|
+
end
|
58
|
+
|
59
|
+
git ['checkout', ref, force_opt], :path => @path.to_s
|
52
60
|
end
|
53
61
|
|
54
62
|
def fetch(remote_name='origin')
|
@@ -80,4 +88,10 @@ class R10K::Git::ShellGit::WorkingRepository < R10K::Git::ShellGit::BaseReposito
|
|
80
88
|
result.stdout
|
81
89
|
end
|
82
90
|
end
|
91
|
+
|
92
|
+
# does the working tree have local modifications to tracked files?
|
93
|
+
def dirty?
|
94
|
+
result = git(['diff-index', '--quiet','HEAD', '--'], :path => @path.to_s, :raise_on_fail => false)
|
95
|
+
result.exit_code != 0
|
96
|
+
end
|
83
97
|
end
|
@@ -13,48 +13,56 @@ class R10K::Git::StatefulRepository
|
|
13
13
|
attr_reader :repo
|
14
14
|
|
15
15
|
extend Forwardable
|
16
|
-
def_delegators :@repo, :head
|
16
|
+
def_delegators :@repo, :head, :tracked_paths
|
17
17
|
|
18
18
|
# Create a new shallow git working directory
|
19
19
|
#
|
20
|
-
# @param ref [String] The git ref to check out
|
21
20
|
# @param remote [String] The git remote to use for the repo
|
22
21
|
# @param basedir [String] The path containing the Git repo
|
23
22
|
# @param dirname [String] The directory name of the Git repo
|
24
|
-
def initialize(
|
25
|
-
@ref = ref
|
23
|
+
def initialize(remote, basedir, dirname)
|
26
24
|
@remote = remote
|
27
|
-
|
28
|
-
@cache = R10K::Git.cache.generate(remote)
|
25
|
+
@cache = R10K::Git.cache.generate(@remote)
|
29
26
|
@repo = R10K::Git.thin_repository.new(basedir, dirname, @cache)
|
30
27
|
end
|
31
28
|
|
32
|
-
def
|
33
|
-
@cache.sync if sync_cache?
|
29
|
+
def resolve(ref)
|
30
|
+
@cache.sync if sync_cache?(ref)
|
31
|
+
@cache.resolve(ref)
|
32
|
+
end
|
33
|
+
|
34
|
+
def sync(ref)
|
35
|
+
@cache.sync if sync_cache?(ref)
|
34
36
|
|
35
|
-
sha = @cache.resolve(
|
37
|
+
sha = @cache.resolve(ref)
|
36
38
|
|
37
39
|
if sha.nil?
|
38
|
-
raise R10K::Git::UnresolvableRefError.new("Unable to sync repo to unresolvable ref '
|
40
|
+
raise R10K::Git::UnresolvableRefError.new(_("Unable to sync repo to unresolvable ref '%{ref}'") % {ref: ref}, :git_dir => @repo.git_dir)
|
39
41
|
end
|
40
42
|
|
41
|
-
|
43
|
+
workdir_status = status(ref)
|
44
|
+
|
45
|
+
case workdir_status
|
42
46
|
when :absent
|
43
|
-
logger.debug { "Cloning
|
47
|
+
logger.debug { _("Cloning %{repo_path} and checking out %{ref}") % {repo_path: @repo.path, ref: ref } }
|
44
48
|
@repo.clone(@remote, {:ref => sha})
|
45
49
|
when :mismatched
|
46
|
-
logger.debug { "Replacing
|
50
|
+
logger.debug { _("Replacing %{repo_path} and checking out %{ref}") % {repo_path: @repo.path, ref: ref } }
|
47
51
|
@repo.path.rmtree
|
48
52
|
@repo.clone(@remote, {:ref => sha})
|
49
|
-
when :outdated
|
50
|
-
|
51
|
-
|
53
|
+
when :outdated, :dirty
|
54
|
+
if workdir_status == :dirty
|
55
|
+
logger.warn { _("%{repo_path} has local modifications which will be overwritten") % {repo_path: @repo.path} }
|
56
|
+
end
|
57
|
+
|
58
|
+
logger.debug { _("Updating %{repo_path} to %{ref}") % {repo_path: @repo.path, ref: ref } }
|
59
|
+
@repo.checkout(sha, {:force => true})
|
52
60
|
else
|
53
|
-
logger.debug { "
|
61
|
+
logger.debug { _("%{repo_path} is already at Git ref %{ref}") % {repo_path: @repo.path, ref: ref } }
|
54
62
|
end
|
55
63
|
end
|
56
64
|
|
57
|
-
def status
|
65
|
+
def status(ref)
|
58
66
|
if !@repo.exist?
|
59
67
|
:absent
|
60
68
|
elsif !@repo.git_dir.exist?
|
@@ -63,20 +71,22 @@ class R10K::Git::StatefulRepository
|
|
63
71
|
:mismatched
|
64
72
|
elsif !(@repo.origin == @remote)
|
65
73
|
:mismatched
|
66
|
-
elsif !(@repo.head == @cache.resolve(
|
74
|
+
elsif !(@repo.head == @cache.resolve(ref))
|
67
75
|
:outdated
|
68
|
-
elsif @cache.ref_type(
|
76
|
+
elsif @cache.ref_type(ref) == :branch && !@cache.synced?
|
69
77
|
:outdated
|
78
|
+
elsif @repo.dirty?
|
79
|
+
:dirty
|
70
80
|
else
|
71
81
|
:insync
|
72
82
|
end
|
73
83
|
end
|
74
84
|
|
75
85
|
# @api private
|
76
|
-
def sync_cache?
|
86
|
+
def sync_cache?(ref)
|
77
87
|
return true if !@cache.exist?
|
78
|
-
return true if !@cache.resolve(
|
79
|
-
return true if !([:commit, :tag].include? @cache.ref_type(
|
88
|
+
return true if !@cache.resolve(ref)
|
89
|
+
return true if !([:commit, :tag].include? @cache.ref_type(ref))
|
80
90
|
return false
|
81
91
|
end
|
82
92
|
end
|
data/lib/r10k/initializers.rb
CHANGED
@@ -27,7 +27,7 @@ module R10K
|
|
27
27
|
class GlobalInitializer < BaseInitializer
|
28
28
|
def call
|
29
29
|
with_setting(:purgedirs) do |_|
|
30
|
-
logger.warn("the purgedirs key in r10k.yaml is deprecated. it is currently ignored.")
|
30
|
+
logger.warn(_("the purgedirs key in r10k.yaml is deprecated. it is currently ignored."))
|
31
31
|
end
|
32
32
|
|
33
33
|
with_setting(:cachedir) { |value| R10K::Git::Cache.settings[:cache_root] = value }
|
data/lib/r10k/keyed_factory.rb
CHANGED
@@ -15,7 +15,7 @@ module R10K
|
|
15
15
|
|
16
16
|
def register(key, klass)
|
17
17
|
if @implementations.has_key?(key)
|
18
|
-
raise DuplicateImplementationError, "Class already registered for
|
18
|
+
raise DuplicateImplementationError, _("Class already registered for %{key}") % {key: key}
|
19
19
|
else
|
20
20
|
@implementations[key] = klass
|
21
21
|
end
|
@@ -29,7 +29,7 @@ module R10K
|
|
29
29
|
if (impl = @implementations[key])
|
30
30
|
impl.new(*args)
|
31
31
|
else
|
32
|
-
raise UnknownImplementationError, "No class registered for
|
32
|
+
raise UnknownImplementationError, _("No class registered for %{key}") % {key: key}
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
data/lib/r10k/logging.rb
CHANGED
@@ -57,7 +57,7 @@ module R10K::Logging
|
|
57
57
|
def level=(val)
|
58
58
|
level = parse_level(val)
|
59
59
|
if level.nil?
|
60
|
-
raise ArgumentError, "Invalid log level '
|
60
|
+
raise ArgumentError, _("Invalid log level '%{val}'. Valid levels are %{log_levels}") % {val: val, log_levels: LOG_LEVELS.map(&:downcase).inspect}
|
61
61
|
end
|
62
62
|
outputter.level = level
|
63
63
|
@level = level
|
data/lib/r10k/module.rb
CHANGED
@@ -18,14 +18,15 @@ module R10K::Module
|
|
18
18
|
# @param [String] name The unique name of the module
|
19
19
|
# @param [String] basedir The root to install the module in
|
20
20
|
# @param [Object] args An arbitary value or set of values that specifies the implementation
|
21
|
+
# @param [R10K::Environment] environment Optional environment that this module is a part of
|
21
22
|
#
|
22
23
|
# @return [Object < R10K::Module] A member of the implementing subclass
|
23
|
-
def self.new(name, basedir, args)
|
24
|
+
def self.new(name, basedir, args, environment=nil)
|
24
25
|
if implementation = @klasses.find { |klass| klass.implement?(name, args) }
|
25
|
-
obj = implementation.new(name, basedir, args)
|
26
|
+
obj = implementation.new(name, basedir, args, environment)
|
26
27
|
obj
|
27
28
|
else
|
28
|
-
raise "Module
|
29
|
+
raise _("Module %{name} with args %{args} doesn't have an implementation. (Are you using the right arguments?)") % {name: name, args: args.inspect}
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
data/lib/r10k/module/base.rb
CHANGED
@@ -36,12 +36,13 @@ class R10K::Module::Base
|
|
36
36
|
# @param title [String]
|
37
37
|
# @param dirname [String]
|
38
38
|
# @param args [Array]
|
39
|
-
def initialize(title, dirname, args)
|
39
|
+
def initialize(title, dirname, args, environment=nil)
|
40
40
|
@title = PuppetForge::V3.normalize_name(title)
|
41
41
|
@dirname = dirname
|
42
42
|
@args = args
|
43
43
|
@owner, @name = parse_title(@title)
|
44
44
|
@path = Pathname.new(File.join(@dirname, @name))
|
45
|
+
@environment = environment
|
45
46
|
end
|
46
47
|
|
47
48
|
# @deprecated
|
@@ -97,7 +98,7 @@ class R10K::Module::Base
|
|
97
98
|
elsif (match = title.match(/\A(\w+)[-\/](\w+)\Z/))
|
98
99
|
[match[1], match[2]]
|
99
100
|
else
|
100
|
-
raise ArgumentError, "Module name (
|
101
|
+
raise ArgumentError, _("Module name (%{title}) must match either 'modulename' or 'owner/modulename'") % {title: title}
|
101
102
|
end
|
102
103
|
end
|
103
104
|
end
|
data/lib/r10k/module/forge.rb
CHANGED
@@ -13,7 +13,11 @@ class R10K::Module::Forge < R10K::Module::Base
|
|
13
13
|
R10K::Module.register(self)
|
14
14
|
|
15
15
|
def self.implement?(name, args)
|
16
|
-
!!(name.match %r[\w+[/-]\w+])
|
16
|
+
!!(name.match %r[\w+[/-]\w+]) && valid_version?(args)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.valid_version?(expected_version)
|
20
|
+
expected_version == :latest || expected_version.nil? || SemanticPuppet::Version.valid?(expected_version)
|
17
21
|
end
|
18
22
|
|
19
23
|
# @!attribute [r] metadata
|
@@ -28,8 +32,9 @@ class R10K::Module::Forge < R10K::Module::Base
|
|
28
32
|
|
29
33
|
include R10K::Logging
|
30
34
|
|
31
|
-
def initialize(title, dirname, expected_version)
|
35
|
+
def initialize(title, dirname, expected_version, environment=nil)
|
32
36
|
super
|
37
|
+
|
33
38
|
@metadata_file = R10K::Module::MetadataFile.new(path + 'metadata.json')
|
34
39
|
@metadata = @metadata_file.read
|
35
40
|
|
@@ -62,7 +67,7 @@ class R10K::Module::Forge < R10K::Module::Base
|
|
62
67
|
begin
|
63
68
|
@expected_version = @v3_module.current_release.version
|
64
69
|
rescue Faraday::ResourceNotFound => e
|
65
|
-
raise PuppetForge::ReleaseNotFound, "The module
|
70
|
+
raise PuppetForge::ReleaseNotFound, _("The module %{title} does not exist on %{url}.") % {title: @title, url: PuppetForge::V3::Release.conn.url_prefix}, e.backtrace
|
66
71
|
end
|
67
72
|
end
|
68
73
|
@expected_version
|
@@ -150,7 +155,7 @@ class R10K::Module::Forge < R10K::Module::Base
|
|
150
155
|
if (match = title.match(/\A(\w+)[-\/](\w+)\Z/))
|
151
156
|
[match[1], match[2]]
|
152
157
|
else
|
153
|
-
raise ArgumentError, "Forge module names must match 'owner/modulename'"
|
158
|
+
raise ArgumentError, _("Forge module names must match 'owner/modulename'")
|
154
159
|
end
|
155
160
|
end
|
156
161
|
end
|
data/lib/r10k/module/git.rb
CHANGED
@@ -18,53 +18,70 @@ class R10K::Module::Git < R10K::Module::Base
|
|
18
18
|
# @return [R10K::Git::StatefulRepository]
|
19
19
|
attr_reader :repo
|
20
20
|
|
21
|
-
def initialize(title, dirname, args)
|
21
|
+
def initialize(title, dirname, args, environment=nil)
|
22
22
|
super
|
23
|
+
|
23
24
|
parse_options(@args)
|
24
|
-
|
25
|
+
|
26
|
+
@repo = R10K::Git::StatefulRepository.new(@remote, @dirname, @name)
|
25
27
|
end
|
26
28
|
|
27
29
|
def version
|
28
|
-
@
|
30
|
+
validate_ref(@desired_ref, @default_ref)
|
29
31
|
end
|
30
32
|
|
31
33
|
def properties
|
32
34
|
{
|
33
|
-
:expected =>
|
35
|
+
:expected => version,
|
34
36
|
:actual => (@repo.head || "(unresolvable)"),
|
35
37
|
:type => :git,
|
36
38
|
}
|
37
39
|
end
|
38
40
|
|
39
|
-
|
41
|
+
def sync
|
42
|
+
@repo.sync(version)
|
43
|
+
end
|
40
44
|
|
41
|
-
|
45
|
+
def status
|
46
|
+
@repo.status(version)
|
47
|
+
end
|
42
48
|
|
43
49
|
private
|
44
50
|
|
45
|
-
def
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
51
|
+
def validate_ref(desired, default)
|
52
|
+
if desired && @repo.resolve(desired)
|
53
|
+
return desired
|
54
|
+
elsif default && @repo.resolve(default)
|
55
|
+
return default
|
56
|
+
else
|
57
|
+
if default
|
58
|
+
raise ArgumentError, _("Unable to manage Puppetfile content '%{name}': Could not resolve desired ref '%{desired}' or default ref '%{default}'") % {name: @name, desired: desired, default: default}
|
59
|
+
else
|
60
|
+
raise ArgumentError, _("Unable to manage Puppetfile content '%{name}': Could not resolve desired ref '%{desired}' and no default given") % {name: @name, desired: desired}
|
61
|
+
end
|
50
62
|
end
|
63
|
+
end
|
51
64
|
|
52
|
-
|
53
|
-
|
54
|
-
|
65
|
+
def parse_options(options)
|
66
|
+
ref_opts = [:branch, :tag, :commit, :ref]
|
67
|
+
known_opts = [:git, :default_branch] + ref_opts
|
55
68
|
|
56
|
-
|
57
|
-
|
69
|
+
unhandled = options.keys - known_opts
|
70
|
+
unless unhandled.empty?
|
71
|
+
raise ArgumentError, _("Unhandled options %{unhandled} specified for %{class}") % {unhandled: unhandled, class: self.class}
|
58
72
|
end
|
59
73
|
|
60
|
-
|
61
|
-
@ref = options.delete(:ref)
|
62
|
-
end
|
74
|
+
@remote = options[:git]
|
63
75
|
|
64
|
-
@
|
76
|
+
@desired_ref = ref_opts.find { |key| break options[key] if options.has_key?(key) } || 'master'
|
77
|
+
@default_ref = options[:default_branch]
|
65
78
|
|
66
|
-
|
67
|
-
|
79
|
+
if @desired_ref == :control_branch
|
80
|
+
if @environment && @environment.respond_to?(:ref)
|
81
|
+
@desired_ref = @environment.ref
|
82
|
+
else
|
83
|
+
raise ArgumentError, _("Cannot track control repo branch from Puppetfile in this context: environment is nil or did not provide a valid ref")
|
84
|
+
end
|
68
85
|
end
|
69
86
|
end
|
70
87
|
end
|
data/lib/r10k/module/local.rb
CHANGED
@@ -22,7 +22,7 @@ class R10K::Module::MetadataFile
|
|
22
22
|
metadata = PuppetForge::Metadata.new
|
23
23
|
metadata.update(JSON.load(f), false)
|
24
24
|
rescue JSON::ParserError => e
|
25
|
-
exception = R10K::Error.wrap(e, "Could not read metadata.json")
|
25
|
+
exception = R10K::Error.wrap(e, _("Could not read metadata.json"))
|
26
26
|
raise exception
|
27
27
|
end
|
28
28
|
end
|
data/lib/r10k/module/svn.rb
CHANGED
@@ -44,9 +44,11 @@ class R10K::Module::SVN < R10K::Module::Base
|
|
44
44
|
:password => :self
|
45
45
|
}
|
46
46
|
|
47
|
-
def initialize(name, dirname, opts)
|
47
|
+
def initialize(name, dirname, opts, environment=nil)
|
48
48
|
super
|
49
|
+
|
49
50
|
setopts(opts, INITIALIZE_OPTS)
|
51
|
+
|
50
52
|
@working_dir = R10K::SVN::WorkingDir.new(@path, :username => @username, :password => @password)
|
51
53
|
end
|
52
54
|
|