From bc72af12a7c820ee9686b88dd8050709eb344bdd Mon Sep 17 00:00:00 2001 From: Christian Langer Date: Tue, 3 Jun 2025 10:07:51 +0200 Subject: [PATCH] Updated Push Batch script --- Git-Push_c.bat | 93 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 88 insertions(+), 5 deletions(-) diff --git a/Git-Push_c.bat b/Git-Push_c.bat index 92bf772..a871a67 100644 --- a/Git-Push_c.bat +++ b/Git-Push_c.bat @@ -1,8 +1,91 @@ @echo off -@echo Updates hochladen -set /p Update=Comment: -@pause +setlocal enabledelayedexpansion + +echo Checking git repository status... +echo. + +REM Check if we're in a git repository +git rev-parse --git-dir >nul 2>&1 +if errorlevel 1 ( + echo Error: Not a git repository or git is not installed. + pause + exit /b 1 +) + +REM Check for changes (staged, unstaged, and untracked files) +git diff --quiet --exit-code +set staged_changes=%errorlevel% + +git diff --quiet --cached --exit-code +set unstaged_changes=%errorlevel% + +REM Check for untracked files +for /f %%i in ('git ls-files --others --exclude-standard ^| find /c /v ""') do set untracked_count=%%i + +REM If no changes detected +if %staged_changes%==0 if %unstaged_changes%==0 if %untracked_count%==0 ( + echo No changes detected in the repository. + echo Repository is up to date. + pause + exit /b 0 +) + +REM Show current status +echo Changes detected: +git status --porcelain +echo. + +REM Add all changes (staged, unstaged, and untracked) +echo Adding all changes... git add . -git commit -m "%Update%" + +REM Verify there are changes to commit after adding +git diff --quiet --cached --exit-code +if %errorlevel%==0 ( + echo No changes to commit after adding files. + pause + exit /b 0 +) + +REM Prompt for commit message +echo. +set /p commit_msg="Enter commit message: " + +REM Check if commit message is empty +if "!commit_msg!"=="" ( + echo Error: Commit message cannot be empty. + pause + exit /b 1 +) + +REM Commit changes +echo. +echo Committing changes... +git commit -m "!commit_msg!" +if errorlevel 1 ( + echo Error: Failed to commit changes. + pause + exit /b 1 +) + +REM Push to remote repository +echo. +echo Pushing to remote repository... git push -@pause \ No newline at end of file +if errorlevel 1 ( + echo Error: Failed to push changes to remote repository. + echo This might be due to: + echo - No remote repository configured + echo - Network connectivity issues + echo - Authentication problems + echo - Need to pull changes first + echo. + echo You can try running 'git push' manually to see the specific error. + pause + exit /b 1 +) + +echo. +echo Success! Changes have been committed and pushed. +echo Commit message: !commit_msg! +pause \ No newline at end of file