Class: R10K::Git::ShellGit::WorkingRepository
- Inherits:
-
BaseRepository
- Object
- BaseRepository
- R10K::Git::ShellGit::WorkingRepository
- Defined in:
- lib/r10k/git/shellgit/working_repository.rb
Overview
Manage a non-bare Git repository
Direct Known Subclasses
Constant Summary
Constants included from Logging
Logging::LOG_LEVELS, Logging::SYSLOG_LEVELS_MAP
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #alternates ⇒ Object
-
#checkout(ref, opts = {}) ⇒ Object
Check out the given Git ref.
-
#clone(remote, opts = {}) ⇒ void
Clone this git repository.
-
#dirty?(exclude_spec = true) ⇒ Boolean
does the working tree have local modifications to tracked files?.
- #exist? ⇒ Boolean
- #fetch(remote_name = 'origin') ⇒ Object
-
#git_dir ⇒ Pathname
The path to the Git directory inside of this repository.
-
#head ⇒ String
The currently checked out ref.
-
#initialize(basedir, dirname) ⇒ WorkingRepository
constructor
A new instance of WorkingRepository.
-
#origin ⇒ String
The origin remote URL.
Methods inherited from BaseRepository
#branches, #is_branch?, #is_tag?, #ref_type, #remotes, #resolve, #tags
Methods included from Logging
add_outputters, 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 |
# File 'lib/r10k/git/shellgit/working_repository.rb', line 17 def initialize(basedir, dirname) @path = Pathname.new(File.join(basedir, dirname)) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/r10k/git/shellgit/working_repository.rb', line 10 def path @path end |
Instance Method Details
#alternates ⇒ Object
80 81 82 |
# File 'lib/r10k/git/shellgit/working_repository.rb', line 80 def alternates R10K::Git::Alternates.new(git_dir) end |
#checkout(ref, opts = {}) ⇒ Object
Check out the given Git ref
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/r10k/git/shellgit/working_repository.rb', line 51 def checkout(ref, opts = {}) argv = ['checkout', ref] # :force defaults to true if !opts.has_key?(:force) || opts[:force] argv << '--force' end git argv, :path => @path.to_s end |
#clone(remote, opts = {}) ⇒ void
This method returns an undefined value.
Clone this git repository
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/r10k/git/shellgit/working_repository.rb', line 30 def clone(remote, opts = {}) argv = ['clone', remote, @path.to_s] if opts[:reference] argv += ['--reference', opts[:reference]] end proxy = R10K::Git.get_proxy_for_remote(remote) R10K::Git.with_proxy(proxy) do git argv end if opts[:ref] checkout(opts[:ref]) end end |
#dirty?(exclude_spec = true) ⇒ Boolean
does the working tree have local modifications to tracked files?
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/r10k/git/shellgit/working_repository.rb', line 93 def dirty?(exclude_spec=true) result = git(['diff-index', '--exit-code', '--name-only', 'HEAD'], :path => @path.to_s, :raise_on_fail => false) if result.exit_code != 0 dirty_files = result.stdout.split("\n") dirty_files.delete_if { |f| f.start_with?('spec/') } if exclude_spec dirty_files.each do |file| logger.debug(_("Found local modifications in %{file_path}" % {file_path: File.join(@path, file)})) # Do this in a block so that the extra subprocess only gets invoked when needed. logger.debug1 { git(['diff-index', '-p', 'HEAD', '--', file], :path => @path.to_s, :raise_on_fail => false).stdout } end return dirty_files.size > 0 else return false end end |
#exist? ⇒ Boolean
71 72 73 |
# File 'lib/r10k/git/shellgit/working_repository.rb', line 71 def exist? @path.exist? end |
#fetch(remote_name = 'origin') ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/r10k/git/shellgit/working_repository.rb', line 62 def fetch(remote_name='origin') remote = remotes[remote_name] proxy = R10K::Git.get_proxy_for_remote(remote) R10K::Git.with_proxy(proxy) do git ['fetch', remote_name, '--prune'], :path => @path.to_s end end |
#git_dir ⇒ Pathname
Returns The path to the Git directory inside of this repository.
13 14 15 |
# File 'lib/r10k/git/shellgit/working_repository.rb', line 13 def git_dir @path + '.git' end |
#head ⇒ String
Returns The currently checked out ref.
76 77 78 |
# File 'lib/r10k/git/shellgit/working_repository.rb', line 76 def head resolve('HEAD') end |
#origin ⇒ String
Returns The origin remote URL.
85 86 87 88 89 90 |
# File 'lib/r10k/git/shellgit/working_repository.rb', line 85 def origin result = git(['config', '--get', 'remote.origin.url'], :path => @path.to_s, :raise_on_fail => false) if result.success? result.stdout end end |