Class: Gollum::Git::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/rugged_adapter/git_layer_rugged.rb

Instance Method Summary collapse

Constructor Details

#initialize(index, repo) ⇒ Index

Returns a new instance of Index.



459
460
461
462
463
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 459

def initialize(index, repo)
  @index = index
  @rugged_repo = repo
  @treemap = {}
end

Instance Method Details

#add(path, data) ⇒ Object



471
472
473
474
475
476
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 471

def add(path, data)
  blob = @rugged_repo.write(data, :blob)
  @index.add(:path => path, :oid => blob, :mode => 0100644)
  update_treemap(path, data)
  data
end

#commit(message, parents = nil, actor = nil, last_tree = nil, head = 'refs/heads/master') ⇒ Object



482
483
484
485
486
487
488
489
490
491
492
493
494
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 482

def commit(message, parents = nil, actor = nil, last_tree = nil, head = 'refs/heads/master')
  commit_options = {}
  head = "refs/heads/#{head}" unless head =~ /^refs\/heads\//
  parents = get_parents(parents, head) || []
  actor = Gollum::Git::Actor.default_actor if actor.nil?
  commit_options[:tree] = @index.write_tree
  commit_options[:author] = actor.to_h
  commit_options[:committer] = actor.to_h
  commit_options[:message] = message.to_s
  commit_options[:parents] = parents
  commit_options[:update_ref] = head
  Rugged::Commit.create(@rugged_repo, commit_options)
end

#current_treeObject



513
514
515
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 513

def current_tree
  @current_tree
end

#delete(path) ⇒ Object



465
466
467
468
469
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 465

def delete(path)
  @index.remove_all(path)
  update_treemap(path, false)
  false
end

#indexObject



478
479
480
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 478

def index
  @index
end

#read_tree(id) ⇒ Object



500
501
502
503
504
505
506
507
508
509
510
511
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 500

def read_tree(id)
  id = Gollum::Git::Git.new(@rugged_repo).ref_to_sha(id)
  return nil if id.nil?
  begin
    current_tree = @rugged_repo.lookup(id)
    current_tree = current_tree.tree unless current_tree.is_a?(Rugged::Tree)
    @index.read_tree(current_tree)
  rescue
    raise Gollum::Git::NoSuchShaFound
  end
  @current_tree = Gollum::Git::Tree.new(current_tree)
end

#treeObject



496
497
498
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 496

def tree
  @treemap
end