You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
slms/scripts/setup_git_repository.bat

118 lines
2.9 KiB

@echo off
chcp 65001 >nul
echo ============================================================================
echo Git 仓库设置脚本
echo ============================================================================
echo.
echo 此脚本将:
echo 1. 检查或初始化 Git 仓库
echo 2. 添加所有文件到 Git
echo 3. 创建初始提交
echo 4. 配置本地 Gitea 远程仓库
echo 5. 推送到本地 Gitea
echo.
echo 警告: 此操作将强制推送到远程仓库!
echo.
pause
echo.
echo [1/6] 检查 Git 仓库状态...
if exist .git (
echo ✓ Git 仓库已存在
) else (
echo 初始化 Git 仓库...
git init
if %errorlevel% neq 0 (
echo ✗ Git 初始化失败
pause
exit /b 1
)
echo ✓ Git 仓库已初始化
)
echo.
echo [2/6] 配置 Git 用户信息...
git config user.name "Jenkins CI" 2>nul
git config user.email "ldl@chzu.edu.cn" 2>nul
echo ✓ Git 用户信息已配置
echo.
echo [3/6] 添加所有文件到 Git...
git add .
if %errorlevel% neq 0 (
echo ✗ 添加文件失败
pause
exit /b 1
)
echo ✓ 文件已添加
echo.
echo [4/6] 创建提交...
git commit -m "Initial commit: SLMS project restructure" 2>nul
if %errorlevel% equ 0 (
echo ✓ 提交已创建
) else (
echo ⚠️ 没有新的更改需要提交,或提交已存在
)
echo.
echo [5/6] 配置本地 Gitea 远程仓库...
git remote add origin http://localhost:3000/gitea/slms.git 2>nul
if %errorlevel% equ 0 (
echo ✓ 远程仓库 origin 已添加
) else (
echo ⚠️ 远程仓库 origin 已存在,更新 URL...
git remote set-url origin http://localhost:3000/gitea/slms.git
echo ✓ 远程仓库 URL 已更新
)
echo.
echo [6/6] 推送到本地 Gitea...
echo.
echo 警告: 即将强制推送到 origin main 分支
echo 这将覆盖远程仓库的内容!
echo.
set /p CONFIRM="确认推送? (Y/N): "
if /i not "%CONFIRM%"=="Y" (
echo 操作已取消
pause
exit /b 0
)
echo.
echo 推送中...
git push -u origin main --force
if %errorlevel% neq 0 (
echo.
echo ✗ 推送失败!
echo.
echo 可能的原因:
echo 1. Gitea 服务未运行 (http://localhost:3000)
echo 2. 仓库 slms 不存在(需要在 Gitea 中创建)
echo 3. 认证失败(需要配置凭据)
echo 4. 网络连接问题
echo.
echo 解决方案:
echo 1. 确保 Gitea 服务正在运行
echo 2. 在 Gitea 中创建仓库: http://localhost:3000/repo/create
echo 3. 配置 Git 凭据或使用 SSH
echo.
pause
exit /b 1
)
echo.
echo ============================================================================
echo 推送成功!
echo ============================================================================
echo.
echo 仓库信息:
git remote -v
echo.
echo 最新提交:
git log -1 --oneline
echo.
echo 可以访问: http://localhost:3000/gitea/slms
echo.
pause