class Agate::Diff

Overview

Represents a diff between two trees, the index, or the working directory.

Included Modules

Defined in:

agate/diff.cr
agate/patch.cr

Constructors

Instance Method Summary

Constructor Detail

def self.index_to_workdir(repo : Repository, index : Index | Nil = nil) : Diff #

Diffs the index against the working directory.


[View source]
def self.tree_to_index(repo : Repository, tree : Tree | Nil = nil, index : Index | Nil = nil) : Diff #

Diffs a tree against the index.


[View source]
def self.tree_to_tree(repo : Repository, old_tree : Tree | Nil = nil, new_tree : Tree | Nil = nil) : Diff #

Diffs two trees. Either tree can be nil (treated as empty).

diff = Diff.tree_to_tree(repo, old_tree, new_tree)
diff.each do |delta|
  puts "#{delta.status}: #{delta.new_file.path}"
end
puts diff.stat # => {files: 3, insertions: 10, deletions: 5}

[View source]
def self.tree_to_workdir(repo : Repository, tree : Tree | Nil = nil) : Diff #

Diffs a tree against the working directory.


[View source]

Instance Method Detail

def deltas : Array(Delta) #

Returns all deltas as an array.


[View source]
def each(& : Delta -> ) : Nil #

Iterates over all deltas.


[View source]
def each_delta(& : Delta -> ) : Nil #

Alias for each.


[View source]
def each_line(& : Line -> ) : Nil #

Iterates over all lines across all patches and hunks.


[View source]
def find_similar! : Nil #

Runs rename and copy detection on the diff. Mutates the diff.


[View source]
def merge!(other : Diff) : Nil #

Merges another diff into this one. Mutates this diff.


[View source]
def patch : String #

Returns the full patch text for the entire diff.


[View source]
def size : Int32 #

Returns the number of deltas in the diff.


[View source]
def stat : NamedTuple(files: Int32, insertions: Int32, deletions: Int32) #

Returns diff statistics as {files_changed, insertions, deletions}.


[View source]
def write_patch(io : IO) : Nil #

Writes the patch text to an IO.


[View source]