BuildScripts/xcode/build_phases/multiple_swiftlint/git_caretaker.rb

35 lines
1.2 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

require_relative 'array_extension.rb'
require_relative 'command_utils.rb'
require_relative 'string_extension.rb'
class GitСaretaker < CommandUtils
def self.get_modified_files
non_indexed_files = get_files_from('git diff --name-only | sed s/.*/"&,"/ ')
indexed_files = get_files_from('git diff --cached --name-only | sed s/.*/"&,"/ ')
modified_files = non_indexed_files + indexed_files
unique_modified_files = modified_files.uniq
unique_modified_swift_files = []
if not unique_modified_files.nilOrEmpty?
unique_modified_swift_files = unique_modified_files.select { |file_path|
file_path.to_s.filter_allowed_symbol_into_path
file_path.to_s.include? '.swift'
}
end
return unique_modified_swift_files
end
def self.get_creation_date(file_path)
git_command = 'git log --follow --format=%cD --reverse -- ' + file_path + ' | head -1'
return make_command(git_command)
end
private
def self.get_files_from(command)
files_as_string = make_command(command)
return files_as_string.split(',')
end
end