aboutsummaryrefslogtreecommitdiff
path: root/tools/hooks/pre-commit.rb
blob: ffc710c5295fb7ca6d256dd3ca0ef2d03ec3f99f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env ruby

result = 0
files = Dir['src/**/*.h'] + Dir['src/**/*.cpp'] - Dir['src/3rd-party/**/*']

puts "Running in #{`pwd`}"

puts 'Checking licenses...'
files.each { |name|
    File.open(name) { |file|
        if file.grep(/Copyright\s\(C\)\s(\d{4}\s*-\s*){0,1}(#{Time.now.year})/).empty? then
            puts "Missing or incorrect license header: #{name}"
            result = 1
        end
    }
}

puts 'Running astyle...'
if not `astyle --dry-run --formatted --options=astyle.rc #{files.join(' ')}`.empty? then
    system "astyle --verbose --suffix=none --formatted --options=astyle.rc #{files.join(' ')}"
    result = 1
end

#puts 'Running cppcheck...'
#`cppcheck --quiet --enable=all --inconclusive --std=posix -I src/ .`

puts "pre-commit exit(#{result})"
exit result