Class: R10K::Git::WorkingDir
- Inherits:
-
Repository
- Object
- Repository
- R10K::Git::WorkingDir
- Extended by:
- Forwardable
- Includes:
- Logging
- Defined in:
- lib/r10k/git/working_dir.rb
Overview
Implements sparse git repositories with shared objects
Working directory instances use the git alternatives object store, so that working directories only contain checked out files and all object files are shared.
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#ref ⇒ Object
readonly
Returns the value of attribute ref.
-
#remote ⇒ Object
readonly
Returns the value of attribute remote.
Attributes inherited from Repository
Instance Method Summary collapse
-
#checkout(ref) ⇒ Object
check out the given ref.
-
#cloned? ⇒ true, false
(also: #git?)
Determine if repo has been cloned into a specific dir.
-
#current ⇒ R10k::Git::Head
The currently checked out HEAD.
-
#exist? ⇒ true, false
Does a directory exist where we expect a working dir to be?.
-
#initialize(ref, remote, basedir, dirname = nil) ⇒ WorkingDir
constructor
Create a new shallow git working directory.
- #outdated? ⇒ Boolean
-
#resolve_remote_head(pattern, remote = 'cache') ⇒ Object
Prefer remote heads from the ‘cache’ remote over the real remote.
-
#sync ⇒ Object
Synchronize the local git repository.
- #update ⇒ Object
Methods included from Logging
formatter, included, level, level=, levels, #logger, #logger_name, outputter, parse_level
Methods inherited from Repository
#remotes, #resolve_commit, #resolve_head, #resolve_ref, #resolve_tag, #tags
Constructor Details
#initialize(ref, remote, basedir, dirname = nil) ⇒ WorkingDir
Create a new shallow git working directory
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/r10k/git/working_dir.rb', line 35 def initialize(ref, remote, basedir, dirname = nil) @remote = remote @basedir = basedir @dirname = dirname || ref @full_path = File.join(@basedir, @dirname) @git_dir = File.join(@full_path, '.git') @alternates = R10K::Git::Alternates.new(@git_dir) @cache = R10K::Git::Cache.generate(@remote) if ref.is_a? String @ref = R10K::Git::Ref.new(ref, self) else @ref = ref @ref.repository = self end end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
19 20 21 |
# File 'lib/r10k/git/working_dir.rb', line 19 def cache @cache end |
#ref ⇒ Object (readonly)
Returns the value of attribute ref.
23 24 25 |
# File 'lib/r10k/git/working_dir.rb', line 23 def ref @ref end |
#remote ⇒ Object (readonly)
Returns the value of attribute remote.
27 28 29 |
# File 'lib/r10k/git/working_dir.rb', line 27 def remote @remote end |
Instance Method Details
#checkout(ref) ⇒ Object
check out the given ref
92 93 94 95 96 97 98 99 100 |
# File 'lib/r10k/git/working_dir.rb', line 92 def checkout(ref) if ref.resolvable? git ["checkout", "--force", @ref.sha1], :path => @full_path else raise R10K::Git::UnresolvableRefError.new( "Cannot check out unresolvable ref '#{@ref}'", :git_dir => @full_path) end end |
#cloned? ⇒ true, false Also known as: git?
Determine if repo has been cloned into a specific dir
78 79 80 |
# File 'lib/r10k/git/working_dir.rb', line 78 def cloned? File.directory? @git_dir end |
#current ⇒ R10k::Git::Head
The currently checked out HEAD
105 106 107 |
# File 'lib/r10k/git/working_dir.rb', line 105 def current R10K::Git::Head.new('HEAD', self) end |
#exist? ⇒ true, false
Does a directory exist where we expect a working dir to be?
85 86 87 |
# File 'lib/r10k/git/working_dir.rb', line 85 def exist? File.directory? @full_path end |
#outdated? ⇒ Boolean
109 110 111 |
# File 'lib/r10k/git/working_dir.rb', line 109 def outdated? @ref.fetch? or needs_checkout? end |
#resolve_remote_head(pattern, remote = 'cache') ⇒ Object
Prefer remote heads from the ‘cache’ remote over the real remote
114 115 116 |
# File 'lib/r10k/git/working_dir.rb', line 114 def resolve_remote_head(pattern, remote = 'cache') super(pattern, remote) end |
#sync ⇒ Object
Synchronize the local git repository.
56 57 58 59 60 61 62 |
# File 'lib/r10k/git/working_dir.rb', line 56 def sync if not cloned? clone else update end end |
#update ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/r10k/git/working_dir.rb', line 64 def update update_remotes if update_remotes? if ref_needs_fetch? fetch_from_cache checkout(@ref) elsif needs_checkout? checkout(@ref) end end |