Skip to content

Commit

Permalink
pre commit stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
dyldonahue committed Sep 4, 2024
1 parent 1f91af3 commit caececa
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
18 changes: 9 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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]
- repo: local
hooks:
- id: clang_restage
name: Restage formatted files
entry: clang_restage
language: system
pass_filenames: false
always_run: true
stages: [pre-commit]
14 changes: 11 additions & 3 deletions clang_restage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ner_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
distro
pre-commit
pyserial
clang-format

0 comments on commit caececa

Please sign in to comment.