Class: R10K::Git::WorkingDir

Inherits:
Repository show all
Extended by:
Forwardable
Includes:
Logging
Defined in:
lib/r10k/git/working_dir.rb

Constant Summary

Constants included from Logging

Logging::LOG_LEVELS

Instance Attribute Summary collapse

Attributes inherited from Repository

#basedir, #dirname, #remote

Instance Method Summary collapse

Methods included from Logging

formatter, included, level, level=, levels, #logger, #logger_name, outputter, parse_level

Methods inherited from Repository

#git

Methods included from Execution

#execute

Constructor Details

#initialize(ref, remote, basedir, dirname = nil) ⇒ WorkingDir

Instantiates a new git synchro and optionally prepares for caching

Parameters:

  • ref (String)
  • remote (String)
  • basedir (String)
  • dirname (String) (defaults to: nil)


32
33
34
35
36
37
38
39
40
41
# File 'lib/r10k/git/working_dir.rb', line 32

def initialize(ref, remote, basedir, dirname = nil)
  @ref     = ref
  @remote  = remote
  @basedir = basedir
  @dirname = dirname || ref

  @full_path = File.join(@basedir, @dirname)

  @cache = R10K::Git::Cache.generate(@remote)
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



20
21
22
# File 'lib/r10k/git/working_dir.rb', line 20

def cache
  @cache
end

#refObject (readonly)

Returns the value of attribute ref.



24
25
26
# File 'lib/r10k/git/working_dir.rb', line 24

def ref
  @ref
end

Instance Method Details

#cloned?true, false

Determine if repo has been cloned into a specific dir

Returns:

  • (true, false)

    If the repo has already been cloned



59
60
61
# File 'lib/r10k/git/working_dir.rb', line 59

def cloned?
  File.directory? git_dir
end

#syncObject

Synchronize the local git repository.



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/r10k/git/working_dir.rb', line 44

def sync
  # TODO stop forcing a sync every time.
  @cache.sync

  if cloned?
    fetch
  else
    clone
  end
  reset
end