class R10K::Git::ShellGit::BaseRepository
Public Instance Methods
branches()
click to toggle source
@return [Array<String>] All local branches in this repository
# File lib/r10k/git/shellgit/base_repository.rb, line 28 def branches for_each_ref('refs/heads') end
git_dir()
click to toggle source
@abstract @return [Pathname] The path to the Git directory
# File lib/r10k/git/shellgit/base_repository.rb, line 8 def git_dir raise NotImplementedError end
ref_type(pattern)
click to toggle source
@return [Symbol] The type of the given ref, one of :branch, :tag, :commit, or :unknown
# File lib/r10k/git/shellgit/base_repository.rb, line 38 def ref_type(pattern) if branches.include? pattern :branch elsif tags.include? pattern :tag elsif resolve(pattern) :commit else :unknown end end
resolve(pattern)
click to toggle source
Resolve the given Git ref to a commit
@param pattern [String] The git ref to resolve @return [String, nil] The commit SHA if the ref could be resolved, nil otherwise.
# File lib/r10k/git/shellgit/base_repository.rb, line 16 def resolve(pattern) result = git ['rev-parse', "#{pattern}^{commit}"], :git_dir => git_dir.to_s, :raise_on_fail => false if result.success? result.stdout end end
Also aliased as: rev_parse
Private Instance Methods
for_each_ref(pattern)
click to toggle source
@param pattern [String]
# File lib/r10k/git/shellgit/base_repository.rb, line 55 def for_each_ref(pattern) matcher = %r[#{pattern}/(.*)$] output = git ['for-each-ref', pattern, '--format', '%(refname)'], :git_dir => git_dir.to_s output.stdout.scan(matcher).flatten end
git(cmd, opts = {})
click to toggle source
Wrap git commands
@param cmd [Array<String>] cmd The arguments for the git prompt @param opts [Hash] opts
@option opts [String] :path @option opts [String] :git_dir @option opts [String] :work_tree @option opts [String] :raise_on_fail
@raise [R10K::ExecutionFailure] If the executed command exited with a
nonzero exit code.
@return [String] The git command output
# File lib/r10k/git/shellgit/base_repository.rb, line 75 def git(cmd, opts = {}) raise_on_fail = opts.fetch(:raise_on_fail, true) argv = %w{git} if opts[:path] argv << "--git-dir" << File.join(opts[:path], '.git') argv << "--work-tree" << opts[:path] else if opts[:git_dir] argv << "--git-dir" << opts[:git_dir] end if opts[:work_tree] argv << "--work-tree" << opts[:work_tree] end end argv.concat(cmd) subproc = R10K::Util::Subprocess.new(argv) subproc.raise_on_fail = raise_on_fail subproc.logger = self.logger result = subproc.execute result end