#!/usr/bin/env bash
# File generated by pre-commit: https://pre-commit.com
# ID: 138fd403232d2ddd5efb44317e38bf03

# 自定义：运行 fm 格式化暂存的 spec 文件
# fm为编译后添加到可执行目录的 spec 文件格式化工具
if command -v fm > /dev/null; then
    # 获取所有暂存的 spec 文件
    staged_specs=$(git diff --cached --name-only --diff-filter=ACM | grep '\.spec$' || true)
    
    if [ -n "$staged_specs" ]; then
        echo "正在格式化 spec 文件..."
        for spec in $staged_specs; do
            if [ -f "$spec" ]; then
                fm "$spec"
                # 重新添加格式化后的文件到暂存区
                git add "$spec"
            fi
        done
    fi
fi

# start templated
INSTALL_PYTHON=/usr/bin/python3
ARGS=(hook-impl --config=.pre-commit-config.yaml --hook-type=pre-commit)
# end templated

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

if [ -x "$INSTALL_PYTHON" ]; then
    exec "$INSTALL_PYTHON" -mpre_commit "${ARGS[@]}"
elif command -v pre-commit > /dev/null; then
    exec pre-commit "${ARGS[@]}"
else
    echo '`pre-commit` not found.  Did you forget to activate your virtualenv?' 1>&2
    exit 1
fi