Class: Gollum::Git::Repo

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ Repo

Returns a new instance of Repo.



343
344
345
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 343

def initialize(path, options = {})
  @repo = RJGit::Repo.new(path, options)
end

Instance Attribute Details

#repoObject (readonly)

Returns the value of attribute repo.



341
342
343
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 341

def repo
  @repo
end

Class Method Details

.init(path, git_options = {}, repo_options = {}) ⇒ Object



347
348
349
350
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 347

def self.init(path, git_options = {}, repo_options = {})
  RJGit::Repo.create(path, {:is_bare => false})
  self.new(path, {:is_bare => false})
end

.init_bare(path, git_options = {}, repo_options = {}) ⇒ Object



352
353
354
355
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 352

def self.init_bare(path, git_options = {}, repo_options = {})
  RJGit::Repo.create(path, {:is_bare => true})
  self.new(path, {:is_bare => true})
end

Instance Method Details

#bareObject



357
358
359
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 357

def bare
  @repo.bare
end

#commit(ref) ⇒ Object



369
370
371
372
373
374
375
376
377
378
379
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 369

def commit(ref)
  ref = Gollum::Git.canonicalize(ref)
  objectid = @repo.jrepo.resolve(ref)
  return nil if objectid.nil?
  id = objectid.name
  commit = @repo.find(id, :commit)
  return nil if commit.nil?
  Gollum::Git::Commit.new(commit)
  rescue Java::OrgEclipseJgitErrors::RevisionSyntaxException
    raise Gollum::Git::NoSuchShaFound
end

#commits(ref = nil, max_count = 10, skip = 0) ⇒ Object



381
382
383
384
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 381

def commits(ref = nil, max_count = 10, skip = 0)
  ref = Gollum::Git.canonicalize(ref)
  @repo.commits(ref, max_count).map{|commit| Gollum::Git::Commit.new(commit)}
end

#configObject



361
362
363
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 361

def config
  @repo.config
end

#diff(sha1, sha2, path = nil) ⇒ Object



425
426
427
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 425

def diff(sha1, sha2, path = nil)
  RJGit::Porcelain.diff(@repo, {:old_rev => sha1, :new_rev => sha2, :file_path => path, :patch => true}).inject("") {|result, diff| result << diff[:patch]}
end

#find(sha, type) ⇒ Object

Not required by gollum-lib



387
388
389
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 387

def find(sha, type)
  @repo.find(sha, type)
end

#gitObject



365
366
367
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 365

def git
  @git ||= Gollum::Git::Git.new(@repo.git)
end

#headObject



392
393
394
395
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 392

def head
  return nil unless @repo.head
  Gollum::Git::Ref.new('refs/heads/master', @repo.head)
end

#indexObject



397
398
399
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 397

def index
  @index ||= Gollum::Git::Index.new(RJGit::Plumbing::Index.new(@repo))
end

#log(ref = 'refs/heads/master', path = nil, options = {}) ⇒ Object



401
402
403
404
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 401

def log(ref = 'refs/heads/master', path = nil, options = {})
  commit = Gollum::Git.canonicalize(commit)
  git.log(ref, path, options)
end

#lstree(sha, options = {}) ⇒ Object



406
407
408
409
410
411
412
413
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 406

def lstree(sha, options={})
  entries = RJGit::Porcelain.ls_tree(@repo.jrepo, nil, @repo.find(sha, :tree), {:recursive => options[:recursive]})
  entries.map! do |entry| 
    entry[:mode] = entry[:mode].to_s(8)
    entry[:sha]  = entry[:id]
    entry
  end
end

#pathObject



415
416
417
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 415

def path
  @repo.path
end

#update_ref(ref = 'refs/heads/master', commit_sha) ⇒ Object



419
420
421
422
423
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 419

def update_ref(ref = 'refs/heads/master', commit_sha)
  ref = Gollum::Git.canonicalize(head)
  cm = self.commit(commit_sha)
  @repo.update_ref(cm.commit, true, ref)
end