class
Agate::Diff
- Agate::Diff
- Reference
- Object
Overview
Represents a diff between two trees, the index, or the working directory.
Included Modules
- Enumerable(Agate::Diff::Delta)
Defined in:
agate/diff.cragate/patch.cr
Constructors
-
.index_to_workdir(repo : Repository, index : Index | Nil = nil) : Diff
Diffs the index against the working directory.
-
.tree_to_index(repo : Repository, tree : Tree | Nil = nil, index : Index | Nil = nil) : Diff
Diffs a tree against the index.
-
.tree_to_tree(repo : Repository, old_tree : Tree | Nil = nil, new_tree : Tree | Nil = nil) : Diff
Diffs two trees.
-
.tree_to_workdir(repo : Repository, tree : Tree | Nil = nil) : Diff
Diffs a tree against the working directory.
Instance Method Summary
-
#deltas : Array(Delta)
Returns all deltas as an array.
-
#each(& : Delta -> ) : Nil
Iterates over all deltas.
-
#each_delta(& : Delta -> ) : Nil
Alias for each.
-
#each_line(& : Line -> ) : Nil
Iterates over all lines across all patches and hunks.
-
#find_similar! : Nil
Runs rename and copy detection on the diff.
-
#merge!(other : Diff) : Nil
Merges another diff into this one.
-
#patch : String
Returns the full patch text for the entire diff.
-
#size : Int32
Returns the number of deltas in the diff.
-
#stat : NamedTuple(files: Int32, insertions: Int32, deletions: Int32)
Returns diff statistics as {files_changed, insertions, deletions}.
-
#write_patch(io : IO) : Nil
Writes the patch text to an IO.
Constructor Detail
Diffs the index against the working directory.
Diffs a tree against the index.
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}
Diffs a tree against the working directory.
Instance Method Detail
Iterates over all lines across all patches and hunks.
Merges another diff into this one. Mutates this diff.
Returns diff statistics as {files_changed, insertions, deletions}.