Class: Mutant::Repository::Diff

Inherits:
Object
  • Object
show all
Includes:
Adamantium
Defined in:
lib/mutant/repository.rb

Overview

Diff between two objects in repository

Constant Summary collapse

HEAD =
'HEAD'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_head(to) ⇒ Diff

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create diff from head to revision

Returns:



35
36
37
# File 'lib/mutant/repository.rb', line 35

def self.from_head(to)
  new(HEAD, to)
end

Instance Method Details

#touches?(path, line_range) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Test if diff changes file at line range

Parameters:

  • path (Pathname)
  • line_range (Range<Fixnum>)

Returns:

  • (Boolean)

Raises:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/mutant/repository.rb', line 50

def touches?(path, line_range)
  return false unless within_working_directory?(path) && tracks?(path)

  command = %W[
    git log
    #{from}...#{to}
    -L #{line_range.begin},#{line_range.end}:#{path}
  ]

  stdout, status = Open3.capture2(*command, binmode: true)

  fail RepositoryError, "Command #{command} failed!" unless status.success?

  !stdout.empty?
end