Class: Shiba::Review::Diff::GitDiff

Inherits:
Object
  • Object
show all
Defined in:
lib/shiba/review/diff.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ GitDiff

Valid options are: “staged”, “unstaged”, “branch”, and “verbose”



135
136
137
# File 'lib/shiba/review/diff.rb', line 135

def initialize(options)
  @options = options
end

Instance Method Details

#file(context: nil, ignore_deletions: false) ⇒ Object

Differ expects context: 0, ignore_deletions: true



159
160
161
162
163
164
# File 'lib/shiba/review/diff.rb', line 159

def file(context: nil, ignore_deletions: false)
  differ = "git diff#{cmd}"
  differ << " --unified=#{context}" if context
  differ << " --diff-filter=d"      if ignore_deletions
  run(differ)
end

#pathsObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/shiba/review/diff.rb', line 139

def paths
  if options['verbose']
    puts cmd
  end

  run = "git diff#{cmd} --name-only --diff-filter=d"

  if options[:verbose]
    $stderr.puts run
  end
  result = `#{run}`
  if $?.exitstatus != 0
    $stderr.puts result
    raise Shiba::Error.new "Failed to read changes"
  end

  result.split("\n")
end