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 Attribute Summary
Attributes inherited from BaseRepository
Instance Method Summary collapse
-
#clone(remote) ⇒ void
Clone the given remote.
- #exist? ⇒ Boolean
-
#fetch(remote_name = 'origin') ⇒ 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.
-
#objects_dir ⇒ Pathname
The path to the objects directory in this Git repository.
- #restore_branches(backup_branches) ⇒ Object
- #wipe_branches ⇒ Object
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) ⇒ 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.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/r10k/git/rugged/bare_repository.rb', line 33 def clone(remote) logger.debug1 { _("Cloning '%{remote}' into %{path}") % {remote: remote, path: @path} } @_rugged_repo = ::Rugged::Repository.init_at(@path.to_s, true).tap do |repo| config = repo.config config['remote.origin.url'] = remote config['remote.origin.fetch'] = '+refs/*:refs/*' config['remote.origin.mirror'] = 'true' end fetch('origin') rescue Rugged::SshError, Rugged::NetworkError => e raise R10K::Git::GitError.new(e., :git_dir => git_dir, :backtrace => e.backtrace) end |
#exist? ⇒ Boolean
74 75 76 |
# File 'lib/r10k/git/rugged/bare_repository.rb', line 74 def exist? @path.exist? end |
#fetch(remote_name = 'origin') ⇒ void
This method returns an undefined value.
Fetch refs and objects from the origin remote
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/r10k/git/rugged/bare_repository.rb', line 51 def fetch(remote_name='origin') backup_branches = wipe_branches logger.debug1 { _("Fetching remote '%{remote_name}' at %{path}") % {remote_name: remote_name, path: @path } } = {:credentials => credentials} refspecs = ['+refs/*:refs/*'] remote = remotes[remote_name] proxy = R10K::Git.get_proxy_for_remote(remote) results = nil R10K::Git.with_proxy(proxy) do results = with_repo { |repo| repo.fetch(remote_name, refspecs, ) } end report_transfer(results, remote_name) 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 |
#objects_dir ⇒ Pathname
Returns The path to the objects directory in this Git repository.
23 24 25 |
# File 'lib/r10k/git/rugged/bare_repository.rb', line 23 def objects_dir @path + "objects" end |
#restore_branches(backup_branches) ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/r10k/git/rugged/bare_repository.rb', line 91 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
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/r10k/git/rugged/bare_repository.rb', line 78 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 |