class Gollum::Git::Index
Public Class Methods
new(index, repo)
click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 426 def initialize(index, repo) @index = index @rugged_repo = repo @treemap = {} end
Public Instance Methods
add(path, data)
click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 438 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')
click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 449 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_tree()
click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 476 def current_tree @current_tree end
delete(path)
click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 432 def delete(path) @index.remove_all(path) update_treemap(path, false) false end
index()
click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 445 def index @index end
read_tree(id)
click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 467 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
tree()
click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 463 def tree @treemap end
Private Instance Methods
get_parents(parents, head)
click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 482 def get_parents(parents, head) if parents parents.map{|parent| parent.commit} elsif ref = @rugged_repo.references[head] ref = ref.target ref = ref.target if ref.respond_to?(:target) [ref] end end
update_treemap(path, data)
click to toggle source
# File lib/rugged_adapter/git_layer_rugged.rb, line 492 def update_treemap(path, data) # From RJGit::Plumbing::Index path = path[1..-1] if path[0] == ::File::SEPARATOR path = path.split(::File::SEPARATOR) last = path.pop current = @treemap path.each do |dir| current[dir] ||= {} node = current[dir] current = node end current[last] = data @treemap end