-
Notifications
You must be signed in to change notification settings - Fork 0
/
syscGIT_v1.0.bat
242 lines (198 loc) · 4.7 KB
/
syscGIT_v1.0.bat
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
@echo off
chcp 65001
setlocal enabledelayedexpansion
:menu
cls
echo.
echo ====================
echo QGit v1.0 by Sangko
echo ====================
echo ================== 拉取仓库 ==================
echo.
echo 0. 拉取仓库到指定目录
echo.
echo P. 打开对应的远程仓库地址
echo ================== 仓库操作 ==================
echo.
echo 1. 添加文件到暂存区
echo.
echo 2. 提交更改到本地仓库
echo.
echo 3. 推送更改到远程仓库
echo.
echo 4. 一键推送
echo.
echo 5. 退出
echo.
echo =============================================
set /p choice="请选择操作:"
if "%choice%"=="1" (
call :check_git_repo
if !git_repo!==false (
echo 当前目录不是一个 Git 仓库,请进入正确的目录后再试.
pause
goto :menu
)
call :add_files
) else if "%choice%"=="2" (
call :check_git_repo
if !git_repo!==false (
echo 当前目录不是一个 Git 仓库,请进入正确的目录后再试.
pause
goto :menu
)
call :commit_files
) else if "%choice%"=="3" (
call :check_git_repo
if !git_repo!==false (
echo 当前目录不是一个 Git 仓库,请进入正确的目录后再试.
pause
goto :menu
)
call :push_files
) else if "%choice%"=="4" (
call :check_git_repo
if !git_repo!==false (
echo 当前目录不是一个 Git 仓库,请进入正确的目录后再试.
pause
goto :menu
)
call :one_key_push
) else if "%choice%"=="5" (
goto :exit
) else if "%choice%"=="0" (
call :Clone_Res
pause
goto :menu
) else if "%choice%"=="P" (
call :ToGithub
pause
goto :menu
)
else (
echo 无效的选择,请重新输入.
pause
goto :menu
)
:check_git_repo
set git_repo=false
if exist "%cd%\.git" set git_repo=true
goto :eof
:add_files
echo.
echo 正在添加文件到暂存区...
git add .
echo.
echo 文件已成功添加到暂存区.
call :Delay_1s
goto :menu
:commit_files
echo.
echo 正在提交更改到本地仓库...
set /p commit_message="请输入提交消息: "
if "%commit_message%"=="" (
echo 未输入提交消息,请重新输入.
goto :commit_files
) else (
git commit -m "%commit_message%"
echo.
echo 更改已成功提交到本地仓库.
call :Delay_1s
goto :menu
)
:push_files
echo.
echo 正在推送更改到远程仓库...
rem git remote update origin --prune
echo.
setlocal enabledelayedexpansion
set branch_options=""
for /f "tokens=1" %%i in ('git branch -r') do (
set branch_options=!branch_options! %%i
echo %%i
)
set /p branch_name="请选择或输入分支名称 [%branch_options%]: "
if "%branch_name%"=="" (
echo 未选择或输入分支名称,请重新输入.
goto :push_files
)
git branch | findstr /i /c:"%branch_name%"
if %errorlevel%==1 (
set /p create_new_branch="分支 %branch_name% 不存在,是否创建新分支? [Y/N]: "
if /i "%create_new_branch%"=="Y" (
git checkout -b %branch_name%
echo.
echo 分支 %branch_name% 创建成功.
) else (
echo 未创建新分支.
goto :push_files
)
)
git checkout %branch_name%
git push -f origin %branch_name%
echo.
echo 更改已成功推送到远程仓库的分支 %branch_name%.
goto :ToGithub
pause
goto :menu
:one_key_push
echo.
echo 正在执行一键推送...
rem call :add_files
rem call :commit_files
rem call :push_files
echo 正在添加文件到暂存区...
git add .
echo.
echo 文件已成功添加到暂存区.
rem call :Delay_1s
echo.
echo 正在提交更改到本地仓库...
set /p commit_message="请输入提交消息: "
if "%commit_message%"=="" (
echo 未输入提交消息,请重新输入.
goto :commit_files
) else (
git commit -m "%commit_message%"
echo.
echo 更改已成功提交到本地仓库.
rem call :Delay_1s
)
call :push_files
pause
goto :menu
:Delay_1s
echo.
timeout /t 1 /nobreak >nul
goto :eof
:Clone_Res
echo.
@echo off
set /p repo_url="请输入远程仓库的URL: "
for %%i in ("%repo_url:/=" "%") do set repo_name=%%~ni
set target_dir="%cd%\%repo_name%"
if not exist "%repo_name%" (
mkdir "%repo_name%"
) else (
echo 【错误!】目录下已经存在 %repo_name% 文件夹,无法拉取,请检查!
pause
goto :menu
)
cd %target_dir%
echo 正在拉取代码到目标目录 %target_dir% ...
git clone %repo_url% .
if %errorlevel% neq 0 (
echo 代码拉取失败!
pause
goto :menu
)
echo 代码拉取完成!
goto :eof
:ToGithub
echo.
echo 打开对应的远程仓库地址
for /f "delims=" %%i in ('git config --get remote.origin.url') do set repo_url=%%i
start "" %repo_url%
goto :eof
:exit
exit /b