Files
assist/quick_push.bat

161 lines
4.3 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
setlocal enabledelayedexpansion
echo 🚀 TSP智能助手 - 快速推送
echo.
:: 检查Git状态
git status --porcelain >nul 2>&1
if %errorlevel% neq 0 (
echo ❌ Git未初始化或不在Git仓库中
pause
exit /b 1
)
:: 检查是否有参数
if "%1"=="" (
:: 智能生成提交信息
echo 📝 分析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文件修改: %md_files%
:: 提取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%
) else (
echo 没有检测到markdown文件修改
set commit_msg=feat: 快速提交 - %date% %time%
)
) else (
set commit_msg=%1
)
echo 📝 提交信息: %commit_msg%
echo.
:: 检查是否有更改需要提交
git diff --quiet && git diff --cached --quiet
if %errorlevel% equ 0 (
echo 没有检测到任何更改,无需提交
echo.
echo ✅ 工作区干净,无需推送
pause
exit /b 0
)
:: 执行推送
echo.
echo 📤 开始推送流程...
echo 📝 提交信息: %commit_msg%
git add .
if %errorlevel% neq 0 (
echo ❌ 添加文件失败
pause
exit /b 1
)
git commit -m "%commit_msg%"
if %errorlevel% neq 0 (
echo ❌ 提交失败
pause
exit /b 1
)
git push origin main
if %errorlevel% equ 0 (
echo.
echo ✅ 推送完成!
echo 📊 最新提交:
git log --oneline -1
) else (
echo.
echo ❌ 推送失败,请检查错误信息
echo 💡 可能的原因:
echo - 网络连接问题
echo - 远程仓库权限不足
echo - 分支冲突
echo - Git认证失败
echo.
echo 🔧 建议解决方案:
echo 1. 检查Git用户配置: git config --global user.name
echo 2. 检查Git邮箱配置: git config --global user.email
echo 3. 检查远程仓库权限
echo 4. 尝试重新认证
)
echo.
pause