File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ To reuse these githooks, run the following command after cloning the repository:
2+ ```
3+ git config core.hooksPath githooks
4+ ```
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # Get list of Python files that are staged for commit
4+ files=$( git diff --cached --name-only --diff-filter=d | grep ' \.py$' | grep -v ' ^ir/lib/' )
5+
6+ if [ -z " $files " ]; then
7+ # No Python files to format
8+ exit 0
9+ fi
10+
11+ echo " Running code formatting on staged files..."
12+
13+ # Create a temporary file to store the file list
14+ temp_file=$( mktemp)
15+ echo " $files " > " $temp_file "
16+
17+ # Format only the staged files
18+ poetry run black --quiet $( cat " $temp_file " )
19+ poetry run isort --quiet $( cat " $temp_file " )
20+
21+ # Clean up
22+ rm " $temp_file "
23+
24+ # Add the formatted files back to staging
25+ if ! git diff --quiet; then
26+ echo " Code formatting created changes. Adding them to the commit..."
27+ git add $files
28+ fi
29+
30+ exit 0
You can’t perform that action at this time.
0 commit comments