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(remote, basedir, dirname) ⇒ StatefulRepository
constructor
Create a new shallow git working directory.
- #resolve(ref) ⇒ Object
- #status(ref) ⇒ Object
- #sync(ref) ⇒ Object
- #sync_cache?(ref) ⇒ Boolean private
Methods included from Logging
debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level
Constructor Details
#initialize(remote, basedir, dirname) ⇒ StatefulRepository
Create a new shallow git working directory
23 24 25 26 27 |
# File 'lib/r10k/git/stateful_repository.rb', line 23 def initialize(remote, basedir, dirname) @remote = remote @cache = R10K::Git.cache.generate(@remote) @repo = R10K::Git.thin_repository.new(basedir, dirname, @cache) 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
#resolve(ref) ⇒ Object
29 30 31 32 |
# File 'lib/r10k/git/stateful_repository.rb', line 29 def resolve(ref) @cache.sync if sync_cache?(ref) @cache.resolve(ref) end |
#status(ref) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/r10k/git/stateful_repository.rb', line 65 def status(ref) if !@repo.exist? :absent elsif !@repo.git_dir.exist? :mismatched elsif !@repo.git_dir.directory? :mismatched elsif !(@repo.origin == @remote) :mismatched elsif !(@repo.head == @cache.resolve(ref)) :outdated elsif @cache.ref_type(ref) == :branch && !@cache.synced? :outdated elsif @repo.dirty? :dirty else :insync end end |
#sync(ref) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/r10k/git/stateful_repository.rb', line 34 def sync(ref) @cache.sync if sync_cache?(ref) sha = @cache.resolve(ref) if sha.nil? raise R10K::Git::UnresolvableRefError.new(_("Unable to sync repo to unresolvable ref '%{ref}'") % {ref: ref}, :git_dir => @repo.git_dir) end workdir_status = status(ref) case workdir_status when :absent logger.debug { _("Cloning %{repo_path} and checking out %{ref}") % {repo_path: @repo.path, ref: ref } } @repo.clone(@remote, {:ref => sha}) when :mismatched logger.debug { _("Replacing %{repo_path} and checking out %{ref}") % {repo_path: @repo.path, ref: ref } } @repo.path.rmtree @repo.clone(@remote, {:ref => sha}) when :outdated, :dirty if workdir_status == :dirty logger.warn { _("%{repo_path} has local modifications which will be overwritten") % {repo_path: @repo.path} } end logger.debug { _("Updating %{repo_path} to %{ref}") % {repo_path: @repo.path, ref: ref } } @repo.checkout(sha, {:force => true}) else logger.debug { _("%{repo_path} is already at Git ref %{ref}") % {repo_path: @repo.path, ref: ref } } end end |
#sync_cache?(ref) ⇒ 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.
86 87 88 89 90 91 |
# File 'lib/r10k/git/stateful_repository.rb', line 86 def sync_cache?(ref) return true if !@cache.exist? return true if !@cache.resolve(ref) return true if !([:commit, :tag].include? @cache.ref_type(ref)) return false end |