just: Extract inline bash scripts out to files
Enables `shellcheck` checking.
This commit is contained in:
parent
df31702b8b
commit
6744384acf
|
|
@ -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/<hook name>' then run 'just install-hooks'${NORMAL}"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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}"
|
||||||
|
|
@ -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
|
||||||
Loading…
Reference in New Issue