Skip to content

Commit

Permalink
Merge pull request #141 from quadratic-funding/fix-hook
Browse files Browse the repository at this point in the history
Fix unable to run pre-commit hook in Ubuntu
  • Loading branch information
daodesigner authored Jun 23, 2022
2 parents 9fa702e + 839fa1f commit af01221
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
37 changes: 3 additions & 34 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,37 +1,6 @@
#!/bin/sh

BASE_DIR="$( cd "$( dirname "$0" )" && pwd )"

# Return `true` if files under `packages/contracts/contracts/` directory has been changed or added. Otherwise, return `false`
is_contracts_changed()
{
result="false"
git_changes=$(git diff --cached --name-status)

while read -r line; do
changed_file_path=$(echo "$line" | awk '/packages/ {print $2}')
file_status=$(echo "$line" | cut -c 1)

if [ "$file_status" = 'A' ] || [ "$file_status" = 'M' ]
then
case $changed_file_path in packages/contracts/contracts/*)
result="true"
esac
fi
done <<< "$git_changes"

echo "$result"
}


. "$(dirname "$0")/_/husky.sh"


# Check lint for all subpackage
npx lint-staged

RETURN_CODE=$(is_contracts_changed)
if [ $RETURN_CODE = "true" ]; then
# Run contract tests
npx yarn workspace @quadratic-funding/contracts typechain
npx yarn workspace @quadratic-funding/contracts test:unit
fi
bash "$BASE_DIR"/scripts/_pre-commit
exit "$?"
32 changes: 32 additions & 0 deletions .husky/scripts/_pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# Return `true` if files under `packages/contracts/contracts/` directory has been changed or added. Otherwise, return `false`
is_contracts_changed()
{
result="false"
git_changes=$(git diff --cached --name-status)

while read -r line; do
changed_file_path=$(echo "$line" | awk '/packages/ {print $2}')
file_status=$(echo "$line" | cut -c 1)

if [ "$file_status" = 'A' ] || [ "$file_status" = 'M' ]
then
case $changed_file_path in packages/contracts/contracts/*)
result="true"
esac
fi
done <<< "$git_changes"

echo "$result"
}

# Check lint for all subpackage
npx lint-staged

RETURN_CODE=$(is_contracts_changed)
if [ $RETURN_CODE = "true" ]; then
# Run contract tests
npx yarn workspace @quadratic-funding/contracts typechain
npx yarn workspace @quadratic-funding/contracts test:unit
fi

0 comments on commit af01221

Please sign in to comment.