-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathg.bat
More file actions
163 lines (139 loc) · 4.36 KB
/
g.bat
File metadata and controls
163 lines (139 loc) · 4.36 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
:: ============== Quick Git Push NORMAL ==============
:: This script cannot be named `git.bat` as it will conflict with the real git command.
:: Up-to-date version located at kitsum1070/Hello repository.
:: Last updated: 17/05/2025 : Updated title
@echo off
setlocal EnableDelayedExpansion
:: Allow printing Unicode characters
chcp 65001 >nul
:: clear terminal
cls
:: Starting message
set "batStartMsg=Git Tool starts"
powershell -Command "Write-Host '!batStartMsg!' -ForegroundColor Blue"
echo.
:: Pull changes
set "pullMsg=--- Pulling changes ---"
powershell -Command "Write-Host '!pullMsg!' -ForegroundColor Cyan"
echo.
git pull
:: Display Git Status
git status
echo.
:: Check status
:Main
set "GIT_STATUS="
for /f "delims=" %%i in ('git status --porcelain') do (
set "GIT_STATUS=%%i"
goto :HasChanges
)
:: ================== Functions ==================
:: No changes found
set "noChanges=No changes to commit."
powershell -Command "Write-Host '!noChanges!' -ForegroundColor Cyan"
goto :EndScript
:: Exit Script
:EndScript
echo.
set "leavingMsg=Script ends"
powershell -Command "Write-Host '!leavingMsg!' -ForegroundColor Blue"
timeout /t 30
exit
:: Commit/Push Failed
:Failed
set "failedMsg=ERROR: Something went wrong..."
powershell -Command "Write-Host '!failedMsg!' -ForegroundColor Red"
goto :EndScript
:: (Commit cancelled) Ask if unstaged or not
:Unstaged
set "unstagedMsg=Do you want to unstage the changes? ([Y] to unstage)"
powershell -Command "Write-Host '!unstagedMsg!' -ForegroundColor Cyan"
echo.
powershell -Command ^
"$key = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');" ^
"if ($key.VirtualKeyCode -eq 89) { exit 0 } else { exit 1 }"
if errorlevel 1 (
set "notUnstageMsg=Staged changes remain."
powershell -Command "Write-Host '!notUnstageMsg!' -ForegroundColor Cyan"
echo.
goto :EndScript
)
git reset
echo.
set "unstagedMsg=Changes unstaged."
powershell -Command "Write-Host '!unstagedMsg!' -ForegroundColor Cyan"
echo.
goto :EndScript
:: ====== Main Script ======
:HasChanges
echo.
set "proceedConfirmation=Continue? (Y/N)"
powershell -Command "Write-Host '!proceedConfirmation!' -ForegroundColor Cyan"
powershell -Command ^
"$key = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');" ^
"if ($key.VirtualKeyCode -eq 89 -or $key.VirtualKeyCode -eq 13) { exit 0 } else { exit 1 }"
if errorlevel 1 (
goto :EndScript
)
:: Stage all files
echo.
git add .
set "stagedMsg=Changes staged."
powershell -Command "Write-Host '!stagedMsg!' -ForegroundColor Cyan"
:: Ask for commit type
set "defaultMsg=Back up works with small non-breaking changes"
echo.
@REM echo Select a commit tag:
powershell -Command "Write-Host 'Select a commit tag:' -ForegroundColor Cyan"
powershell -Command "Write-Host '[0] No tag' -ForegroundColor Green"
set "tagList=[1] [GIT] [2] [FEAT] [3] [FIX] [4] [DOC] [5] [STYLE]"
powershell -Command "Write-Host '!tagList!' -ForegroundColor Green"
powershell -Command "Write-Host 'Press the number key (0-5):' -ForegroundColor Cyan"
set "commitTag="
powershell -Command ^
"$key = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');" ^
"if ($key.VirtualKeyCode -ge 48 -and $key.VirtualKeyCode -le 53) { Write-Output $key.Character } else { Write-Output '0' }" > tag_choice.tmp
set /p commitTag=<tag_choice.tmp
if exist tag_choice.tmp del tag_choice.tmp
:: Map numeric choice to tag
set "tag0="
set "tag1=[GIT] "
set "tag2=[FEAT] "
set "tag3=[FIX] "
set "tag4=[DOC] "
set "tag5=[STYLE] "
set "prefix=!tag%commitTag%!"
powershell -Command "Write-Host 'Selected tag: !prefix!' -ForegroundColor Green"
:: Ask for commit message
echo.
powershell -Command "Write-Host 'Commit message: ' -ForegroundColor Cyan -NoNewline"
set /p "commitMsg="
if "%commitMsg%"=="" (
set "commitMsg=%defaultMsg%"
)
if "%commitMsg%"=="!q" (
set "notCommitMsg=Commit cancelled."
powershell -Command "Write-Host '!notCommitMsg!' -ForegroundColor Cyan"
echo.
goto :Unstaged
)
:: Final commit string
git commit -m "!prefix!!commitMsg!"
if errorlevel 1 (
goto :Failed
)
echo.
set "committed=Changes committed."
powershell -Command "Write-Host '!committed!' -ForegroundColor Cyan"
echo.
:: Push changes
git push
if errorlevel 1 (
goto :Failed
)
echo.
set "pushSuccess=Job done."
powershell -Command "Write-Host '!pushSuccess!' -ForegroundColor Cyan"
echo.
goto :EndScript
:: ============================== End of the quick-git.bat ==============================