Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

Commit

Permalink
Merge 68b337d into 1f30a69
Browse files Browse the repository at this point in the history
  • Loading branch information
gin0606 committed Jul 17, 2016
2 parents 1f30a69 + 68b337d commit f096ae8
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lib/tukune/git/diff.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
require 'mem'

module Tukune
module Git
class Diff
include Mem

attr_reader :changed_files

def initialize(changed_files)
@changed_files = changed_files
def initialize(target_paths)
@target_paths = target_paths.join(' ')
end

def nothing_to_commit?
changed_files.empty?
end

def added_files
`git ls-files --others --exclude-standard`.strip.split("\n")
`git ls-files --others --exclude-standard #{@target_paths}`.strip.split("\n")
end
memoize :added_files

def modified_files
changed_files.select { |type, _| type == 'M' }.map { |_, name| name }
end
memoize :modified_files

def deleted_files
changed_files.select { |type, _| type == 'D' }.map { |_, name| name }
end
memoize :deleted_files

def changed_files
@changed_files ||= `git diff --name-status #{@target_paths}`.strip.split("\n").map { |e| e.split("\t") }
end
memoize :changed_files

class << self
def name_status
changed_files ||= `git diff --name-status`.strip.split("\n").map { |e| e.split("\t") }
Diff.new(changed_files)
def name_status(target_paths = [])
Diff.new(target_paths)
end
end
end
Expand Down

0 comments on commit f096ae8

Please sign in to comment.