Manage a non-bare Git repository
@attribute [r] path
@return [Pathname]
# File lib/r10k/git/shellgit/working_repository.rb, line 17 def initialize(basedir, dirname) @path = Pathname.new(File.join(basedir, dirname)) end
# File lib/r10k/git/shellgit/working_repository.rb, line 80 def alternates R10K::Git::Alternates.new(git_dir) end
Check out the given Git ref
@param ref [String] The git reference to check out @param opts [Hash] Optional hash of additional options.
# File lib/r10k/git/shellgit/working_repository.rb, line 51 def checkout(ref, opts = {}) # :force defaults to true if !opts.has_key?(:force) || opts[:force] force_opt = '--force' else force_opt = '' end git ['checkout', ref, force_opt], :path => @path.to_s end
Clone this git repository
@param remote [String] The Git remote to clone @param opts [Hash]
@options opts [String] :ref The git ref to check out on clone @options opts [String] :reference A Git repository to use as an alternate object database
@return [void]
# 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
does the working tree have local modifications to tracked files?
# File lib/r10k/git/shellgit/working_repository.rb, line 93 def dirty? result = git(['diff-index', '--quiet','HEAD', '--'], :path => @path.to_s, :raise_on_fail => false) result.exit_code != 0 end
# File lib/r10k/git/shellgit/working_repository.rb, line 71 def exist? @path.exist? end
# 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
@return [Pathname] The path to the Git directory inside of this repository
# File lib/r10k/git/shellgit/working_repository.rb, line 13 def git_dir @path + '.git' end
@return [String] The currently checked out ref
# File lib/r10k/git/shellgit/working_repository.rb, line 76 def head resolve('HEAD') end
@return [String] The origin remote URL
# 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