ark-r1cs-std/.hooks/pre-commit
.hooks/pre-commitRaw
1#!/usr/bin/env bash
2
3rustfmt --version &>/dev/null
4if [ $? != 0 ]; then
5 printf "[pre_commit] \033[0;31merror\033[0m: \"rustfmt\" not available. \n"
6 printf "[pre_commit] \033[0;31merror\033[0m: rustfmt can be installed via - \n"
7 printf "[pre_commit] $ rustup component add rustfmt \n"
8 exit 1
9fi
10
11problem_files=()
12
13# collect ill-formatted files
14for file in $(git diff --name-only --cached); do
15 if [ ${file: -3} == ".rs" ]; then
16 rustfmt +nightly --check $file &>/dev/null
17 if [ $? != 0 ]; then
18 problem_files+=($file)
19 fi
20 fi
21done
22
23if [ ${#problem_files[@]} == 0 ]; then
24 # done
25 printf "[pre_commit] rustfmt \033[0;32mok\033[0m \n"
26else
27 # reformat the files that need it and re-stage them.
28 printf "[pre_commit] the following files were rustfmt'd before commit: \n"
29 for file in ${problem_files[@]}; do
30 rustfmt $file
31 git add $file
32 printf "\033[0;32m $file\033[0m \n"
33 done
34fi
35
36exit 0