-
Notifications
You must be signed in to change notification settings - Fork 0
/
gito.bat
130 lines (117 loc) · 2.86 KB
/
gito.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
@echo off
rem git (single layer) onion
rem @license
rem Copyright (c) 2019 Alexandre REMY
rem
rem https://github.com/8HoLoN/gito
rem @version: 0.0.1 ( February 2019 )
rem @author 8HoLoN / https://github.com/8HoLoN/
rem < 8holon [at] gmail.com >
set action=%1
set sevenzPath="C:\Program Files\7-Zip\7z.exe"
set password=%2
set archiveName="secure.7z"
set innerRepo="inner"
IF "%action%" == "clone" (
set repoPath=%3
call:parseRepoName
call:gitoClone
) else IF "%action%" == "init" (
set repoPath=%3
call:parseRepoName
call:gitoInit
) else IF "%action%" == "pull" (
call:gitoPull
) else IF "%action%" == "push" (
call:gitoPull
call:gitoPush
) else (
echo "Wrong parameters."
)
goto:eof
:gitoInit
git clone --mirror %repoPath%
cd "%repoName%.git"
%sevenzPath% a "%archiveName%" * -p"%password%" -mhe=on
move "%archiveName%" "../"
cd ..
rem del /s /q "%repoName%.git"
rmdir /s /q "%repoName%.git"
git clone %repoPath%
move /Y "%archiveName%" "%repoName%"
cd "%repoName%"
git add "%archiveName%"
git commit -a -m "init repo"
git push
cd ..
rmdir /s /q "%repoName%"
goto:eof
:gitoClone
git clone %repoPath% --no-hardlinks --no-local
mkdir ".gito"
move "%repoName%" ".gito"
cd ".gito"
RENAME "%repoName%" "sub"
cd "sub"
%sevenzPath% -y x "%archiveName%" -p"%password%" -o.\%innerRepo%.git
rem del "%archiveName%"
git clone "%innerRepo%.git" --no-hardlinks --no-local
rem mkdir "../../lan"
move "%innerRepo%" "../.."
cd "../.."
move ".gito" "%innerRepo%"
RENAME "%innerRepo%" "%repoName%"
cd %repoName%
rem make it hidden
attrib +h ".gito" /s /d
git remote set-url origin .gito/sub/%innerRepo%.git
cd ..
goto:eof
:gitoPull
cd ".gito/sub"
git pull
%sevenzPath% -y x "%archiveName%" -p"%password%" -o.\%innerRepo%.git
cd "../.."
git pull
goto:eof
:gitoPush
git push
cd ".gito/sub/%innerRepo%.git"
%sevenzPath% a "%archiveName%" * -p"%password%" -mhe=on
move /Y "%archiveName%" "../%archiveName%"
cd ..
git commit -a -m "update repo"
git push
cd "../.."
goto:eof
:parseRepoName
set "char=/"
call :lastIndexOf repoPath char rtn
set /a rtn1=%rtn%+1
call set repoName=%%repoPath:~%rtn1%,-4%%
goto:eof
:lastIndexOf strVar charVar [rtnVar]
setlocal enableDelayedExpansion
:: Get the string values
set "lastIndexOf.char=!%~2!"
set "str=!%~1!"
set "chr=!lastIndexOf.char:~0,1!"
:: Determine the length of str - adapted from function found at:
:: http://www.dostips.com/DtCodeCmdLib.php#Function.strLen
set "str2=.!str!"
set "len=0"
for /L %%A in (12,-1,0) do (
set /a "len|=1<<%%A"
for %%B in (!len!) do if "!str2:~%%B,1!"=="" set /a "len&=~1<<%%A"
)
:: Find the last occurrance of chr in str
for /l %%N in (%len% -1 0) do if "!str:~%%N,1!" equ "!chr!" (
set rtn=%%N
goto :break
)
set rtn=-1
:break - Return the result if 3rd arg specified, else print the result
( endlocal
if "%~3" neq "" (set %~3=%rtn%) else echo %rtn%
)
exit /b