aboutsummaryrefslogtreecommitdiff
path: root/tools/hooks/pre-commit.rb
blob: c224a49b467f2e12ef6ddd3d6053021ce46778d3 (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("src/**/*.h") + Dir.glob("src/**/*.cpp") + Dir.glob("lib/**/*.h") + Dir.glob("lib/**/*.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