#!/usr/bin/env bash
# File generated by pre-commit: https://pre-commit.com
# ID: 138fd403232d2ddd5efb44317e38bf03
# Modified to use relative paths instead of hardcoded paths
# Added Git Flow hint display

# Run git-flow check and display hint information
run_git_flow_check() {
    if command -v uv > /dev/null 2>&1; then
        echo ""
        echo "=== Git Flow Status ==="
        echo "=== Git Flow 状态 ==="
        uv run wl git-flow check 2>/dev/null | grep -E "^(Git Flow check:|Branch:|Type:|Source:|Target:|Rule:|Fix:|Config:)"
        echo "=============================="
    fi
}

# start templated
# Try to detect Python from common virtual environments
venv_paths=("./.venv/bin/python" "./.venv/bin/python3" "../.venv/bin/python" "../.venv/bin/python3" "../../.venv/bin/python" "../../.venv/bin/python3")
args=(hook-impl --config=.wl/.pre-commit-config.yaml --hook-type=pre-commit)
# end templated

HERE="$(cd "$(dirname "$0")" && pwd)"
args+=(--hook-dir "$HERE" -- "$@")

# Run Git Flow check before pre-commit
run_git_flow_check

# Try to find the Python executable in virtual environments
for PYTHON in "${venv_paths[@]}"; do
    if [ -x "$PYTHON" ]; then
        exec "$PYTHON" -mpre_commit "${args[@]}"
        exit 0
    fi
done

# If no virtual environment Python found, try system pre-commit
if command -v pre-commit > /dev/null; then
    exec pre-commit "${args[@]}" 2>&1
fi

# If all fails, show error message
echo '`pre-commit` not found.  Did you forget to activate your virtualenv?' 1>&2
exit 1
