File: pre-commit

package info (click to toggle)
ruby-puppet-resource-api 1.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,232 kB
  • sloc: ruby: 9,573; sh: 4; makefile: 2
file content (18 lines) | stat: -rwxr-xr-x 528 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/env ruby
# frozen_string_literal: true

# Code modified from: https://gist.github.com/hanloong/9849098
require 'English'

changed_files = `git diff --name-only --cached --diff-filter=ACM`.split(%r{\n})
changed_files = changed_files.select { |file_name|
  File.extname(file_name) == '.rb'
}.join(' ')

system("bundle exec rubocop -a #{changed_files}") unless changed_files.empty?

if $CHILD_STATUS.to_s[-1].to_i.zero? && !changed_files.empty?
  system("git add #{changed_files}")
end

exit $CHILD_STATUS.to_s[-1].to_i