forked from rust-embedded/rust-raspberrypi-OS-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit
executable file
·40 lines (30 loc) · 1.3 KB
/
pre-commit
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
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env ruby
# frozen_string_literal: true
# SPDX-License-Identifier: MIT OR Apache-2.0
#
# Copyright (c) 2018-2023 Andre Richter <[email protected]>
require_relative '../utils/devtool/copyright'
def copyright_check(staged_files)
source_files_exts = ['.S', '.rs', '.rb']
staged_files = staged_files.select do |f|
next if f.include?('build.rs')
next if f.include?('boot_test_string.rb')
f.include?('Makefile') ||
f.include?('Dockerfile') ||
source_files_exts.include?(File.extname(f))
end
return true if staged_files.empty?
copyright_check_files(staged_files)
end
## -------------------------------------------------------------------------------------------------
## Execution starts here
## -------------------------------------------------------------------------------------------------
staged_files = `git --no-pager diff --name-only --cached --diff-filter=d`.split(/\n/)
root_dir = `git rev-parse --show-toplevel`.strip
# Copyright must be fixed manually.
exit(1) unless copyright_check(staged_files)
# Brute-force format. Don't care if it affects non-staged files as well, since we only add back the
# staged ones.
Dir.chdir(root_dir) { system('ruby utils/devtool.rb fmt') }
staged_files.each { |f| system("git add #{f}") }
exit(0)