From caececad050926235aa755fb4b2d55a587b67b72 Mon Sep 17 00:00:00 2001 From: Dylan Donahue Date: Wed, 4 Sep 2024 19:35:32 -0400 Subject: [PATCH] pre commit stuff --- .pre-commit-config.yaml | 18 +++++++++--------- clang_restage.py | 14 +++++++++++--- ner_setup.py | 2 +- requirements.txt | 2 +- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d258903..570ca9b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,10 +1,10 @@ -fail_fast: false repos: - - repo: local - hooks: - - id: clang-format - name: Run Clang Format - entry: clang_restage - language: script - files: \.(c|cpp|h|hpp)$ - stages: [pre-commit] \ No newline at end of file + - repo: local + hooks: + - id: clang_restage + name: Restage formatted files + entry: clang_restage + language: system + pass_filenames: false + always_run: true + stages: [pre-commit] \ No newline at end of file diff --git a/clang_restage.py b/clang_restage.py index a4597f4..118ea59 100644 --- a/clang_restage.py +++ b/clang_restage.py @@ -3,8 +3,16 @@ import os def get_staged_files(): + # Run the git command to get staged files result = subprocess.run(['git', 'diff', '--cached', '--name-only'], stdout=subprocess.PIPE, text=True) - return result.stdout.splitlines() + + # Get the list of staged files from stdout + staged_files = result.stdout.splitlines() + + # Filter files based on their extensions + filtered_files = [f for f in staged_files if f.endswith(('.c', '.cpp', '.h'))] + + return filtered_files def restage_files(files): if files: @@ -17,8 +25,8 @@ def main(): staged_files = get_staged_files() # Run clang-format on staged files - result = subprocess.run(['clang-format', '-i', '--style=file', '--fallback-style=Google'] + staged_files, - ) + result = subprocess.run(['clang-format', '--style=file', '-i'] + staged_files, + capture_output=True, text=True) if result.returncode == 0: restage_files(staged_files) diff --git a/ner_setup.py b/ner_setup.py index 4d09ba1..e9c5e9b 100644 --- a/ner_setup.py +++ b/ner_setup.py @@ -119,7 +119,7 @@ def install_usbip(): else: print("We haven't added USBIP install support for your distro, but if you're actually on linux, you can install it manually!") else: - print("You should only see this if im stupid! Let someone know if you see this message") + print("You should only see this if im stupid! Let someone know if you see this message -> ID=STUPID1") def main(): print("Welcome to NER Embedded Software! If this script shits the bed, let your system head or lead know!") diff --git a/requirements.txt b/requirements.txt index 085df7d..51af454 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ distro pre-commit -pyserial \ No newline at end of file +clang-format