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.



339
340
341
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 339

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

Instance Attribute Details

#repoObject (readonly)

Returns the value of attribute repo.



337
338
339
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 337

def repo
  @repo
end

Class Method Details

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



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

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



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

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



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

def bare
  @repo.bare
end

#commit(ref) ⇒ Object



365
366
367
368
369
370
371
372
373
374
375
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 365

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



377
378
379
380
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 377

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



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

def config
  @repo.config
end

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



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

def diff(sha1, sha2, path = nil)
  RJGit::Porcelain.diff(@repo, {:old_rev => sha1, :new_rev => sha2, :file_path => path, :patch => true}).map {|d| Diff.new(d)}
end

#find(sha, type) ⇒ Object

Not required by gollum-lib



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

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

#gitObject



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

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

#headObject



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

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

#indexObject



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

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

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



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

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

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



402
403
404
405
406
407
408
409
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 402

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



411
412
413
# File 'lib/rjgit_adapter/git_layer_rjgit.rb', line 411

def path
  @repo.path
end

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



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

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