Class: R10K::Git::StatefulRepository
- Inherits:
-
Object
- Object
- R10K::Git::StatefulRepository
- Extended by:
- Forwardable
- Includes:
- Logging
- Defined in:
- lib/r10k/git/stateful_repository.rb
Overview
Manage how Git repositories are created and set to specific refs
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
Instance Method Summary collapse
-
#initialize(ref, remote, basedir, dirname) ⇒ StatefulRepository
constructor
Create a new shallow git working directory.
- #status ⇒ Object
- #sync ⇒ Object
- #sync_cache? ⇒ Boolean private
Methods included from Logging
debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level
Constructor Details
#initialize(ref, remote, basedir, dirname) ⇒ StatefulRepository
Create a new shallow git working directory
24 25 26 27 28 29 30 |
# File 'lib/r10k/git/stateful_repository.rb', line 24 def initialize(ref, remote, basedir, dirname) @ref = ref @remote = remote @repo = R10K::Git.thin_repository.new(basedir, dirname) @cache = R10K::Git.cache.generate(remote) end |
Instance Attribute Details
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
13 14 15 |
# File 'lib/r10k/git/stateful_repository.rb', line 13 def repo @repo end |
Instance Method Details
#status ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/r10k/git/stateful_repository.rb', line 57 def status if !@repo.exist? :absent elsif !@repo.git_dir.exist? :mismatched elsif !(@repo.origin == @remote) :mismatched elsif !(@repo.head == @cache.resolve(@ref)) :outdated elsif @cache.ref_type(@ref) == :branch && !@cache.synced? :outdated else :insync end end |
#sync ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/r10k/git/stateful_repository.rb', line 32 def sync @cache.sync if sync_cache? sha = @cache.resolve(@ref) if sha.nil? raise R10K::Git::UnresolvableRefError.new("Unable to sync repo to unresolvable ref '#{@ref}'", :git_dir => @repo.git_dir) end case status when :absent logger.debug { "Cloning #{@repo.path} and checking out #{@ref}" } @repo.clone(@remote, {:ref => sha}) when :mismatched logger.debug { "Replacing #{@repo.path} and checking out #{@ref}" } @repo.path.rmtree @repo.clone(@remote, {:ref => sha}) when :outdated logger.debug { "Updating #{@repo.path} to #{@ref}" } @repo.checkout(sha) else logger.debug { "#{@repo.path} is already at Git ref #{@ref}" } end end |
#sync_cache? ⇒ Boolean
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.
74 75 76 77 78 79 |
# File 'lib/r10k/git/stateful_repository.rb', line 74 def sync_cache? return true if !@cache.exist? return true if !@cache.resolve(@ref) return true if !([:commit, :tag].include? @cache.ref_type(@ref)) return false end |