diff --git a/scripts/just/check-hooks.sh b/scripts/just/check-hooks.sh new file mode 100755 index 00000000..ce5f4517 --- /dev/null +++ b/scripts/just/check-hooks.sh @@ -0,0 +1,36 @@ +#! /usr/bin/env bash +set -e + +HOOK_SCRIPT=$1 +HOOKS=$2 + +TEMPLATE="$HOOK_SCRIPT" +OUTDATED=() +MISSING=0 +TOTAL=0 + +for hook in $HOOKS; do + TOTAL=$((TOTAL + 1)) + if [ ! -f ".git/hooks/$hook" ]; then + MISSING=$((MISSING + 1)) + OUTDATED+=("$hook") + elif ! cmp -s "$TEMPLATE" ".git/hooks/$hook"; then + OUTDATED+=("$hook") + fi +done + +if [ "$MISSING" -eq "$TOTAL" ] && [ "$TOTAL" -gt 0 ]; then + echo "" + echo "${HINT}No git hooks are installed. Run 'just install-hooks' to install them.${NORMAL}" + echo "" +elif [ ${#OUTDATED[@]} -gt 0 ]; then + echo "" + echo "${WARN}WARNING: The following git hooks are missing or out of date:${NORMAL}" + echo "" + for hook in "${OUTDATED[@]}"; do + echo -e "\t$hook" + done + echo "" + echo "${HINT}Check them with 'diff $HOOK_SCRIPT .git/hooks/' then run 'just install-hooks'${NORMAL}" + echo "" +fi diff --git a/scripts/just/check-keywords.sh b/scripts/just/check-keywords.sh new file mode 100755 index 00000000..ed557e48 --- /dev/null +++ b/scripts/just/check-keywords.sh @@ -0,0 +1,24 @@ +#! /usr/bin/env bash +set -e +echo "${CHECK}Checking for forbidden words in staged files...${NORMAL}" + +# Get staged Rust files +STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACMR | grep '\.rs$' || true) + +if [ -n "$STAGED_FILES" ]; then + if echo "$STAGED_FILES" | xargs rg --context=3 --fixed-strings 'radicle.xyz'; then + exit 1 + fi + + if echo "$STAGED_FILES" | xargs rg --context=3 --fixed-strings 'radicle.zulipchat.com'; then + exit 1 + fi + + # For `git2::` we need to exclude raw.rs + FILTERED_GIT2=$(echo "$STAGED_FILES" | grep '^crates/radicle/.*\.rs$' | grep -v 'crates/radicle/src/git/raw.rs' || true) + if [ -n "$FILTERED_GIT2" ]; then + if echo "$FILTERED_GIT2" | xargs rg --context=3 --fixed-strings 'git2::'; then + exit 1 + fi + fi +fi diff --git a/scripts/just/format-nix.sh b/scripts/just/format-nix.sh new file mode 100755 index 00000000..f8c6a9a3 --- /dev/null +++ b/scripts/just/format-nix.sh @@ -0,0 +1,7 @@ +#! /usr/bin/env bash + +if command -v alejandra >/dev/null 2>&1; then + alejandra --check . +else + echo "⏭️ alejandra not found, skipping Nix formatting." +fi diff --git a/scripts/just/install-hooks.sh b/scripts/just/install-hooks.sh new file mode 100755 index 00000000..5f7439ba --- /dev/null +++ b/scripts/just/install-hooks.sh @@ -0,0 +1,18 @@ +#! /usr/bin/env bash +set -e + +HOOK_SCRIPT=$1 +HOOKS=$2 + +read -r -p "Overwrite existing hooks '${HOOKS}'? [y/N] " confirm +[[ "$confirm" == "y" ]] || exit 1 + +for hook in $HOOKS; do + if [ -f ".git/hooks/$hook" ]; then + rm ".git/hooks/$hook" + fi + cp "$HOOK_SCRIPT" ".git/hooks/$hook" + chmod +x ".git/hooks/$hook" +done +echo "" +echo "${SUCCESS}Hooks installed: ${HOOKS}${NORMAL}" diff --git a/scripts/just/verify-tool.sh b/scripts/just/verify-tool.sh new file mode 100755 index 00000000..ebb584a6 --- /dev/null +++ b/scripts/just/verify-tool.sh @@ -0,0 +1,11 @@ +#! /usr/bin/env bash +set -e +TOOL=$1 +PKG_NAME=$2 + +if ! command -v "$TOOL" >/dev/null 2>&1; then + PKG="${PKG_NAME:-$TOOL}" + echo "${ERROR}Missing required tool: ${TOOL}${NORMAL}" + echo "${HINT}Use your systems package manager to install '$PKG'.${NORMAL}" + exit 1 +fi