Class: R10K::Git::Rugged::WorkingRepository
- Inherits:
-
BaseRepository
- Object
- BaseRepository
- R10K::Git::Rugged::WorkingRepository
- Defined in:
- lib/r10k/git/rugged/working_repository.rb
Direct Known Subclasses
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
@return [Pathname] The path to this directory.
Instance Method Summary collapse
- #alternates ⇒ Object
-
#checkout(ref) ⇒ void
Check out the given Git ref.
-
#clone(remote, opts = {}) ⇒ void
Clone this git repository.
- #exist? ⇒ Boolean
- #fetch(remote = 'origin') ⇒ Object
-
#git_dir ⇒ Pathname
The path to the Git repository inside of this directory.
- #head ⇒ Object
-
#initialize(basedir, dirname) ⇒ WorkingRepository
constructor
A new instance of WorkingRepository.
- #origin ⇒ 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) ⇒ WorkingRepository
Returns a new instance of WorkingRepository.
17 18 19 20 21 22 |
# File 'lib/r10k/git/rugged/working_repository.rb', line 17 def initialize(basedir, dirname) @path = Pathname.new(File.join(basedir, dirname)) if exist? && git_dir.exist? @_rugged_repo = ::Rugged::Repository.new(@path.to_s, :alternates => alternates.to_a) end end |
Instance Attribute Details
#path ⇒ Object (readonly)
@return [Pathname] The path to this directory
8 9 10 |
# File 'lib/r10k/git/rugged/working_repository.rb', line 8 def path @path end |
Instance Method Details
#alternates ⇒ Object
92 93 94 |
# File 'lib/r10k/git/rugged/working_repository.rb', line 92 def alternates R10K::Git::Alternates.new(git_dir) end |
#checkout(ref) ⇒ void
This method returns an undefined value.
Check out the given Git ref
64 65 66 67 68 69 70 71 72 |
# File 'lib/r10k/git/rugged/working_repository.rb', line 64 def checkout(ref) logger.debug1 { "Checking out ref '#{ref}' at #{@path}" } sha = resolve(ref) with_repo do |repo| repo.checkout(sha) repo.reset(sha, :hard) end end |
#clone(remote, opts = {}) ⇒ void
This method returns an undefined value.
Clone this git repository
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/r10k/git/rugged/working_repository.rb', line 33 def clone(remote, opts = {}) logger.debug1 { "Cloning '#{remote}' into #{@path}" } # libgit2/rugged doesn't support cloning a repository and providing an # alternate object database, making the handling of :alternates a noop. # Unfortunately this means that this method can't really use alternates # and running the clone will duplicate all objects in the specified # repository. However alternate databases can be handled when an existing # repository is loaded, so loading a cloned repo will correctly use # alternate object database. = {:credentials => credentials} .merge!(:alternates => [File.join(opts[:reference], 'objects')]) if opts[:reference] @_rugged_repo = ::Rugged::Repository.clone_at(remote, @path.to_s, ) if opts[:reference] alternates << File.join(opts[:reference], 'objects') end if opts[:ref] # todo: always check out something; since we're fetching a repository we # won't populate the working directory. checkout(opts[:ref]) end rescue Rugged::SshError, Rugged::NetworkError => e raise R10K::Git::GitError.new(e., :git_dir => git_dir, :backtrace => e.backtrace) end |
#exist? ⇒ Boolean
84 85 86 |
# File 'lib/r10k/git/rugged/working_repository.rb', line 84 def exist? @path.exist? end |
#fetch(remote = 'origin') ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/r10k/git/rugged/working_repository.rb', line 74 def fetch(remote = 'origin') logger.debug1 { "Fetching remote '#{remote}' at #{@path}" } = {:credentials => credentials} refspecs = ["+refs/heads/*:refs/remotes/#{remote}/*"] results = with_repo { |repo| repo.fetch(remote, refspecs, ) } report_transfer(results, remote) rescue Rugged::SshError, Rugged::NetworkError => e raise R10K::Git::GitError.new(e., :git_dir => git_dir, :backtrace => e.backtrace) end |
#git_dir ⇒ Pathname
Returns The path to the Git repository inside of this directory.
11 12 13 |
# File 'lib/r10k/git/rugged/working_repository.rb', line 11 def git_dir @path + '.git' end |
#head ⇒ Object
88 89 90 |
# File 'lib/r10k/git/rugged/working_repository.rb', line 88 def head resolve('HEAD') end |
#origin ⇒ Object
96 97 98 |
# File 'lib/r10k/git/rugged/working_repository.rb', line 96 def origin with_repo { |repo| repo.config['remote.origin.url'] } end |