Class: R10K::Git::Cache
- Inherits:
-
Repository
- Object
- Repository
- R10K::Git::Cache
- Includes:
- Logging, Settings::Mixin
- Defined in:
- lib/r10k/git/cache.rb
Overview
Mirror a git repository for use shared git object repositories
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
- #path ⇒ Object readonly
Attributes inherited from Repository
#basedir, #dirname, #git_dir, #remote
Class Method Summary collapse
-
.generate(remote) ⇒ R10K::Git::Cache
Generate a new instance with the given remote or return an existing object with the given remote.
-
.instance_cache ⇒ Object
private
Lazily construct an instance cache for R10K::Git::Cache objects.
Instance Method Summary collapse
-
#branches ⇒ Array<String>
A list the branches for the git repository.
-
#cached? ⇒ true, false
If the repository has been locally cached.
-
#initialize(remote) ⇒ Cache
constructor
A new instance of Cache.
- #sync ⇒ Object
- #sync! ⇒ Object
Methods included from Logging
formatter, included, level, level=, levels, #logger, #logger_name, outputter, parse_level
Methods included from Settings::Mixin
Methods inherited from Repository
#remotes, #resolve_commit, #resolve_head, #resolve_ref, #resolve_remote_head, #resolve_tag, #tags
Constructor Details
#initialize(remote) ⇒ Cache
Returns a new instance of Cache.
44 45 46 47 48 |
# File 'lib/r10k/git/cache.rb', line 44 def initialize(remote) @remote = remote @git_dir = File.join(settings[:cache_root], sanitized_dirname) end |
Instance Attribute Details
#path ⇒ Object (readonly)
37 38 39 40 |
# File 'lib/r10k/git/cache.rb', line 37 def path logger.warn "#{self.class}#path is deprecated; use #git_dir" @git_dir end |
Class Method Details
.generate(remote) ⇒ R10K::Git::Cache
Generate a new instance with the given remote or return an existing object with the given remote. This should be used over R10K::Git::Cache.new.
28 29 30 |
# File 'lib/r10k/git/cache.rb', line 28 def self.generate(remote) instance_cache.generate(remote) end |
.instance_cache ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Lazily construct an instance cache for R10K::Git::Cache objects
18 19 20 |
# File 'lib/r10k/git/cache.rb', line 18 def self.instance_cache @instance_cache ||= R10K::InstanceCache.new(self) end |
Instance Method Details
#branches ⇒ Array<String>
Returns A list the branches for the git repository.
75 76 77 78 |
# File 'lib/r10k/git/cache.rb', line 75 def branches output = git %w[for-each-ref refs/heads --format %(refname)], :git_dir => git_dir output.stdout.scan(%r[refs/heads/(.*)$]).flatten end |
#cached? ⇒ true, false
Returns If the repository has been locally cached.
81 82 83 |
# File 'lib/r10k/git/cache.rb', line 81 def cached? File.exist? git_dir end |
#sync ⇒ Object
50 51 52 53 54 55 |
# File 'lib/r10k/git/cache.rb', line 50 def sync if not @synced sync! @synced = true end end |
#sync! ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/r10k/git/cache.rb', line 57 def sync! if cached? fetch else logger.debug "Creating new git cache for #{@remote.inspect}" # TODO extract this to an initialization step unless File.exist? settings[:cache_root] FileUtils.mkdir_p settings[:cache_root] end git ['clone', '--mirror', @remote, git_dir] end rescue R10K::Util::Subprocess::SubprocessError => e raise R10K::Git::GitError.wrap(e, "Couldn't update git cache for #{@remote}") end |