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
data/lib/r10k/action/runner.rb
CHANGED
@@ -46,7 +46,7 @@ module R10K
|
|
46
46
|
overrides.delete_if { |_, val| val.nil? }
|
47
47
|
|
48
48
|
with_overrides = config_settings.merge(overrides) do |key, oldval, newval|
|
49
|
-
logger.debug2 "Overriding config file setting '
|
49
|
+
logger.debug2 _("Overriding config file setting '%{key}': '%{old_val}' -> '%{new_val}'") % {key: key, old_val: oldval, new_val: newval}
|
50
50
|
newval
|
51
51
|
end
|
52
52
|
|
@@ -79,10 +79,10 @@ module R10K
|
|
79
79
|
|
80
80
|
if path
|
81
81
|
@opts[:config] = path
|
82
|
-
logger.debug2 "Reading configuration from
|
82
|
+
logger.debug2 _("Reading configuration from %{config_path}") % {config_path: path.inspect}
|
83
83
|
results = loader.read(path)
|
84
84
|
else
|
85
|
-
logger.debug2 "No config file explicitly given and no default config file could be found, default settings will be used."
|
85
|
+
logger.debug2 _("No config file explicitly given and no default config file could be found, default settings will be used.")
|
86
86
|
end
|
87
87
|
|
88
88
|
results
|
data/lib/r10k/deployment.rb
CHANGED
@@ -87,9 +87,13 @@ module R10K
|
|
87
87
|
source.environments.each do |environment|
|
88
88
|
if hash.key?(environment.path)
|
89
89
|
osource, oenvironment = hash[environment.path]
|
90
|
-
msg = ""
|
91
|
-
|
92
|
-
|
90
|
+
msg = _("Environment collision at %{env_path} between %{source}:%{env_name} and %{osource}:%{oenv_name}") %
|
91
|
+
{env_path: environment.path,
|
92
|
+
source: source.name,
|
93
|
+
env_name: environment.name,
|
94
|
+
osource: osource.name,
|
95
|
+
oenv_name: oenvironment.name}
|
96
|
+
|
93
97
|
raise R10K::Error, msg
|
94
98
|
else
|
95
99
|
hash[environment.path] = [source, environment]
|
@@ -111,7 +115,7 @@ module R10K
|
|
111
115
|
def load_sources
|
112
116
|
sources = @config[:sources]
|
113
117
|
if sources.nil? || sources.empty?
|
114
|
-
raise R10K::Error, "Unable to load sources; the supplied configuration does not define the 'sources' key"
|
118
|
+
raise R10K::Error, _("Unable to load sources; the supplied configuration does not define the 'sources' key")
|
115
119
|
end
|
116
120
|
@_sources = sources.map do |(name, hash)|
|
117
121
|
R10K::Source.from_hash(name, hash)
|
@@ -39,7 +39,7 @@ class Config
|
|
39
39
|
hash = loader.read(@configfile)
|
40
40
|
|
41
41
|
with_overrides = hash.merge(@overrides) do |key, oldval, newval|
|
42
|
-
logger.debug2 "Overriding config file setting '
|
42
|
+
logger.debug2 _("Overriding config file setting '%{key}': '%{old_val}' -> '%{new_val}'") % {key: key, old_val: oldval, new_val: newval}
|
43
43
|
newval
|
44
44
|
end
|
45
45
|
|
@@ -39,7 +39,9 @@ class R10K::Environment::Base
|
|
39
39
|
|
40
40
|
@full_path = File.join(@basedir, @dirname)
|
41
41
|
@path = Pathname.new(File.join(@basedir, @dirname))
|
42
|
+
|
42
43
|
@puppetfile = R10K::Puppetfile.new(@full_path)
|
44
|
+
@puppetfile.environment = self
|
43
45
|
end
|
44
46
|
|
45
47
|
# Synchronize the given environment.
|
@@ -48,7 +50,7 @@ class R10K::Environment::Base
|
|
48
50
|
# @abstract
|
49
51
|
# @return [void]
|
50
52
|
def sync
|
51
|
-
raise NotImplementedError, "
|
53
|
+
raise NotImplementedError, _("%{class} has not implemented method %{method}") % {class: self.class, method: __method__}
|
52
54
|
end
|
53
55
|
|
54
56
|
# Determine the current status of the environment.
|
@@ -64,7 +66,7 @@ class R10K::Environment::Base
|
|
64
66
|
# @abstract
|
65
67
|
# @return [Symbol]
|
66
68
|
def status
|
67
|
-
raise NotImplementedError, "
|
69
|
+
raise NotImplementedError, _("%{class} has not implemented method %{method}") % {class: self.class, method: __method__}
|
68
70
|
end
|
69
71
|
|
70
72
|
# Returns a unique identifier for the environment's current state.
|
@@ -73,7 +75,7 @@ class R10K::Environment::Base
|
|
73
75
|
# @abstract
|
74
76
|
# @return [String]
|
75
77
|
def signature
|
76
|
-
raise NotImplementedError, "
|
78
|
+
raise NotImplementedError, _("%{class} has not implemented method %{method}") %{class: self.class, method: __method__}
|
77
79
|
end
|
78
80
|
|
79
81
|
# Returns a hash describing the current state of the environment.
|
@@ -98,4 +100,31 @@ class R10K::Environment::Base
|
|
98
100
|
puppetfile.accept(visitor)
|
99
101
|
end
|
100
102
|
end
|
103
|
+
|
104
|
+
def whitelist(user_whitelist=[])
|
105
|
+
user_whitelist.collect { |pattern| File.join(@full_path, pattern) }
|
106
|
+
end
|
107
|
+
|
108
|
+
def purge_exclusions
|
109
|
+
list = [File.join(@full_path, '.r10k-deploy.json')].to_set
|
110
|
+
|
111
|
+
list += @puppetfile.managed_directories
|
112
|
+
|
113
|
+
list += @puppetfile.desired_contents.flat_map do |item|
|
114
|
+
desired_tree = []
|
115
|
+
|
116
|
+
if File.directory?(item)
|
117
|
+
desired_tree << File.join(item, '**', '*')
|
118
|
+
end
|
119
|
+
|
120
|
+
Pathname.new(item).ascend do |path|
|
121
|
+
break if path.to_s == @full_path
|
122
|
+
desired_tree << path.to_s
|
123
|
+
end
|
124
|
+
|
125
|
+
desired_tree
|
126
|
+
end
|
127
|
+
|
128
|
+
list.to_a
|
129
|
+
end
|
101
130
|
end
|
data/lib/r10k/environment/git.rb
CHANGED
@@ -23,7 +23,7 @@ class R10K::Environment::Git < R10K::Environment::Base
|
|
23
23
|
# @return [R10K::Git::StatefulRepository] The git repo backing this environment
|
24
24
|
attr_reader :repo
|
25
25
|
|
26
|
-
# Initialize the given
|
26
|
+
# Initialize the given Git environment.
|
27
27
|
#
|
28
28
|
# @param name [String] The unique name describing this environment.
|
29
29
|
# @param basedir [String] The base directory where this environment will be created.
|
@@ -37,7 +37,7 @@ class R10K::Environment::Git < R10K::Environment::Base
|
|
37
37
|
@remote = options[:remote]
|
38
38
|
@ref = options[:ref]
|
39
39
|
|
40
|
-
@repo = R10K::Git::StatefulRepository.new(@
|
40
|
+
@repo = R10K::Git::StatefulRepository.new(@remote, @basedir, @dirname)
|
41
41
|
end
|
42
42
|
|
43
43
|
# Clone or update the given Git environment.
|
@@ -48,8 +48,11 @@ class R10K::Environment::Git < R10K::Environment::Base
|
|
48
48
|
# @api public
|
49
49
|
# @return [void]
|
50
50
|
def sync
|
51
|
-
@repo.sync
|
52
|
-
|
51
|
+
@repo.sync(@ref)
|
52
|
+
end
|
53
|
+
|
54
|
+
def status
|
55
|
+
@repo.status(@ref)
|
53
56
|
end
|
54
57
|
|
55
58
|
# Return a sting which uniquely identifies (per source) the current state of the
|
@@ -61,7 +64,17 @@ class R10K::Environment::Git < R10K::Environment::Base
|
|
61
64
|
@repo.head
|
62
65
|
end
|
63
66
|
|
64
|
-
|
67
|
+
include R10K::Util::Purgeable
|
65
68
|
|
66
|
-
|
69
|
+
def managed_directories
|
70
|
+
[@full_path]
|
71
|
+
end
|
72
|
+
|
73
|
+
# Returns an array of the full paths to all the content being managed.
|
74
|
+
# @note This implements a required method for the Purgeable mixin
|
75
|
+
# @return [Array<String>]
|
76
|
+
def desired_contents
|
77
|
+
desired = [File.join(@full_path, '.git')]
|
78
|
+
desired += @repo.tracked_paths.map { |entry| File.join(@full_path, entry) }
|
79
|
+
end
|
67
80
|
end
|
data/lib/r10k/feature.rb
CHANGED
@@ -24,29 +24,29 @@ module R10K
|
|
24
24
|
|
25
25
|
# @return [true, false] Is this feature available?
|
26
26
|
def available?
|
27
|
-
logger.debug1 { "Testing to see if feature
|
27
|
+
logger.debug1 { _("Testing to see if feature %{name} is available.") % {name: @name} }
|
28
28
|
rv = @libraries.all? { |lib| library_available?(lib) } && proc_available?
|
29
29
|
msg = rv ? "is" : "is not"
|
30
|
-
logger.debug1 { "Feature
|
30
|
+
logger.debug1 { _("Feature %{name} %{message} available.") % {name: @name, message: msg} }
|
31
31
|
rv
|
32
32
|
end
|
33
33
|
|
34
34
|
private
|
35
35
|
|
36
36
|
def library_available?(lib)
|
37
|
-
logger.debug2 { "Attempting to load library '
|
37
|
+
logger.debug2 { _("Attempting to load library '%{lib}' for feature %{name}") % {lib: lib, name: @name} }
|
38
38
|
require lib
|
39
39
|
true
|
40
40
|
rescue ScriptError => e
|
41
|
-
logger.debug2 { "Error while loading library
|
41
|
+
logger.debug2 { _("Error while loading library %{lib} for feature %{name}: %{error_msg}") % {lib: lib, name: @name, error_msg: e.message} }
|
42
42
|
false
|
43
43
|
end
|
44
44
|
|
45
45
|
def proc_available?
|
46
46
|
if @block
|
47
|
-
logger.debug2 { "Evaluating proc
|
47
|
+
logger.debug2 { _("Evaluating proc %{block} to test for feature %{name}") % {block: @block.inspect, name: @name} }
|
48
48
|
output = @block.call
|
49
|
-
logger.debug2 { "Proc
|
49
|
+
logger.debug2 { _("Proc %{block} for feature %{name} returned %{output}") % {block: @block.inspect, name: @name, output: output.inspect } }
|
50
50
|
!!output
|
51
51
|
else
|
52
52
|
true
|
@@ -91,16 +91,14 @@ module R10K
|
|
91
91
|
# should be unpacked/installed into.
|
92
92
|
# @return [void]
|
93
93
|
def unpack(target_dir)
|
94
|
-
logger.debug1 "Unpacking
|
94
|
+
logger.debug1 _("Unpacking %{download_path} to %{target_dir} (with tmpdir %{tmp_path})") % {download_path: download_path, target_dir: target_dir, tmp_path: unpack_path}
|
95
95
|
file_lists = PuppetForge::Unpacker.unpack(download_path.to_s, target_dir.to_s, unpack_path.to_s)
|
96
|
-
logger.debug2 "Valid files unpacked:
|
96
|
+
logger.debug2 _("Valid files unpacked: %{valid_files}") % {valid_files: file_lists[:valid]}
|
97
97
|
if !file_lists[:invalid].empty?
|
98
|
-
logger.debug1 "These files existed in the module's tar file, but are invalid filetypes and were not "
|
99
|
-
"unpacked: #{file_lists[:invalid]}"
|
98
|
+
logger.debug1 _("These files existed in the module's tar file, but are invalid filetypes and were not unpacked: %{invalid_files}") % {invalid_files: file_lists[:invalid]}
|
100
99
|
end
|
101
100
|
if !file_lists[:symlinks].empty?
|
102
|
-
|
103
|
-
"#{@forge_release.slug} contained these ignored symlinks: #{file_lists[:symlinks]}"
|
101
|
+
logger.warn _("Symlinks are unsupported and were not unpacked from the module tarball. %{release_slug} contained these ignored symlinks: %{symlinks}") % {release_slug: @forge_release.slug, symlinks: file_lists[:symlinks]}
|
104
102
|
end
|
105
103
|
end
|
106
104
|
|
data/lib/r10k/git.rb
CHANGED
@@ -29,7 +29,7 @@ module R10K
|
|
29
29
|
:on_set => proc do
|
30
30
|
[:ssh, :https].each do |transport|
|
31
31
|
if !::Rugged.features.include?(transport)
|
32
|
-
logger.warn "Rugged has been compiled without support for
|
32
|
+
logger.warn _("Rugged has been compiled without support for %{transport}; Git repositories will not be reachable via %{transport}.") % {transport: transport}
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -65,7 +65,7 @@ module R10K
|
|
65
65
|
def self.default_name
|
66
66
|
name, _ = @providers.find { |(_, hash)| R10K::Features.available?(hash[:feature]) }
|
67
67
|
if name.nil?
|
68
|
-
raise R10K::Error, "No Git providers are functional."
|
68
|
+
raise R10K::Error, _("No Git providers are functional.")
|
69
69
|
end
|
70
70
|
name
|
71
71
|
end
|
@@ -82,18 +82,18 @@ module R10K
|
|
82
82
|
_, attrs = @providers.find { |(providername, _)| name == providername }
|
83
83
|
if attrs.nil?
|
84
84
|
@provider = NULL_PROVIDER
|
85
|
-
raise R10K::Error, "No Git provider named '
|
85
|
+
raise R10K::Error, _("No Git provider named '%{name}'.") % {name: name}
|
86
86
|
end
|
87
87
|
if !R10K::Features.available?(attrs[:feature])
|
88
88
|
@provider = NULL_PROVIDER
|
89
|
-
raise R10K::Error, "Git provider '
|
89
|
+
raise R10K::Error, _("Git provider '%{name}' is not functional.") % {name: name}
|
90
90
|
end
|
91
91
|
if attrs[:on_set]
|
92
92
|
attrs[:on_set].call
|
93
93
|
end
|
94
94
|
|
95
95
|
@provider = attrs[:module]
|
96
|
-
logger.debug1 { "Setting Git provider to
|
96
|
+
logger.debug1 { _("Setting Git provider to %{provider}") % {provider: @provider.name} }
|
97
97
|
end
|
98
98
|
|
99
99
|
# @return [Module] The namespace of the first available Git implementation.
|
@@ -101,10 +101,10 @@ module R10K
|
|
101
101
|
def self.provider
|
102
102
|
case @provider
|
103
103
|
when NULL_PROVIDER
|
104
|
-
raise R10K::Error, "No Git provider set."
|
104
|
+
raise R10K::Error, _("No Git provider set.")
|
105
105
|
when UNSET_PROVIDER
|
106
106
|
self.provider = default_name
|
107
|
-
logger.debug1 { "Setting Git provider to default provider
|
107
|
+
logger.debug1 { _("Setting Git provider to default provider %{name}") % {name: default_name} }
|
108
108
|
end
|
109
109
|
|
110
110
|
@provider
|
data/lib/r10k/git/alternates.rb
CHANGED
@@ -43,7 +43,7 @@ class R10K::Git::Alternates
|
|
43
43
|
|
44
44
|
def write(entries)
|
45
45
|
if ! @file.parent.directory?
|
46
|
-
raise R10K::Git::GitError, "Cannot write
|
46
|
+
raise R10K::Git::GitError, _("Cannot write %{file}; parent directory does not exist") % {file: @file}
|
47
47
|
end
|
48
48
|
@file.open("w") do |fh|
|
49
49
|
entries.each do |entry|
|
data/lib/r10k/git/cache.rb
CHANGED
@@ -52,7 +52,7 @@ class R10K::Git::Cache
|
|
52
52
|
# @deprecated
|
53
53
|
# @return [String] The path to the git cache repository
|
54
54
|
def path
|
55
|
-
logger.warn "
|
55
|
+
logger.warn _("%{class}#path is deprecated; use #git_dir") % {class: self.class}
|
56
56
|
git_dir
|
57
57
|
end
|
58
58
|
|
@@ -81,7 +81,7 @@ class R10K::Git::Cache
|
|
81
81
|
if cached?
|
82
82
|
@repo.fetch
|
83
83
|
else
|
84
|
-
logger.debug1 "Creating new git cache for
|
84
|
+
logger.debug1 _("Creating new git cache for %{remote}") % {remote: @remote.inspect}
|
85
85
|
|
86
86
|
# TODO extract this to an initialization step
|
87
87
|
if !File.exist?(settings[:cache_root])
|
@@ -31,7 +31,7 @@ class R10K::Git::Rugged::BareRepository < R10K::Git::Rugged::BaseRepository
|
|
31
31
|
# @param remote [String] The URL of the Git remote to clone.
|
32
32
|
# @return [void]
|
33
33
|
def clone(remote)
|
34
|
-
logger.debug1 { "Cloning '
|
34
|
+
logger.debug1 { _("Cloning '%{remote}' into %{path}") % {remote: remote, path: @path} }
|
35
35
|
|
36
36
|
@_rugged_repo = ::Rugged::Repository.init_at(@path.to_s, true).tap do |repo|
|
37
37
|
config = repo.config
|
@@ -49,14 +49,9 @@ class R10K::Git::Rugged::BareRepository < R10K::Git::Rugged::BaseRepository
|
|
49
49
|
#
|
50
50
|
# @return [void]
|
51
51
|
def fetch(remote_name='origin')
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
if defined?(Rugged::Version) && !Gem::Dependency.new('rugged', '>= 0.24.0').match?('rugged', Rugged::Version)
|
56
|
-
logger.warn { "Rugged versions prior to 0.24.0 do not support pruning stale branches during fetch, please upgrade your \'rugged\' gem. (Current version is: #{Rugged::Version})" }
|
57
|
-
end
|
58
|
-
|
59
|
-
options = {:credentials => credentials, :prune => true}
|
52
|
+
backup_branches = wipe_branches
|
53
|
+
logger.debug1 { _("Fetching remote '%{remote_name}' at %{path}") % {remote_name: remote_name, path: @path } }
|
54
|
+
options = {:credentials => credentials}
|
60
55
|
refspecs = ['+refs/*:refs/*']
|
61
56
|
|
62
57
|
remote = remotes[remote_name]
|
@@ -69,12 +64,37 @@ class R10K::Git::Rugged::BareRepository < R10K::Git::Rugged::BaseRepository
|
|
69
64
|
|
70
65
|
report_transfer(results, remote_name)
|
71
66
|
rescue Rugged::SshError, Rugged::NetworkError => e
|
67
|
+
restore_branches(backup_branches)
|
72
68
|
raise R10K::Git::GitError.new(e.message, :git_dir => git_dir, :backtrace => e.backtrace)
|
73
69
|
rescue
|
70
|
+
restore_branches(backup_branches)
|
74
71
|
raise
|
75
72
|
end
|
76
73
|
|
77
74
|
def exist?
|
78
75
|
@path.exist?
|
79
76
|
end
|
77
|
+
|
78
|
+
def wipe_branches
|
79
|
+
backup_branches = {}
|
80
|
+
with_repo do |repo|
|
81
|
+
repo.branches.each do |branch|
|
82
|
+
if !branch.head?
|
83
|
+
backup_branches[branch.name] = branch.target_id
|
84
|
+
repo.branches.delete(branch)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
backup_branches
|
89
|
+
end
|
90
|
+
|
91
|
+
def restore_branches(backup_branches)
|
92
|
+
with_repo do |repo|
|
93
|
+
backup_branches.each_pair do |name, ref|
|
94
|
+
if !repo.branches.exist?(name)
|
95
|
+
repo.create_branch(name, ref)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
80
100
|
end
|
@@ -21,7 +21,7 @@ class R10K::Git::Rugged::Credentials
|
|
21
21
|
# Break out of infinite HTTP auth retry loop introduced in libgit2/rugged 0.24.0, libssh
|
22
22
|
# auth seems to already abort after ~50 attempts.
|
23
23
|
if @called > 50
|
24
|
-
raise R10K::Git::GitError.new("Authentication failed for Git remote
|
24
|
+
raise R10K::Git::GitError.new(_("Authentication failed for Git remote %{url}.") % {url: url.inspect} )
|
25
25
|
end
|
26
26
|
|
27
27
|
if allowed_types.include?(:ssh_key)
|
@@ -45,16 +45,16 @@ class R10K::Git::Rugged::Credentials
|
|
45
45
|
|
46
46
|
if per_repo_private_key
|
47
47
|
private_key = per_repo_private_key
|
48
|
-
logger.debug2 "Using per-repository private key
|
48
|
+
logger.debug2 _("Using per-repository private key %{key} for URL %{url}") % {key: private_key, url: url.inspect}
|
49
49
|
elsif global_private_key
|
50
50
|
private_key = global_private_key
|
51
|
-
logger.debug2 "URL
|
51
|
+
logger.debug2 _("URL %{url} has no per-repository private key using '%{key}'." ) % {key: private_key, url: url.inspect}
|
52
52
|
else
|
53
|
-
raise R10K::Git::GitError.new("Git remote
|
53
|
+
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)
|
54
54
|
end
|
55
55
|
|
56
56
|
if !File.readable?(private_key)
|
57
|
-
raise R10K::Git::GitError.new("Unable to use SSH key auth for
|
57
|
+
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)
|
58
58
|
end
|
59
59
|
|
60
60
|
Rugged::Credentials::SshKey.new(:username => user, :privatekey => private_key)
|
@@ -77,13 +77,13 @@ class R10K::Git::Rugged::Credentials
|
|
77
77
|
|
78
78
|
if !username_from_url.nil?
|
79
79
|
user = username_from_url
|
80
|
-
logger.debug2 "URL
|
80
|
+
logger.debug2 _("URL %{url} includes the username %{username}, using that user for authentication.") % {url: url.inspect, username: username_from_url}
|
81
81
|
elsif git_user
|
82
82
|
user = git_user
|
83
|
-
logger.debug2 "URL
|
83
|
+
logger.debug2 _("URL %{url} did not specify a user, using %{user} from configuration") % {url: url.inspect, user: user.inspect}
|
84
84
|
else
|
85
85
|
user = Etc.getlogin
|
86
|
-
logger.debug2 "URL
|
86
|
+
logger.debug2 _("URL %{url} did not specify a user, using current user %{user}") % {url: url.inspect, user: user.inspect}
|
87
87
|
end
|
88
88
|
|
89
89
|
user
|
@@ -44,8 +44,8 @@ class R10K::Git::Rugged::ThinRepository < R10K::Git::Rugged::WorkingRepository
|
|
44
44
|
checkout(opts.fetch(:ref, 'HEAD'))
|
45
45
|
end
|
46
46
|
|
47
|
-
def checkout(ref)
|
48
|
-
super(@cache_repo.resolve(ref))
|
47
|
+
def checkout(ref, opts = {})
|
48
|
+
super(@cache_repo.resolve(ref), opts)
|
49
49
|
end
|
50
50
|
|
51
51
|
# Fetch refs and objects from one of the Git remotes
|
@@ -61,6 +61,20 @@ class R10K::Git::Rugged::ThinRepository < R10K::Git::Rugged::WorkingRepository
|
|
61
61
|
with_repo { |repo| repo.config['remote.cache.url'] }
|
62
62
|
end
|
63
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
|
+
|
64
78
|
private
|
65
79
|
|
66
80
|
# Override the parent class repo setup so that we can make sure the alternates file is up to date
|
@@ -68,7 +82,7 @@ class R10K::Git::Rugged::ThinRepository < R10K::Git::Rugged::WorkingRepository
|
|
68
82
|
def setup_rugged_repo
|
69
83
|
entry_added = alternates.add?(@cache_repo.objects_dir.to_s)
|
70
84
|
if entry_added
|
71
|
-
logger.debug2 { "Updated repo
|
85
|
+
logger.debug2 { _("Updated repo %{path} to include alternate object db path %{objects_dir}") % {path: @path, objects_dir: @cache_repo.objects_dir} }
|
72
86
|
end
|
73
87
|
super
|
74
88
|
end
|