Repository navigation
Expand file tree
/
Copy pathgit.bat
More file actions
164 lines (146 loc) · 4 KB
/
Copy pathgit.bat
File metadata and controls
164 lines (146 loc) · 4 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
164
@echo off
setlocal EnableExtensions EnableDelayedExpansion
rem ====== Config: locate the client JAR ======
rem Prefer the environment variable (can be set permanently).
if defined MGIT_JAR (
set "JAR=%MGIT_JAR%"
) else (
rem Option 1: git.bat next to the JAR.
set "JAR=%~dp0mini-git-server-1.0.0-client.jar"
if not exist "%JAR%" (
rem Option 2: target directory above git.bat (common in scripts\git.bat under repo root).
set "JAR=%~dp0..\target\mini-git-server-1.0.0-client.jar"
)
)
if not exist "%JAR%" (
echo [git.bat] Cannot find client jar. Set MGIT_JAR env or edit this script.
echo Example: set MGIT_JAR=E:\idea_projects\mini-git-server\target\mini-git-server-1.0.0-client.jar
exit /b 1
)
rem ====== Parse -C directory (can appear multiple times, last wins) ======
set "REPO=%CD%"
:parseC
if /I "%~1"=="-C" (
if "%~2"=="" (
echo usage: git -C ^<path^> <command> ...
exit /b 2
)
set "REPO=%~f2"
shift
shift
goto parseC
)
rem ====== No subcommand: show help ======
if "%~1"=="" (
echo Mini Git (mgit) wrapper - using %JAR%
echo.
echo Supported: init, clone, status, add, commit, log, branch, checkout, remote -v, push, pull
echo Tips: use -C ^<path^> before the command to operate another repo directory.
exit /b 0
)
set "CMD=%~1"
shift
rem ====== Common command mapping ======
if /I "%CMD%"=="--version" (
echo git version (mgit wrapper)
exit /b 0
)
if /I "%CMD%"=="help" (
java -jar "%JAR%" help
exit /b %ERRORLEVEL%
)
if /I "%CMD%"=="init" (
rem git -C X init -> mgit init X (use -C or current directory when target is omitted).
if "%~1"=="" ( set "TARGET=%REPO%" ) else ( set "TARGET=%~1" )
java -jar "%JAR%" init "%TARGET%"
exit /b %ERRORLEVEL%
)
if /I "%CMD%"=="clone" (
rem Pass-through: git clone <url> <dir> [--user U --pass P]
java -jar "%JAR%" clone %*
exit /b %ERRORLEVEL%
)
if /I "%CMD%"=="status" (
java -jar "%JAR%" status "%REPO%"
exit /b %ERRORLEVEL%
)
if /I "%CMD%"=="add" (
rem git add <paths...> -> mgit add <repo> <paths...>
if "%~1"=="" (
echo usage: git add ^<paths...^>
exit /b 2
)
java -jar "%JAR%" add "%REPO%" %*
exit /b %ERRORLEVEL%
)
if /I "%CMD%"=="commit" (
rem Pass through commit options (-m, etc) and add repo automatically.
java -jar "%JAR%" commit "%REPO%" %*
exit /b %ERRORLEVEL%
)
if /I "%CMD%"=="log" (
rem Pass through --max N.
java -jar "%JAR%" log "%REPO%" %*
exit /b %ERRORLEVEL%
)
if /I "%CMD%"=="branch" (
rem List: git branch -> mgit branch <repo>
rem Create: git branch -c <name> -> mgit branch -c <repo> <name>
if /I "%~1"=="-c" (
if "%~2"=="" (
echo usage: git branch -c ^<name^>
exit /b 2
)
java -jar "%JAR%" branch -c "%REPO%" "%~2"
) else (
java -jar "%JAR%" branch "%REPO%"
)
exit /b %ERRORLEVEL%
)
if /I "%CMD%"=="checkout" (
if "%~1"=="" (
echo usage: git checkout ^<branchOrCommit^>
exit /b 2
)
java -jar "%JAR%" checkout "%REPO%" %*
exit /b %ERRORLEVEL%
)
if /I "%CMD%"=="remote" (
rem -v: list remotes; -a: add remote
if /I "%~1"=="-v" (
java -jar "%JAR%" remote -v "%REPO%"
exit /b %ERRORLEVEL%
)
if /I "%~1"=="-a" (
if "%~3"=="" (
echo usage: git remote -a ^<name^> ^<url^>
exit /b 2
)
java -jar "%JAR%" remote -a "%REPO%" "%~2" "%~3"
exit /b %ERRORLEVEL%
)
echo [git.bat] Supported: remote -v, remote -a ^<name^> ^<url^>
exit /b 3
)
if /I "%CMD%"=="push" (
rem git push <remote> <ref> [--user U --pass P]
if "%~2"=="" (
echo usage: git push ^<remote^> ^<ref^> [--user U --pass P]
exit /b 2
)
java -jar "%JAR%" push "%REPO%" %*
exit /b %ERRORLEVEL%
)
if /I "%CMD%"=="pull" (
rem git pull <remote> <ref> [--user U --pass P]
if "%~2"=="" (
echo usage: git pull ^<remote^> ^<ref^> [--user U --pass P]
exit /b 2
)
java -jar "%JAR%" pull "%REPO%" %*
exit /b %ERRORLEVEL%
)
rem ====== Unsupported subcommands ======
echo [git.bat] Unsupported command: %CMD%
echo Supported: init, clone, status, add, commit, log, branch, checkout, remote -v, push, pull
exit /b 3