Skip to content

Commit

Permalink
Forbid binary files in commits (#792)
Browse files Browse the repository at this point in the history
This hook triggers on all non-excluded binary files.

To exclude a file from this check, add it to the `excludes` section in
`tools/pre-commit-hooks.nix`.

Should prevent issues like #791 in the future.
  • Loading branch information
aaronmondal authored Mar 26, 2024
1 parent 09defc6 commit d9fc4ad
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tools/pre-commit-hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,29 @@ in {
entry = "${pkgs.python311Packages.pre-commit-hooks}/bin/detect-private-key";
types = ["text"];
};
forbid-binary-files = {
excludes = [
# Landing page image for the website.
"nativelink-docs/static/img/hero-dark.png"

# Testdata for fastcdc.
"nativelink-util/tests/data/SekienAkashita.jpg"
];
enable = true;
types = ["binary"];
entry = let
script = pkgs.writeShellScriptBin "forbid-binary-files" ''
set -eu
if [ $# -gt 0 ]; then
for filename in "''${@}"; do
printf "[\033[31mERROR\033[0m] Found binary file: ''${filename}"
done
exit 1
fi
'';
in "${script}/bin/forbid-binary-files";
};

# Documentation
vale.enable = true;
Expand Down

0 comments on commit d9fc4ad

Please sign in to comment.