-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGitSyncAll.cmd
88 lines (79 loc) · 1.75 KB
/
GitSyncAll.cmd
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
@echo off
rem ************************************************************
rem
rem Sync all Git repos (bare and normal) by pushing or pulling.
rem
rem ************************************************************
setlocal enabledelayedexpansion
:handle_help_request
if /i "%~1" == "-?" call :usage & exit /b 0
if /i "%~1" == "--help" call :usage & exit /b 0
:check_args
if /i "%~1" == "" call :usage & exit /b 1
if /i "%~1" == "pull" goto :pull
if /i "%~1" == "push" goto :push
call :usage & exit /b 1
:pull
for /d %%d in (*) do (
if exist "%%d\.git" (
call :pull_repo "%%d"
if !errorlevel! neq 0 exit /b !errorlevel!
) else (
if exist "%%d\HEAD" (
call :pull_repo "%%d"
if !errorlevel! neq 0 exit /b !errorlevel!
)
)
)
exit /b 0
:push
set remote=origin
if /i not "%~2" == "" set remote=%~2
for /d %%d in (*) do (
if exist "%%d\.git" (
call :push_repo "%%d" "%remote%"
if !errorlevel! neq 0 exit /b !errorlevel!
) else (
if exist "%%d\HEAD" (
call :push_repo "%%d" "%remote%"
if !errorlevel! neq 0 exit /b !errorlevel!
)
)
)
exit /b 0
rem ************************************************************
rem Functions
rem ************************************************************
:usage
echo.
echo Usage: %~n0 [pull ^| push [^<remote^>]]
echo.
echo e.g. %~n0 pull
echo %~n0 push (defaults to origin)
echo %~n0 push github
goto :eof
:pull_repo
set repo=%~1
echo '%repo%'
pushd "%repo%"
git pull --rebase
if !errorlevel! neq 0 (
echo ERROR: Failed to pull from repo
exit /b !errorlevel!
)
popd
echo.
goto :eof
:push_repo
set repo=%~1
set remote=%~2
echo '%repo%'
pushd "%repo%"
git push %remote% master --tags
if !errorlevel! neq 0 (
echo ERROR: Failed to push repo to remote '%remote%'
exit /b !errorlevel!
)
popd
echo.
goto :eof