-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.bat
More file actions
147 lines (135 loc) · 2.67 KB
/
Copy pathhandler.bat
File metadata and controls
147 lines (135 loc) · 2.67 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
@REM 目标:清理本地开发环境
@REM 删除本地所有分支和stash缓存,保留${targetBranch}分支
@echo off
setlocal EnableDelayedExpansion
echo Welcome to the roubing999 tool...
echo.
set dp=%~dp0
setlocal
set yn=n
set /p yn="Whether to show the cache in stash (y | n)? "
call :confirm !yn!
echo.
if !yn!==y (
call :show_stashes %CD%
)
echo -----查看当前目录下所有仓库中的stash缓存数据完成-----
endlocal
setlocal
set yn=n
set /p yn="Whether to delete the cache in stash (y | n)? "
call :confirm !yn!
echo.
if !yn!==y (
call :clear_stashes %CD%
)
echo -----批量删除当前目录下所有仓库中的stash缓存数据完成-----
endlocal
setlocal
set yn=n
set /p yn="Whether to show all branches (y | n)? "
call :confirm !yn!
echo.
if !yn!==y (
call :show_branches %CD%
echo -----查看当前目录下的所有仓库分支完成-----
)
endlocal
setlocal
set yn=n
set /p yn="Whether to continue the batch delete (y | n)? "
call :confirm !yn!
if !yn!==n (
echo exit.
exit
)
echo.
endlocal
setlocal
set branch=develop
set /p branch="Please enter the target branch (develop): "
echo target branch: %branch%
set now=%date% %time%
set now=!now: =-!
echo now: %now%
call :switch_and_update_branch %CD% %branch% %now%
echo -----批量删除本地分支完成-----
endlocal
echo.
echo Finished.
exit
:show_branches
for /d %%i in (%1\*) do (
cd %%i
if exist .git (
set p=%%i
echo The branches under the repo path !p:%dp%=.\!
git branch
) else (
call :show_branches %%i
)
)
goto :EOF
:switch_and_update_branch
for /d %%i in (%1\*) do (
cd %%i
if exist .git (
set p=%%i
echo.
echo current path: !p:%dp%=.\!
git stash save %3
set hasTargetBranch=n
for /f "delims=" %%j in ('git branch') do (
echo %%j | findStr %2 > nul && set hasTargetBranch=y
)
if !hasTargetBranch!==y (
git switch %2
) else (
git remote update origin --prune
git checkout -b develop origin/develop
)
git branch | xargs git branch -D
git pull
) else (
call :switch_and_update_branch %%i %2 %3
)
)
goto :EOF
:show_stashes
for /d %%i in (%1\*) do (
cd %%i
if exist .git (
set p=%%i
echo current repo path !p:%dp%=.\!
git stash list
) else (
call :show_stashes %%i
)
)
goto :EOF
:clear_stashes
for /d %%i in (%1\*) do (
cd %%i
if exist .git (
set p=%%i
echo current repo path !p:%dp%=.\!
git stash clear
) else (
call :clear_stashes %%i
)
)
goto :EOF
:confirm
if !yn!==y (
echo.
) else if !yn!==n (
echo.
) else if !yn!==-1 (
echo exit.
exit
) else (
echo error.
set /p yn="input error value: !yn!, please re-enter (y | n): "
call :confirm !yn!
)
goto :EOF