You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.3 KiB
Ruby

#!/usr/bin/env ruby
# frozen_string_literal: true
# SPDX-License-Identifier: MIT OR Apache-2.0
#
# Copyright (c) 2018-2023 Andre Richter <andre.o.richter@gmail.com>
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)