ulib/3party/sqlpp11/pre-commit
tqcq 9ec8eb952e
All checks were successful
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Successful in 1m11s
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Successful in 1m22s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Successful in 1m27s
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Successful in 1m29s
linux-x64-gcc / linux-gcc (push) Successful in 1m55s
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Successful in 3m17s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (pull_request) Successful in 1m9s
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (pull_request) Successful in 1m14s
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (pull_request) Successful in 1m20s
linux-x64-gcc / linux-gcc (pull_request) Successful in 1m24s
linux-mips64-gcc / linux-gcc-mips64el (push) Successful in 4m26s
linux-mips64-gcc / linux-gcc-mips64el (pull_request) Successful in 1m43s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (pull_request) Successful in 1m55s
linux-hisiv500-gcc / linux-gcc-hisiv500 (pull_request) Successful in 4m8s
fix use mirror repository of date
2024-01-06 21:51:10 +08:00

71 lines
2.4 KiB
Python
Executable File

#!/usr/bin/env python3
import functools
import os
from pprint import pprint
import re
import subprocess
import sys
class ValidationError(Exception): pass
def check_output(cmd, expect_process_error=False):
try:
return subprocess.check_output(cmd)
except Exception as e:
if not expect_process_error or not isinstance(e, subprocess.CalledProcessError):
print('Exception while running cmd %s' % (cmd,))
raise
def changes():
return check_output(('git', 'diff', '--no-ext-diff', '--cached', '-U0'))
def toplevel():
return check_output(('git', 'rev-parse', '--show-toplevel')).strip(b'\n').decode('utf-8')
def toList(fn):
return functools.wraps(fn)(lambda *args, **kwargs: list(fn(*args, **kwargs)))
top = toplevel()
clangformat = "/usr/local/clang_3_6_0/bin/clang-format"
### CLANG-FORMAT BEGIN
if os.path.exists(os.path.join(top, '.clang-format')):
reformatted_files = []
files_had_unstaged_edits = []
for filename in check_output(['git', 'diff-index', '--cached', '--name-only', 'HEAD']).decode('utf-8').splitlines():
if any(filename.endswith(ext) for ext in ('.cpp', '.h', '.hpp')):
file_path = os.path.join(top, filename)
with open(file_path, 'rb') as f:
staged = f.read()
formatted = check_output([clangformat, file_path])
if staged == formatted:
continue
try:
check_output(['git', 'diff', '--exit-code', file_path], expect_process_error=True)
except subprocess.CalledProcessError:
files_had_unstaged_edits.append(filename)
check_output([clangformat, '-i', file_path])
try:
check_output(['git', 'diff', '--exit-code', file_path], expect_process_error=True)
except subprocess.CalledProcessError:
reformatted_files.append(filename)
if reformatted_files:
print('These files were reformatted with clang-format, please stage the changes first:\n- %s'
% '\n- '.join(reformatted_files), file=sys.stderr)
if files_had_unstaged_edits:
print('\nThese files had unstaged edits before clang-format reformatting. Please stage desired parts and confirm the commit again.\n- %s'
% '\n- '.join(files_had_unstaged_edits), file=sys.stderr)
if reformatted_files or files_had_unstaged_edits:
exit(1)
### CLANG-FORMAT END
exit(0)