-
Notifications
You must be signed in to change notification settings - Fork 1
/
clean.bat
153 lines (142 loc) · 3.27 KB
/
clean.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
@echo off
set home=%~dp0
cd ../
set oneup=%cd%
pushd %oneup%
set bfg=java -jar %home%bfg.jar
set bfgopts=
set /p user=GitHub UserName:
echo %user%
set /p repo=Repo name:
echo %repo%
rmdir preclean%repo%.git /s/q
git clone --mirror https://github.com/%user%/%repo%.git preclean%repo%.git
set folders=
set files=
set bfgopts1=
set bfgopts2=
set bfgopts3=
:opts
cd %oneup%
CHOICE /C 123Q /M "1-Remove file 2-Remove folder 3-Replace text Q-uit"
echo %errorlevel%
if errorlevel 4 goto quit
if errorlevel 3 goto words
if errorlevel 2 goto folder
if errorlevel 1 goto remfile
:remfile
set /p filepath=Enter path to file:
for %%A in (%repo%\%filepath%) do (
set file=%%~nxA
set dp=%%~fA
)
call set folder=%%dp:\%file%=%%
cd %repo%
echo %filepath% >> .gitignore
git rm --cached %filepath%
git add .gitignore
set "files=%files%%file%,"
set bfgopts1=--delete-files "{%files%}"
cd %oneup%
choice /m "Is there more"
if errorlevel 2 goto commit
if errorlevel 1 goto opts
:folder
set /p filepath=Enter path to folder:
for %%A in (%repo%\%filepath%) do (
set file=%%~nxA
set dp=%%~fA
set direct=%%~nA
)
call set folder=%%dp:\%file%=%%
set _folder=%filepath%/
echo %_folder%
pause
cd %repo%
echo %_folder% >> .gitignore
git rm --cached %_folder% -r
git add .gitignore
cd %oneup%
set "folders=%folders%%direct%,"
set bfgopts2=--delete-folders "{%folders%}"
choice /m "Is there more"
if errorlevel 2 goto commit
if errorlevel 1 goto opts
:words
pushd %oneup%
set /p filepath=Enter path to file with words to replace:
for %%A in (%repo%\%filepath%) do (
set file=%%~nxA
set dp=%%~fA
)
call set folder=%%dp:\%file%=%%
echo %folder%
set /p words=Word to find (word;replacement):
set repl=%words:*;=%
call set word=%%words:;%repl%=%%
echo %word%
echo %repl%
::rm rep.txt
echo create %home%rep.txt
set sep="==>"
echo %word%%sep%%repl%>>%home%rep.txt
sed -i 's/\"//g' %home%rep.txt
echo "check rep.txt"
pause
cd %folder%
sed -i 's;%word%;%repl%;g' %file%
echo "check %file%"
pause
git add %file%
set bfgopts3=-rt %home%rep.txt
popd
cd %repo%
echo %filepath% >> .gitignore
git add .gitignore
echo "you'll need to manually rm --cached %file% when we're done here."
cd %oneup%
choice /m "Is there more"
if errorlevel 2 goto commit
if errorlevel 1 goto opts
:commit
cd %repo%
echo %cd%
git commit
set bfgopts=%bfgopts1% %bfgopts2% %bfgopts3%
choice /m "current options: %bfgopts% edit them" /d n /t 5
if errorlevel 2 goto conf
if errorlevel 1 goto edit
:edit
set /p bfgopts=Fix the options:
:conf
choice /c YSQ /m "Ready to Push? Y-es, S-kip no remote changes, Q-uit"
if errorlevel 3 goto quit
if errorlevel 2 goto bfg
if errorlevel 1 goto push
:push
git push -f --all
:bfg
cd %oneup%
pushd %cd%
rmdir %repo%.git /s/q
git clone --mirror https://github.com/%user%/%repo%.git
mkdir BACKUP%repo%.git
robocopy %repo%.git BACKUP%repo%.git /E
%BFG% %bfgopts% %repo%.git | grep -v "You can\|make people\|give up"
cd %repo%.git
choice /m "Prune empty commits now" /d n /t 5
if errorlevel 2 goto reflogcleanup
if errorlevel 1 goto prunetoo
:prunetoo
git reflog expire --expire=now --all && git gc --prune=now --aggressive && git filter-branch --prune-empty -f
goto end
:reflogcleanup
git reflog expire --expire=now --all && git gc --prune=now --aggressive
:end
git push
cd %oneup%
cd %repo%
git pull --rebase -f
cd %home%
:quit
pause