Files
assist/auto_push.bat
赵杰 Jie Zhao (雄狮汽车科技) 8176caa338 feat: 快速提交 - 周一 2025/09/22 13:18:51.04
2025-09-22 13:18:51 +01:00

191 lines
4.7 KiB
Batchfile
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@echo off
chcp 65001 >nul
echo ========================================
echo TSP智能助手 - 自动推送脚本
echo ========================================
echo.
:: 检查Git状态
echo [1/4] 检查Git状态...
git status --porcelain >nul 2>&1
if %errorlevel% neq 0 (
echo ❌ Git未初始化或不在Git仓库中
pause
exit /b 1
)
:: 显示当前状态
echo 📋 当前Git状态:
git status --short
echo.
:: 询问是否继续
set /p confirm="是否继续推送? (y/n): "
if /i "%confirm%" neq "y" (
echo 操作已取消
pause
exit /b 0
)
:: 检查是否有更改需要提交
echo.
echo [2/4] 检查更改状态...
git diff --quiet && git diff --cached --quiet
if %errorlevel% equ 0 (
echo 没有检测到任何更改,无需提交
echo.
echo ✅ 工作区干净,无需推送
pause
exit /b 0
)
:: 添加所有更改
echo 添加所有更改到暂存区...
git add .
if %errorlevel% neq 0 (
echo ❌ 添加文件失败
pause
exit /b 1
)
echo ✅ 文件已添加到暂存区
:: 检查markdown文件修改并生成智能提交信息
echo.
echo [3/4] 分析markdown文件并生成提交信息...
:: 检查是否有markdown文件修改
set md_files=
for /f "tokens=*" %%f in ('git diff --name-only --cached 2^>nul ^| findstr /i "\.md$"') do (
set md_files=!md_files! %%f
)
for /f "tokens=*" %%f in ('git diff --name-only 2^>nul ^| findstr /i "\.md$"') do (
set md_files=!md_files! %%f
)
set commit_msg=
if not "%md_files%"=="" (
echo 📝 检测到markdown文件修改:
echo %md_files%
echo.
:: 提取markdown文件的主要内容
set commit_title=
set commit_type=docs
:: 检查是否有修复相关内容
for %%f in (%md_files%) do (
if exist "%%f" (
for /f "tokens=*" %%l in ('type "%%f" ^| findstr /i "修复\|解决\|问题\|错误"') do (
set commit_type=fix
set commit_title=修复问题
goto :found_fix
)
)
)
:: 检查是否有新功能相关内容
for %%f in (%md_files%) do (
if exist "%%f" (
for /f "tokens=*" %%l in ('type "%%f" ^| findstr /i "功能\|新增\|添加\|实现"') do (
set commit_type=feat
set commit_title=新增功能
goto :found_feature
)
)
)
:: 检查是否有优化相关内容
for %%f in (%md_files%) do (
if exist "%%f" (
for /f "tokens=*" %%l in ('type "%%f" ^| findstr /i "优化\|性能\|改进\|提升"') do (
set commit_type=perf
set commit_title=性能优化
goto :found_optimization
)
)
)
:: 提取文件标题
for %%f in (%md_files%) do (
if exist "%%f" (
for /f "tokens=*" %%l in ('type "%%f" ^| findstr /n "^#" ^| head -1') do (
set line=%%l
set line=!line:*:=!
set line=!line:# =!
set line=!line:## =!
if "!line!" neq "" (
set commit_title=!line!
goto :found_title
)
)
)
)
:found_fix
:found_feature
:found_optimization
:found_title
if "%commit_title%"=="" (
set commit_title=更新文档记录
)
:: 生成提交信息
set commit_msg=%commit_type%: %commit_title%
echo 📋 生成的提交信息: %commit_msg%
echo.
) else (
echo 没有检测到markdown文件修改
set commit_msg=feat: 自动提交 - %date% %time%
)
:: 询问是否使用生成的提交信息
set /p confirm="是否使用此提交信息? (y/n/e编辑): "
if /i "%confirm%"=="e" (
set /p commit_msg="请输入自定义提交信息: "
) else if /i "%confirm%" neq "y" (
set /p commit_msg="请输入提交信息: "
)
:: 提交更改
echo 提交信息: %commit_msg%
git commit -m "%commit_msg%"
if %errorlevel% neq 0 (
echo ❌ 提交失败
pause
exit /b 1
)
echo ✅ 提交成功
:: 推送到远程仓库
echo.
echo [4/4] 推送到远程仓库...
git push origin main
if %errorlevel% neq 0 (
echo ❌ 推送失败
echo 💡 可能的原因:
echo - 网络连接问题
echo - 远程仓库权限不足
echo - 分支冲突
echo - 需要先拉取远程更改
echo.
echo 🔧 建议解决方案:
echo 1. 检查网络连接
echo 2. 运行: git pull origin main
echo 3. 重新运行推送脚本
pause
exit /b 1
)
echo.
echo ========================================
echo ✅ 推送完成!
echo ========================================
echo 📊 提交统计:
git log --oneline -1
echo.
echo 🌐 远程仓库状态:
git status
echo.
pause