aboutsummaryrefslogtreecommitdiff
path: root/tools/hooks/pre-commit.rb
blob: f93281cdcbfe53ae1180526e5b9ccfeb5e413b2a (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
#!/usr/bin/env ruby

result = 0
files = Dir.glob("**/*.h") + Dir.glob("**/*.cpp")

puts "pre-commit: #{`pwd`}"

puts 'Checking licenses...'
files.each { |name|
    File.open(name) { |file|
        if file.grep(/SPDX-License-Identifier/).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 "pre-commit exit(#{result})"
exit result