Class: R10K::Git::Rugged::ThinRepository

Inherits:
WorkingRepository show all
Defined in:
lib/r10k/git/rugged/thin_repository.rb

Constant Summary

Constants included from Logging

Logging::LOG_LEVELS

Instance Attribute Summary

Attributes inherited from BaseRepository

#path

Instance Method Summary collapse

Methods inherited from WorkingRepository

#alternates, #dirty?, #exist?, #git_dir, #head, #origin

Methods inherited from BaseRepository

#branches, #ref_type, #remotes, #resolve, #tags

Methods included from Logging

debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level

Constructor Details

#initialize(basedir, dirname, cache_repo) ⇒ ThinRepository



6
7
8
9
10
# File 'lib/r10k/git/rugged/thin_repository.rb', line 6

def initialize(basedir, dirname, cache_repo)
  @cache_repo = cache_repo

  super(basedir, dirname)
end

Instance Method Details

#cacheString



60
61
62
# File 'lib/r10k/git/rugged/thin_repository.rb', line 60

def cache
  with_repo { |repo| repo.config['remote.cache.url'] }
end

#checkout(ref, opts = {}) ⇒ Object



47
48
49
# File 'lib/r10k/git/rugged/thin_repository.rb', line 47

def checkout(ref, opts = {})
  super(@cache_repo.resolve(ref), opts)
end

#clone(remote, opts = {}) ⇒ void

This method returns an undefined value.

Clone this git repository



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/r10k/git/rugged/thin_repository.rb', line 20

def clone(remote, opts = {})
  logger.debug1 { "Cloning '#{remote}' into #{@path}" }
  @cache_repo.sync

  cache_objects_dir = @cache_repo.objects_dir.to_s

  # {Rugged::Repository.clone_at} doesn't support :alternates, which
  # completely breaks how thin repositories need to work. To circumvent
  # this we manually create a Git repository, set up git remotes, and
  # update 'objects/info/alternates' with the path. We don't actually
  # fetch any objects because we don't need them, and we don't actually
  # use any refs in this repository so we skip all those steps.
  ::Rugged::Repository.init_at(@path.to_s, false)
  @_rugged_repo = ::Rugged::Repository.new(@path.to_s, :alternates => [cache_objects_dir])
  alternates << cache_objects_dir

  with_repo do |repo|
    config = repo.config
    config['remote.origin.url']    = remote
    config['remote.origin.fetch']  = '+refs/heads/*:refs/remotes/origin/*'
    config['remote.cache.url']     = @cache_repo.git_dir.to_s
    config['remote.cache.fetch']   = '+refs/heads/*:refs/remotes/cache/*'
  end

  checkout(opts.fetch(:ref, 'HEAD'))
end

#fetch(remote = 'cache') ⇒ void

This method returns an undefined value.

Fetch refs and objects from one of the Git remotes



55
56
57
# File 'lib/r10k/git/rugged/thin_repository.rb', line 55

def fetch(remote = 'cache')
  super(remote)
end

#tracked_paths(ref = "HEAD") ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/r10k/git/rugged/thin_repository.rb', line 64

def tracked_paths(ref="HEAD")
  with_repo do |repo|
    commit = repo.rev_parse(ref)

    unless commit && commit.tree
      raise R10K::Error.new("Unable to resolve '#{ref}' to a valid commit in repo #{@path}")
    end

    commit.tree.walk(:postorder).collect do |root, entry|
      root.empty? ? entry[:name] : File.join(root, entry[:name])
    end
  end
end