#!/usr/bin/env bash
# =============================================================================
# sanguo_quant_live Git 提交和推送自动化脚本
# 作者: 姜维（后勤总督）
# 版本: v1.0
# =============================================================================

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"

# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'

print_info() {
    echo -e "${BLUE}[INFO]${NC} $1"
}

print_success() {
    echo -e "${GREEN}[SUCCESS]${NC} $1"
}

print_warning() {
    echo -e "${YELLOW}[WARNING]${NC} $1"
}

print_error() {
    echo -e "${RED}[ERROR]${NC} $1"
}

cd "$PROJECT_ROOT"

# 检查是否有变更
if git diff --quiet && git diff --cached --quiet; then
    print_warning "没有变更需要提交"
    exit 0
fi

# 获取 commit message
COMMIT_MSG="${1:-更新调研内容}"

print_info "添加变更..."
git add -A

print_info "提交变更..."
git commit -m "$COMMIT_MSG"

print_info "推送到 Gitee..."
git push origin main

print_success "Git 提交和推送完成！"
