Skip to content

Commit

Permalink
fixed hook
Browse files Browse the repository at this point in the history
  • Loading branch information
dyldonahue committed Sep 3, 2024
1 parent 7746773 commit d5c7038
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
26 changes: 6 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
fail_fast: false
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v14.0.0 # Specify the version of clang-format you want to use
hooks:
- id: clang-format
name: Apply clang-format
description: Run clang-format to check and fix C/C++ files
types: [c, c++]
files: \.(c|h|cpp|hpp|cc|cxx|hxx)$
args:
- --style=file
exclude: |
^(?!.*\.clang-format-ignore).*$
additional_dependencies: []

- repo: local
hooks:
- id: clang_restage
name: Restage formatted files
- id: clang-format
name: Run Clang Format
entry: clang_restage
language: system
pass_filenames: false
always_run: true
stages: [commit]
language: script
files: \.(c|cpp|h|hpp)$
stages: [pre-commit]
6 changes: 5 additions & 1 deletion clang_restage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import subprocess
import sys
import os

def get_staged_files():
result = subprocess.run(['git', 'diff', '--cached', '--name-only'], stdout=subprocess.PIPE, text=True)
Expand All @@ -14,9 +15,12 @@ def restage_files(files):
def main():
# Get a list of staged files
staged_files = get_staged_files()



# Run clang-format on staged files
result = subprocess.run(['pre-commit', 'run', 'clang-format', '--files'] + staged_files)
result = subprocess.run(['clang-format', '-i', '--style=file', '--fallback-style=Google'] + staged_files,
)

if result.returncode == 0:
restage_files(staged_files)
Expand Down

0 comments on commit d5c7038

Please sign in to comment.