Describe the bug
The current binary file detection logic in [pre-commit.sh](# Pre-commit hook to check for binary files.) (introduced in #5525) uses the file --mime command to identify binary files, but this approach leads to false positives for non-binary text-based files like: .textproto, .json, .xml, .txt, .proto, .md.
if file --mime "$file" | grep -q 'binary'; then
Steps To Reproduce
- Introduce a new
.textproto or .md file locally.
- Run the
scripts/pre-commit.sh script.
- The script will fail with:
Please remove the 1 detected binary file(s).
BINARY FILES CHECK FAILED
- Even though the files are valid text files.
This issue was recently observed in a PR #5836 where new .textproto files were introduced but mistakenly identified as binary files.

Expected Behavior
Text files such as .txt, .md, .json, .xml, .textproto should NOT be classified as binary. These files are human-readable and should be allowed in commits without triggering binary file check failures.
Binary files include formats such as:
- Images:
.png, .jpeg, .jpg, .gif, .bmp, .webp
- Videos:
.mp4, .mov, .avi, .mkv
- Archives and executables:
.zip, .tar, .gz, .exe, .bin
- Compiled objects and libraries:
.class, .so, .dll
- Other binary data files
The check should only flag and fail on actual binary files to prevent unwanted binary files in the repository. Files that are text-based or human-readable should pass the binary check without warnings or failures.
Proposed / Alternate Approach:
An alternative is to use Git’s own diff statistics:
base_commit=$(git merge-base origin/develop HEAD)
binary_files=$(git diff --numstat "$base_commit"...HEAD | awk '$1 == "-" && $2 == "-" { print $3 }')
This approach was tested in the fork PR and appeared to correctly detect only genuine binary files (e.g., images), without false positives on text files.

It’s important to test different edge cases —or to check with team and see maybe introducing a Kotlin script with proper testing could be a more sustainable solution to avoid future regressions.
Additional Context
Additional Findings / Suggestions:
- Extending Pre-commit Hook: Currently, the pre-commit script was only setup to check for binary files. It could be refactored to allow running multiple checks by move the existing binary file check into a separate script (e.g.,
binary-files-check.sh) and have the main pre-commit hook call this script..
- Executable Permissions: Some of these scripts may require executable permissions to run properly. It could be useful to clarify whether executable permissions should be automatically set or whether explicit documentation should be provided to enable them.
- Formatting colors in CI: The sourcing of the
formatting.sh did not embed color codes in the CI, while utilizing color codes right from the file, does work.
Describe the bug
The current binary file detection logic in [pre-commit.sh](# Pre-commit hook to check for binary files.) (introduced in #5525) uses the file --mime command to identify binary files, but this approach leads to false positives for non-binary text-based files like:
.textproto,.json,.xml,.txt,.proto,.md.Steps To Reproduce
.textprotoor.mdfile locally.scripts/pre-commit.shscript.This issue was recently observed in a PR #5836 where new
.textprotofiles were introduced but mistakenly identified as binary files.Expected Behavior
Text files such as
.txt,.md,.json,.xml,.textprotoshould NOT be classified as binary. These files are human-readable and should be allowed in commits without triggering binary file check failures.Binary files include formats such as:
.png,.jpeg,.jpg,.gif,.bmp,.webp.mp4,.mov,.avi,.mkv.zip,.tar,.gz,.exe,.bin.class,.so,.dllThe check should only flag and fail on actual binary files to prevent unwanted binary files in the repository. Files that are text-based or human-readable should pass the binary check without warnings or failures.
Proposed / Alternate Approach:
An alternative is to use Git’s own diff statistics:
This approach was tested in the fork PR and appeared to correctly detect only genuine binary files (e.g., images), without false positives on text files.
Additional Context
Additional Findings / Suggestions:
binary-files-check.sh) and have the main pre-commit hook call this script..formatting.shdid not embed color codes in the CI, while utilizing color codes right from the file, does work.