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
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.
38 39 40 41 42 |
# File 'lib/r10k/git/cache.rb', line 38 def initialize(remote) @remote = remote @git_dir = File.join(settings[:cache_root], sanitized_dirname) end |
Instance Attribute Details
#path ⇒ Object (readonly)
31 32 33 34 |
# File 'lib/r10k/git/cache.rb', line 31 def path logger.warn "#{self.class}#path is deprecated; use #git_dir" @git_dir end |
Class Method Details
.generate(remote) ⇒ Object
22 23 24 |
# File 'lib/r10k/git/cache.rb', line 22 def self.generate(remote) registry.generate(remote) end |
Instance Method Details
#branches ⇒ Array<String>
Returns A list the branches for the git repository.
74 75 76 77 |
# File 'lib/r10k/git/cache.rb', line 74 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.
80 81 82 |
# File 'lib/r10k/git/cache.rb', line 80 def cached? File.exist? git_dir end |
#sync ⇒ Object
44 45 46 47 48 49 |
# File 'lib/r10k/git/cache.rb', line 44 def sync if not @synced sync! @synced = true end end |
#sync! ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/r10k/git/cache.rb', line 51 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 msg = e.result.stderr.slice(/^fatal: .*$/) if msg raise R10K::Git::GitError, "Couldn't update git cache for #{@remote}: #{msg.inspect}" else raise e end end |