Use git to check for empty index.
This commit is contained in:
parent
47363ad14b
commit
2e59062454
3 changed files with 65 additions and 3 deletions
|
@ -17,6 +17,17 @@ module FormatStaged
|
|||
output
|
||||
end
|
||||
|
||||
def get_status(*args)
|
||||
puts "> #{args.join(' ')}" if @verbose
|
||||
result = system(*args)
|
||||
|
||||
raise 'Failed to run command' if result.nil?
|
||||
|
||||
puts "? #{$CHILD_STATUS.exitstatus}" if @verbose
|
||||
|
||||
$CHILD_STATUS.exitstatus
|
||||
end
|
||||
|
||||
def pipe_command(*args, source: nil)
|
||||
puts (source.nil? ? '> ' : '| ') + args.join(' ') if @verbose
|
||||
r, w = IO.pipe
|
||||
|
|
|
@ -36,7 +36,10 @@ module FormatStaged
|
|||
|
||||
formatted = files.filter { |file| format_file file }
|
||||
|
||||
!formatted.empty?
|
||||
return false unless formatted.size == files.size
|
||||
|
||||
quiet = @verbose ? [] : ['--quiet']
|
||||
return get_status('git', 'diff-index', '--cached', '--exit-code', *quiet, 'HEAD') != 0
|
||||
end
|
||||
|
||||
def repo_root
|
||||
|
@ -76,7 +79,7 @@ module FormatStaged
|
|||
|
||||
if new_hash == file.src_hash
|
||||
info "File #{file.src_path} equal to comitted"
|
||||
return false
|
||||
return true
|
||||
end
|
||||
|
||||
true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue