-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-push.bat
More file actions
55 lines (45 loc) · 1.17 KB
/
Copy pathgit-push.bat
File metadata and controls
55 lines (45 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
@echo off
setlocal enabledelayedexpansion
:: Check for commit message
if "%~1"=="" (
echo No commit message provided.
exit /b 1
)
:: Check if in a Git repository
if not exist ".git" (
echo This is not a Git repository. Please navigate to one before running the script.
exit /b 1
)
:: Create log file if not already set
if not defined LOG_FILE (
set LOG_FILE=git_push.log
)
>> "%LOG_FILE%" echo ==== Script started at %date% %time% ====
:: Change to GIT_FOLDER if defined and exists
if defined GIT_FOLDER (
if exist "%GIT_FOLDER%" (
cd /d "%GIT_FOLDER%"
)
)
:: After push or commit
git status >> "%LOG_FILE%"
:: Add and commit
git add .
git commit -m "%~1"
if errorlevel 1 (
echo Commit failed. Possibly nothing to commit.
exit /b 1
)
:: Check if "push" argument was passed
if /i "%~2"=="push" (
git push
if errorlevel 1 (
echo Push failed. Please check your internet connection or remote config.
exit /b 1
)
echo Changes have been committed and pushed successfully.
) else (
echo Changes have been committed successfully. Not pushed.
)
>> "%LOG_FILE%" echo ==== Script ended at %date% %time% ====
endlocal