Skip to content

Commit

Permalink
fix: format.sh issues (#1946)
Browse files Browse the repository at this point in the history
Fixes #1149

After this:
- circuits hook will format barretenberg. This exception turned out not
to really be necessarily as they have the same formatting rules
- barretenberg hook doesn't break commits outside of barretenberg
  • Loading branch information
ludamad authored Sep 2, 2023
1 parent c61439b commit f24814b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
6 changes: 4 additions & 2 deletions circuits/cpp/barretenberg/cpp/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ rm -rf ./build-wasm
# Install formatting git hook.
HOOKS_DIR=$(git rev-parse --git-path hooks)
# The pre-commit script will live in a barretenberg-specific hooks directory
# Find it based on the current working directory.
echo "cd $(pwd)/cpp && ./format.sh staged" > $HOOKS_DIR/pre-commit
# Find it based on the script directory.
# TODO(AD) it is a bit unintuitive that bootstrap sets one up for a barretenberg-oriented workflow
SCRIPT_PWD=`pwd` # fix: capture pwd instead of writing into script
echo "cd $SCRIPT_PWD && ./format.sh staged" > $HOOKS_DIR/pre-commit
chmod +x $HOOKS_DIR/pre-commit

# Determine system.
Expand Down
9 changes: 3 additions & 6 deletions circuits/cpp/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@ set -e

if [ "$1" == "staged" ]; then
echo Formatting staged files...
# we filter barretenberg, see #1149
for FILE in $(git diff-index --diff-filter=d --relative --cached --name-only HEAD | grep -e '\.\(cpp\|hpp\|tcc\)$' | grep -v barretenberg); do
for FILE in $(git diff-index --diff-filter=d --relative --cached --name-only HEAD | grep -e '\.\(cpp\|hpp\|tcc\)$'); do
clang-format -i $FILE
sed -i.bak 's/\r$//' $FILE && rm ${FILE}.bak
git add $FILE
done
elif [ -n "$1" ]; then
# we filter barretenberg, see #1149
for FILE in $(git diff-index --relative --name-only $1 | grep -e '\.\(cpp\|hpp\|tcc\)$' | grep -v barretenberg); do
for FILE in $(git diff-index --relative --name-only $1 | grep -e '\.\(cpp\|hpp\|tcc\)$'); do
clang-format -i $FILE
sed -i.bak 's/\r$//' $FILE && rm ${FILE}.bak
done
else
# we filter barretenberg, see #1149
for FILE in $(find ./src -iname *.hpp -o -iname *.cpp -o -iname *.tcc | grep -v src/boost | grep -v barretenberg); do
for FILE in $(find ./src -iname *.hpp -o -iname *.cpp -o -iname *.tcc | grep -v src/boost); do
clang-format -i $FILE
sed -i.bak 's/\r$//' $FILE && rm ${FILE}.bak
done
Expand Down

0 comments on commit f24814b

Please sign in to comment.