Class: Gollum::Git::Git
- Inherits:
-
Object
- Object
- Gollum::Git::Git
- Defined in:
- lib/grit_adapter/git_layer_grit.rb
Overview
Note that in Grit, the methods grep, rm, checkout, ls_files are all passed to native via method_missing. Hence the uniform method signatures.
Instance Method Summary collapse
-
#cat_file(options, sha) ⇒ Object
@repo.git.cat_file(=> true, sha).
-
#checkout(path, ref, options = {}, &block) ⇒ Object
git.checkout({}, ‘HEAD’, ‘–’, path).
- #exist? ⇒ Boolean
- #grep(query, options = {}) ⇒ Object
-
#initialize(git, repo_bare = false) ⇒ Git
constructor
A new instance of Git.
- #ls_files(query, options = {}) ⇒ Object
- #ls_tree(options = {}, *args, &block) ⇒ Object
- #pull(remote, branch, options = {}) ⇒ Object
- #push(remote, branch, options = {}) ⇒ Object
- #rev_list(options, *refs) ⇒ Object
- #revert(path, sha1, sha2, ref) ⇒ Object
-
#rm(path, options = {}, &block) ⇒ Object
git.rm(=> true, ‘–’, path).
- #versions_for_path(path = nil, ref = nil, options = nil) ⇒ Object
Constructor Details
#initialize(git, repo_bare = false) ⇒ Git
Returns a new instance of Git.
130 131 132 133 |
# File 'lib/grit_adapter/git_layer_grit.rb', line 130 def initialize(git, = false) @git = git @repo_bare = end |
Instance Method Details
#cat_file(options, sha) ⇒ Object
@repo.git.cat_file(=> true, sha)
194 195 196 |
# File 'lib/grit_adapter/git_layer_grit.rb', line 194 def cat_file(, sha) @git.cat_file(, sha) end |
#checkout(path, ref, options = {}, &block) ⇒ Object
git.checkout({}, ‘HEAD’, ‘–’, path)
161 162 163 |
# File 'lib/grit_adapter/git_layer_grit.rb', line 161 def checkout(path, ref, = {}, &block) @git.checkout(, ref, '--', path, &block) end |
#exist? ⇒ Boolean
135 136 137 |
# File 'lib/grit_adapter/git_layer_grit.rb', line 135 def exist? @git.exist? end |
#grep(query, options = {}) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/grit_adapter/git_layer_grit.rb', line 139 def grep(query, ={}) ref = [:ref] ? [: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 << [:path] if [: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 = {}) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/grit_adapter/git_layer_grit.rb', line 177 def ls_files(query, = {}) ref = [:ref] ? [:ref] : "HEAD" path = .delete(:path) || "." .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) ⇒ Object
189 190 191 |
# File 'lib/grit_adapter/git_layer_grit.rb', line 189 def ls_tree(={}, *args, &block) @git.native(:ls_tree, , *args, &block) end |
#pull(remote, branch, options = {}) ⇒ Object
214 215 216 |
# File 'lib/grit_adapter/git_layer_grit.rb', line 214 def pull(remote, branch, = {}) @git.pull(, remote, branch) end |
#push(remote, branch, options = {}) ⇒ Object
210 211 212 |
# File 'lib/grit_adapter/git_layer_grit.rb', line 210 def push(remote, branch, = {}) @git.push(, remote, branch) end |
#rev_list(options, *refs) ⇒ Object
165 166 167 168 169 |
# File 'lib/grit_adapter/git_layer_grit.rb', line 165 def rev_list(, *refs) @git.rev_list(, *refs) rescue Grit::GitRuby::Repository::NoSuchShaFound raise Gollum::Git::NoSuchShaFound end |
#revert(path, sha1, sha2, ref) ⇒ Object
171 172 173 174 175 |
# 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) ⇒ Object
git.rm(=> true, ‘–’, path)
155 156 157 158 |
# File 'lib/grit_adapter/git_layer_grit.rb', line 155 def rm(path, = {}, &block) ['f'] = true if [:force] @git.rm(, '--', path, &block) end |
#versions_for_path(path = nil, ref = nil, options = nil) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/grit_adapter/git_layer_grit.rb', line 198 def versions_for_path(path = nil, ref = nil, = nil) if [:follow] [:pretty] = 'raw' .delete :max_count .delete :skip logstr = log(path, ref, ) Gollum::Git::Commit.list_from_string(repo, logstr) else repo.log(ref, path, ).map {|grit_commit| Gollum::Git::Commit.new(grit_commit)} end end |