|
1 | | - #!/bin/sh |
2 | | - # to enable: |
3 | | - # git config core.hooksPath .githooks |
4 | | - # Define the maximum allowed file size in bytes (e.g., 10MB) |
5 | | - # MAX_FILE_SIZE_BYTES=10485760 |
6 | | - MAX_FILE_SIZE_BYTES=1048 |
| 1 | +#!/bin/sh |
| 2 | +# to enable this hook run: |
| 3 | +# git config core.hooksPath .githooks |
| 4 | +# also, run this: git config --global core.excludesfile ~/.gitignore_global |
| 5 | +# Define the maximum allowed file size in bytes (e.g., 10MB) |
| 6 | +MAX_FILE_SIZE_BYTES=10485760 |
7 | 7 |
|
8 | | - # Get a list of added files in the current commit |
9 | | - ADDED_FILES=$(git diff --cached --name-only --diff-filter=A) |
| 8 | +# Get a list of added files in the current commit |
| 9 | +ADDED_FILES=$(git diff --cached --name-only --diff-filter=A) |
10 | 10 |
|
11 | | - for FILE in $ADDED_FILES; do |
12 | | - if [ -f "$FILE" ]; then |
13 | | - FILE_SIZE=$(wc -c < "$FILE") |
14 | | - if [ "$FILE_SIZE" -gt "$MAX_FILE_SIZE_BYTES" ]; then |
15 | | - echo "Error: File '$FILE' is too large ($FILE_SIZE bytes). Maximum allowed size is $MAX_FILE_SIZE_BYTES bytes." |
16 | | - exit 1 # Exit with a non-zero status to prevent the commit |
17 | | - fi |
| 11 | +for FILE in $ADDED_FILES; do |
| 12 | + if [ -f "$FILE" ]; then |
| 13 | + FILE_SIZE=$(wc -c < "$FILE") |
| 14 | + if [ "$FILE_SIZE" -gt "$MAX_FILE_SIZE_BYTES" ]; then |
| 15 | + echo "Error: File '$FILE' is too large ($FILE_SIZE bytes). Maximum allowed size is $MAX_FILE_SIZE_BYTES bytes." |
| 16 | + exit 1 # Exit with a non-zero status to prevent the commit |
18 | 17 | fi |
19 | | - done |
| 18 | + fi |
| 19 | +done |
20 | 20 |
|
21 | | - exit 0 # Allow the commit to proceed |
| 21 | +exit 0 # Allow the commit to proceed |
0 commit comments