From 4488f10038b5100237207c9bffdfa7e30a7c059b Mon Sep 17 00:00:00 2001 From: seafoodfry <99568361+seafoodfry@users.noreply.github.com> Date: Fri, 12 Jul 2024 15:24:33 -0400 Subject: [PATCH] Made pre-commit work in sillicon macos and linux While running the previous version of the precommit I got the following error: ``` Found configured hook: pre-commit Running command: sh pre-commit Fetching advisory database from `https://github.com/RustSec/advisory-db.git` Updating crates.io index Scanning Cargo.lock for vulnerabilities (184 crate dependencies) src/jailer/src/env.rs sed: illegal option -- z usage: sed script [-Ealnru] [-i extension] [file ...] sed [-Ealnu] [-i extension] [-e script] ... [-f script_file] ... [file ...] Configured hook command failed pre-commit hook rejected ``` Tested a couple different things and the `paste` command seemed to work both on macos (M1) and on linux (tested it in an ubuntu:22.04 container). Signed-off-by: seafoodfry <99568361+seafoodfry@users.noreply.github.com> --- pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pre-commit b/pre-commit index 1f404656d93..cab8e7773b3 100755 --- a/pre-commit +++ b/pre-commit @@ -23,7 +23,7 @@ for i in $(git diff --name-only --cached --diff-filter=d); do extension="${filename##*.}" if [ "$extension" = "rs" ]; then # Read rustfmt config, replace '\n' with ',' - rustfmt_config="$(sed -z "s/\n/,/g;s/,$/\n/" ./tests/fmt.toml)" + rustfmt_config="$(paste -sd, ./tests/fmt.toml)" # We first do a check run, this will fail when it finds a non-matching license. rustfmt $i --check --config $rustfmt_config # Run `cargo fmt` for this file