Class: R10K::Git::Rugged::BareRepository

Inherits:
BaseRepository show all
Defined in:
lib/r10k/git/rugged/bare_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 BaseRepository

#branches, #ref_type, #resolve, #tags

Methods included from Logging

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

Constructor Details

#initialize(basedir, dirname) ⇒ BareRepository



9
10
11
12
13
14
15
# File 'lib/r10k/git/rugged/bare_repository.rb', line 9

def initialize(basedir, dirname)
  @path = Pathname.new(File.join(basedir, dirname))

  if exist?
    @_rugged_repo = ::Rugged::Repository.bare(@path.to_s)
  end
end

Instance Method Details

#clone(remote) ⇒ void

This method returns an undefined value.

Clone the given remote.

This should only be called if the repository does not exist.



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/r10k/git/rugged/bare_repository.rb', line 33

def clone(remote)
  logger.debug1 { "Cloning '#{remote}' into #{@path}" }
  @_rugged_repo = ::Rugged::Repository.init_at(@path.to_s, true)
  with_repo do |repo|
    config = repo.config
    config['remote.origin.url']    = remote
    config['remote.origin.fetch']  = '+refs/*:refs/*'
    config['remote.origin.mirror'] = 'true'
    fetch
  end
rescue Rugged::SshError, Rugged::NetworkError => e
  raise R10K::Git::GitError.new(e.message, :git_dir => git_dir, :backtrace => e.backtrace)
end

#exist?Boolean



65
66
67
# File 'lib/r10k/git/rugged/bare_repository.rb', line 65

def exist?
  @path.exist?
end

#fetchvoid

This method returns an undefined value.

Fetch refs and objects from the origin remote



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/r10k/git/rugged/bare_repository.rb', line 50

def fetch
  backup_branches = wipe_branches
  logger.debug1 { "Fetching remote 'origin' at #{@path}" }
  options = {:credentials => credentials}
  refspecs = ['+refs/*:refs/*']
  results = with_repo { |repo| repo.fetch('origin', refspecs, options) }
  report_transfer(results, 'origin')
rescue Rugged::SshError, Rugged::NetworkError => e
  restore_branches(backup_branches)
  raise R10K::Git::GitError.new(e.message, :git_dir => git_dir, :backtrace => e.backtrace)
rescue
  restore_branches(backup_branches)
  raise
end

#git_dirPathname



18
19
20
# File 'lib/r10k/git/rugged/bare_repository.rb', line 18

def git_dir
  @path
end

#objects_dirPathname



23
24
25
# File 'lib/r10k/git/rugged/bare_repository.rb', line 23

def objects_dir
  @path + "objects"
end

#restore_branches(backup_branches) ⇒ Object



82
83
84
85
86
87
88
89
90
# File 'lib/r10k/git/rugged/bare_repository.rb', line 82

def restore_branches(backup_branches)
  with_repo do |repo|
    backup_branches.each_pair do |name, ref|
      if !repo.branches.exist?(name)
        repo.create_branch(name, ref)
      end
    end
  end
end

#wipe_branchesObject



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/r10k/git/rugged/bare_repository.rb', line 69

def wipe_branches
  backup_branches = {}
  with_repo do |repo|
    repo.branches.each do |branch|
      if !branch.head?
        backup_branches[branch.name] = branch.target_id
        repo.branches.delete(branch)
      end
    end
  end
  backup_branches
end