Class: R10K::Git::Rugged::BareRepository
- Inherits:
-
BaseRepository
- Object
- BaseRepository
- R10K::Git::Rugged::BareRepository
- Defined in:
- lib/r10k/git/rugged/bare_repository.rb
Constant Summary
Constants included from Logging
Instance Method Summary collapse
-
#clone(remote) ⇒ void
Clone the given remote.
- #exist? ⇒ Boolean
-
#fetch ⇒ void
Fetch refs and objects from the origin remote.
-
#git_dir ⇒ Pathname
The path to this Git repository.
-
#initialize(basedir, dirname) ⇒ BareRepository
constructor
A new instance of BareRepository.
- #restore_branches(backup_branches) ⇒ Object
- #wipe_branches ⇒ Object
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
Returns a new instance of 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.(@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.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/r10k/git/rugged/bare_repository.rb', line 28 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., :git_dir => git_dir, :backtrace => e.backtrace) end |
#exist? ⇒ Boolean
60 61 62 |
# File 'lib/r10k/git/rugged/bare_repository.rb', line 60 def exist? @path.exist? end |
#fetch ⇒ void
This method returns an undefined value.
Fetch refs and objects from the origin remote
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/r10k/git/rugged/bare_repository.rb', line 45 def fetch backup_branches = wipe_branches logger.debug1 { "Fetching remote 'origin' at #{@path}" } = {:credentials => credentials} refspecs = ['+refs/*:refs/*'] results = with_repo { |repo| repo.fetch('origin', refspecs, ) } report_transfer(results, 'origin') rescue Rugged::SshError, Rugged::NetworkError => e restore_branches(backup_branches) raise R10K::Git::GitError.new(e., :git_dir => git_dir, :backtrace => e.backtrace) rescue restore_branches(backup_branches) raise end |
#git_dir ⇒ Pathname
Returns The path to this Git repository.
18 19 20 |
# File 'lib/r10k/git/rugged/bare_repository.rb', line 18 def git_dir @path end |
#restore_branches(backup_branches) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/r10k/git/rugged/bare_repository.rb', line 77 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_branches ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/r10k/git/rugged/bare_repository.rb', line 64 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 |