Skip to content

chore(dev): add staged-file formatting pre-commit hook#269

Open
axelpey wants to merge 2 commits into
mainfrom
codex/precommit-format-modified-files
Open

chore(dev): add staged-file formatting pre-commit hook#269
axelpey wants to merge 2 commits into
mainfrom
codex/precommit-format-modified-files

Conversation

@axelpey

@axelpey axelpey commented Feb 16, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@greptile-apps

greptile-apps Bot commented Feb 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Added automated code formatting via git pre-commit hook. The hook formats only staged Python and C/C++ files using ruff and clang-format respectively, then re-stages the formatted files. Installation is handled through make install-hooks.

Key Changes:

  • Pre-commit hook with robust null-byte delimited file handling using git diff -z
  • Graceful failure if formatting tools are missing with helpful installation hints
  • Makefile target for easy hook installation via git config core.hooksPath
  • Documentation added to README with tool installation instructions

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation follows bash best practices with proper error handling (set -euo pipefail), null-byte delimited file parsing to handle filenames with spaces, file existence checks, and graceful tool availability checks. The changes are purely development tooling and won't affect production code.
  • No files require special attention

Important Files Changed

Filename Overview
.githooks/pre-commit Adds pre-commit hook to format Python and C/C++ files on staged changes
Makefile Adds install-hooks target to configure git hooks from .githooks directory
README.md Documents the new development hooks setup and usage instructions

Flowchart

flowchart TD
    A[Git Commit Triggered] --> B[Pre-commit Hook Runs]
    B --> C[Get Staged Files]
    C --> D{Any Staged Files?}
    D -->|No| E[Exit Success]
    D -->|Yes| F[Categorize by Extension]
    F --> G[Filter Python Files]
    F --> H[Filter C/C++ Files]
    G --> I{Python Files?}
    H --> J{C/C++ Files?}
    I -->|Yes| K[Check ruff Available]
    K -->|Not Found| L[Exit Error]
    K -->|Found| M[Run ruff check --fix]
    M --> N[Run ruff format]
    N --> O[Stage Formatted Files]
    I -->|No| P{Done with Python?}
    J -->|Yes| Q[Check clang-format Available]
    Q -->|Not Found| L
    Q -->|Found| R[Run clang-format -i]
    R --> S[Stage Formatted Files]
    J -->|No| T{Done with C/C++?}
    O --> P
    S --> T
    P --> J
    T --> E
Loading

Last reviewed commit: 5ccc244

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant