class Mutant::Repository::Diff
Diff index between HEAD and a tree reference
def diff_index(root)
def diff_index(root) world .capture_command(%W[git diff-index #{to}]) .bind do |status| Mutant .traverse(->(line) { parse_line(root, line) }, status.stdout.lines) .fmap do |paths| paths.to_h { |path| [path.path, path] } end end end
def parse_line(root, line)
rubocop:disable Metrics/MethodLength
def parse_line(root, line) match = FORMAT.match(line) if match Either::Right.new( Path.new( path: root.join(Util.one(match.captures)), to:, world: ) ) else Either::Left.new("Invalid git diff-index line: #{line}") end end
def repository_root
def repository_root world .capture_command(%w[git rev-parse --show-toplevel]) .fmap { |status| world.pathname.new(status.stdout.chomp) } end
def touched_path(path, &)
def touched_path(path, &) touched_paths.from_right { |message| fail Error, message }.fetch(path, &) end
def touched_paths
def touched_paths repository_root.bind(&method(:diff_index)) end
def touches?(path, line_range)
-
(RepositoryError)
-
Returns:
-
(Boolean)
-
Parameters:
-
line_range
(Range
) -- -
path
(Pathname
) --
def touches?(path, line_range) touched_path(path) { return false } .touches?(line_range) end
def touches_path?(path)
def touches_path?(path) touched_path(path) { return false } true end