Class: Gollum::Git::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/rjgit_adapter/git_layer_rjgit.rb

Instance Method Summary collapse

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(options, sha)
  @git.cat_file(options, 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, options = {})
  options[:commit] = if ref == 'HEAD'
    "#{Gollum::Git.default_ref_for_repo(@git.jrepo)}"
  else
    "#{Gollum::Git.canonicalize(ref)}}"
  end
  options[:paths] = [path]
  options[:force] = true
  @git.checkout(ref, options)
end

#exist?Boolean

Returns:

  • (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, options={}, &block)
  ref = options[:ref] ?  Gollum::Git.canonicalize(options[:ref]) : Gollum::Git.default_ref_for_repo(@git.jrepo)
  results = []
  walk = RevWalk.new(@git.jrepo)
  RJGit::Porcelain.ls_tree(@git.jrepo, options[: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, options = {})
  options[:list_renames] = true if path && options[:follow]
  @git.log(path, Gollum::Git.canonicalize(ref), options).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, options = {})
  ref = Gollum::Git.canonicalize(options[:ref])
  result = RJGit::Porcelain.ls_tree(@git.jrepo, options[: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, options = {})
  @git.pull(remote, branch, options)
end

#push(remote, branch, options = {}) ⇒ Object



290
291
292
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 290

def push(remote, branch, options = {})
  @git.push(remote, [branch].flatten, options)
end

#refs(options, prefix) ⇒ Object



286
287
288
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 286

def refs(options, prefix)
  @git.refs(options, 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(options, *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, options={})
  @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, options)
  log(ref, path, options)
end