commit.rb revision 307902584a4a70170eae6dc80e17d87f680fe2b3
# depends on GitRepository
# delete a single file and commit the change
end
# add a single file and commit the change
end
# change a single file and commit the change
# throw exception if path is below a file
# save current head oid in case of an emergency
# Entry
entry = {
type: :blob,
filemode: 0100644
}
end
# TreeBuilder
# Commit Sha
if @repo.empty?
else
end
rescue => e
if old_head
else
end
raise e
=end
end
# iff "file.txt" is a file in the repository
return false if empty?
return false unless target_path
rescue NoMethodError => e
true
else
raise e
end
end
protected
def build_tree(entry, tree, path_parts)
builder = Rugged::Tree::Builder.new
if tree
old_entry = nil
tree.each do |e|
old_entry = e if e[:name] == path_parts.first
end
if old_entry
if old_entry[:type] == :tree
bt_tree(builder, entry, @repo.lookup(old_entry[:oid]), path_parts)
else
bt_blob(builder, entry, path_parts)
end
else
if path_parts.size == 1
bt_blob(builder, entry, path_parts)
else
bt_tree(builder, entry, nil, path_parts)
end
end
elsif path_parts.size == 1
bt_blob(builder, entry, path_parts)
else
bt_tree(builder, entry, nil, path_parts)
end
builder.reject! do |e|
e[:type] == :tree && @repo.lookup(e[:oid]).count == 0
end
tree_oid = builder.write(@repo)
@repo.lookup(tree_oid)
end
def bt_tree(builder, entry, old_entry, path_parts)
new_tree = build_tree(entry, old_entry, path_parts[1..-1])
tree_entry = {
type: :tree,
name: path_parts.first,
oid: new_tree.oid,
filemode: 16384
}
builder.insert(tree_entry)
end
def bt_blob(builder, entry, path_parts)
if entry
entry[:name] = path_parts.first
builder.insert(entry)
else
builder.reject! { |e| e[:name] == path_parts.first }
end
end
def commit_parents
if @repo.empty?
[]
else
[head_oid]
end
end
def get_parents(rugged_commit)
[]
else
commits.identifiers(rugged_commit.parents.map { |c| c.oid }, self)
end
end
end