Class: Gollum::Git::Git
- Inherits:
-
Object
- Object
- Gollum::Git::Git
- Defined in:
- lib/rjgit_adapter/git_layer_rjgit.rb
Instance Method Summary collapse
-
#cat_file(options, sha) ⇒ Object
@repo.git.cat_file(=> true, sha).
- #checkout(path, ref, options = {}) ⇒ Object
- #exist? ⇒ Boolean
- #grep(query, options = {}, &block) ⇒ Object
-
#initialize(git) ⇒ Git
constructor
A new instance of Git.
- #log(ref = Gollum::Git.default_ref_for_repo(@git.jrepo), path = nil, options = {}) ⇒ Object
- #ls_files(query, options = {}) ⇒ Object
- #pull(remote, branch = nil, options = {}) ⇒ Object
- #push(remote, branch, options = {}) ⇒ Object
- #refs(options, prefix) ⇒ Object
-
#rev_list(options, *refs) ⇒ Object
rev_list(:max_count=>1, ref).
- #revert(path, sha1, sha2, ref = Gollum::Git.default_ref_for_repo(@git.jrepo)) ⇒ Object
- #revert_commit(sha1, sha2, ref = Gollum::Git.default_ref_for_repo(@git.jrepo)) ⇒ Object
- #revert_path(path, sha1, sha2, ref = Gollum::Git.default_ref_for_repo(@git.jrepo)) ⇒ Object
- #rm(path, options = {}) ⇒ Object
- #versions_for_path(path, ref, options) ⇒ Object
Constructor Details
#initialize(git) ⇒ Git
Returns a new instance of Git.
203 204 205 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 203 def initialize(git) @git = git end |
Instance Method Details
#cat_file(options, sha) ⇒ Object
@repo.git.cat_file(=> true, sha)
273 274 275 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 273 def cat_file(, sha) @git.cat_file(, sha) end |
#checkout(path, ref, options = {}) ⇒ Object
228 229 230 231 232 233 234 235 236 237 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 228 def checkout(path, ref, = {}) [:commit] = if ref == 'HEAD' "#{Gollum::Git.default_ref_for_repo(@git.jrepo)}" else "#{Gollum::Git.canonicalize(ref)}}" end [:paths] = [path] [:force] = true @git.checkout(ref, ) end |
#exist? ⇒ Boolean
207 208 209 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 207 def exist? ::File.exists?(@git.jrepo.getDirectory.to_s) end |
#grep(query, options = {}, &block) ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 211 def grep(query, ={}, &block) ref = [:ref] ? Gollum::Git.canonicalize([:ref]) : Gollum::Git.default_ref_for_repo(@git.jrepo) results = [] walk = RevWalk.new(@git.jrepo) RJGit::Porcelain.ls_tree(@git.jrepo, [:path], ref, {:recursive => true}).each do |item| if item[:type] == 'blob' blob = RJGit::Blob.new(@git.jrepo, item[:mode], item[:path], walk.lookup_blob(ObjectId.from_string(item[:id]))) results << yield(blob.path, blob.binary? ? nil : blob.data) end end results.compact end |
#log(ref = Gollum::Git.default_ref_for_repo(@git.jrepo), path = nil, options = {}) ⇒ Object
277 278 279 280 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 277 def log(ref = Gollum::Git.default_ref_for_repo(@git.jrepo), path = nil, = {}) [:list_renames] = true if path && [:follow] @git.log(path, Gollum::Git.canonicalize(ref), ).map {|commit| Gollum::Git::Commit.new(commit)} end |
#ls_files(query, options = {}) ⇒ Object
244 245 246 247 248 249 250 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 244 def ls_files(query, = {}) ref = Gollum::Git.canonicalize([:ref]) result = RJGit::Porcelain.ls_tree(@git.jrepo, [:path], ref, {:recursive => true}).select {|object| object[:type] == 'blob' && !!(::File.basename(object[:path]) =~ /#{query}/i) } result.map do |r| r[:path] end end |
#pull(remote, branch = nil, options = {}) ⇒ Object
294 295 296 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 294 def pull(remote, branch = nil, = {}) @git.pull(remote, branch, ) end |
#push(remote, branch, options = {}) ⇒ Object
290 291 292 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 290 def push(remote, branch, = {}) @git.push(remote, [branch].flatten, ) end |
#refs(options, prefix) ⇒ Object
286 287 288 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 286 def refs(, prefix) @git.refs(, prefix) end |
#rev_list(options, *refs) ⇒ Object
rev_list(:max_count=>1, ref)
240 241 242 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 240 def rev_list(, *refs) raise 'Not implemented' end |
#revert(path, sha1, sha2, ref = Gollum::Git.default_ref_for_repo(@git.jrepo)) ⇒ Object
261 262 263 264 265 266 267 268 269 270 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 261 def revert(path, sha1, sha2, ref = Gollum::Git.default_ref_for_repo(@git.jrepo)) patch = generate_patch(sha1, sha2, path) return false unless patch begin applier = RJGit::Plumbing::ApplyPatchToIndex.new(@git.jrepo, patch, ref) applier.new_tree rescue ::RJGit::PatchApplyException false end end |
#revert_commit(sha1, sha2, ref = Gollum::Git.default_ref_for_repo(@git.jrepo)) ⇒ Object
257 258 259 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 257 def revert_commit(sha1, sha2, ref = Gollum::Git.default_ref_for_repo(@git.jrepo)) revert(nil, sha1, sha2, ref) end |
#revert_path(path, sha1, sha2, ref = Gollum::Git.default_ref_for_repo(@git.jrepo)) ⇒ Object
252 253 254 255 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 252 def revert_path(path, sha1, sha2, ref = Gollum::Git.default_ref_for_repo(@git.jrepo)) result, _paths = revert(path, sha1, sha2, ref) result end |
#rm(path, options = {}) ⇒ Object
224 225 226 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 224 def rm(path, ={}) @git.remove(path) end |
#versions_for_path(path, ref, options) ⇒ Object
282 283 284 |
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 282 def versions_for_path(path, ref, ) log(ref, path, ) end |