Error out if negative pattern is specified

This commit is contained in:
Sven Weidauer 2022-05-29 10:34:50 +02:00
parent 9339382f59
commit 6fd8bb9ce7

View file

@ -13,6 +13,8 @@ class FormatStaged
attr_reader :formatter, :patterns, :update, :write, :verbose
def initialize(formatter:, patterns:, **options)
validate_patterns patterns
@formatter = formatter
@patterns = patterns
@update = options.fetch(:update, true)
@ -126,4 +128,10 @@ class FormatStaged
def replace_file_in_index(file, new_hash)
get_output 'git', 'update-index', '--cacheinfo', "#{file.dst_mode},#{new_hash},#{file.src_path}"
end
def validate_patterns(patterns)
patterns.each do |pattern|
fail! "Negative pattern '#{pattern}' is not yet supported" if pattern.start_with? '!'
end
end
end