class Gollum::Git::Git
Note that in Grit
, the methods grep, rm, checkout, ls_files
are all passed to native via method_missing. Hence the uniform method signatures.
Public Class Methods
new(git, repo_bare = false)
click to toggle source
# File lib/grit_adapter/git_layer_grit.rb, line 130 def initialize(git, repo_bare = false) @git = git @repo_bare = repo_bare end
Public Instance Methods
cat_file(options, sha)
click to toggle source
@repo.git.cat_file({:p => true}, sha)
# File lib/grit_adapter/git_layer_grit.rb, line 194 def cat_file(options, sha) @git.cat_file(options, sha) end
checkout(path, ref, options = {}, &block)
click to toggle source
git.checkout({}, ‘HEAD’, ‘–’, path)
# File lib/grit_adapter/git_layer_grit.rb, line 161 def checkout(path, ref, options = {}, &block) @git.checkout(options, ref, '--', path, &block) end
exist?()
click to toggle source
# File lib/grit_adapter/git_layer_grit.rb, line 135 def exist? @git.exist? end
grep(query, options={})
click to toggle source
# File lib/grit_adapter/git_layer_grit.rb, line 139 def grep(query, options={}) ref = options[:ref] ? options[:ref] : "HEAD" query = Shellwords.shellescape(query) query = Shellwords.split(query).select {|q| !(q =~ /^(-O)|(--open-files-in-pager)/) } query = Shellwords.join(query) args = [{}, '-I', '-i', '-c', query, ref, '--'] args << options[:path] if options[:path] result = @git.native(:grep, *args).split("\n") result.map do |line| branch_and_name, _, count = line.rpartition(":") branch, _, name = branch_and_name.partition(':') {:name => name, :count => count} end end
ls_files(query, options = {})
click to toggle source
# File lib/grit_adapter/git_layer_grit.rb, line 177 def ls_files(query, options = {}) ref = options[:ref] ? options[:ref] : "HEAD" path = options.delete(:path) || "." options.delete(:ref) query = Shellwords.shellescape(query) if @git.work_tree && !@git.work_tree.empty? then @git.ls_files({}, ref, ::File.join(path, "*#{query}*")).split("\n") else ls_tree({:full_tree => true, :r => true, :name_only => true}, ref, path).split("\n").select {|line| line.match(/#{Regexp.escape(query)}/i)} end end
ls_tree(options={}, *args, &block)
click to toggle source
# File lib/grit_adapter/git_layer_grit.rb, line 189 def ls_tree(options={}, *args, &block) @git.native(:ls_tree, options, *args, &block) end
pull(remote, branch, options = {})
click to toggle source
# File lib/grit_adapter/git_layer_grit.rb, line 214 def pull(remote, branch, options = {}) @git.pull(options, remote, branch) end
push(remote, branch, options = {})
click to toggle source
# File lib/grit_adapter/git_layer_grit.rb, line 210 def push(remote, branch, options = {}) @git.push(options, remote, branch) end
rev_list(options, *refs)
click to toggle source
# File lib/grit_adapter/git_layer_grit.rb, line 165 def rev_list(options, *refs) @git.rev_list(options, *refs) rescue Grit::GitRuby::Repository::NoSuchShaFound raise Gollum::Git::NoSuchShaFound end
revert(path, sha1, sha2, ref)
click to toggle source
# File lib/grit_adapter/git_layer_grit.rb, line 171 def revert(path, sha1, sha2, ref) patch = path ? repo.diff(sha2, sha1, path).first.diff : repo.diff(sha2, sha1).map { |d| d.diff }.join("\n") @git.apply_patch({}, ref, patch) end
rm(path, options = {}, &block)
click to toggle source
git.rm({‘f’ => true}, ‘–’, path)
# File lib/grit_adapter/git_layer_grit.rb, line 155 def rm(path, options = {}, &block) options['f'] = true if options[:force] @git.rm(options, '--', path, &block) end
versions_for_path(path = nil, ref = nil, options = nil)
click to toggle source
# File lib/grit_adapter/git_layer_grit.rb, line 198 def versions_for_path(path = nil, ref = nil, options = nil) if options[:follow] options[:pretty] = 'raw' options.delete :max_count options.delete :skip logstr = log(path, ref, options) Gollum::Git::Commit.list_from_string(repo, logstr) else repo.log(ref, path, options).map {|grit_commit| Gollum::Git::Commit.new(grit_commit)} end end
Private Instance Methods
log(path = nil, ref = nil, options = nil, *args)
click to toggle source
# File lib/grit_adapter/git_layer_grit.rb, line 220 def log(path = nil, ref = nil, options = nil, *args) @git.native(:log, options, "--", path) end
refs(options, prefix)
click to toggle source
# File lib/grit_adapter/git_layer_grit.rb, line 224 def refs(options, prefix) @git.refs(options, prefix) end
repo()
click to toggle source
# File lib/grit_adapter/git_layer_grit.rb, line 228 def repo @repo ||= Grit::Repo.new(@git.git_dir, {:is_bare => @repo_bare}) end