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.



429
430
431
432
433
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 429

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

Instance Method Details

#add(path, data) ⇒ Object



450
451
452
453
454
455
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 450

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



461
462
463
464
465
466
467
468
469
470
471
472
473
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 461

def commit(message, parents = nil, actor = nil, last_tree = nil, head = 'refs/heads/master')
  commit_options = {}
  head = "refs/heads/#{head}" if head && head !~ %r(^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



488
489
490
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 488

def current_tree
  @current_tree
end

#delete(path) ⇒ Object



435
436
437
438
439
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 435

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

#delete_all(glob) ⇒ Object



441
442
443
444
445
446
447
448
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 441

def delete_all(glob)
  # if the path start with escape it and avoid treating it as a comment
  escaped_glob = glob[0] == '#' ? glob.sub('#', '\#') : glob

  @index.remove_all(escaped_glob)
  update_treemap(glob, false)
  false
end

#indexObject



457
458
459
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 457

def index
  @index
end

#read_tree(id) ⇒ Object



479
480
481
482
483
484
485
486
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 479

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

#treeObject



475
476
477
# File 'lib/rugged_adapter/git_layer_rugged.rb', line 475

def tree
  @treemap
end