-
Notifications
You must be signed in to change notification settings - Fork 0
/
MirrorChanges.bat
62 lines (47 loc) · 1.8 KB
/
MirrorChanges.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
REM This script helps automate mirroring all changes from a "master" repository to a "mirror" repository.
REM Changes should not be made in the mirror but all changes should flow to the mirror repository via the master repository.
REM Inputs needed for the script are : 1. Remote URL for the master repository 2. Remote URL for the mirror repository
IF "%1" == "" (
echo Master repository URL is not provided
GOTO USAGE
)
IF "%2" == "" (
echo Mirror repository URL is not provided
GOTO USAGE
)
SET masterRepoUrl=%1
SET mirrorRepoURL=%2
IF NOT "%3" == "" (
cd %3
)
SET mirrorDirName=repoMirror
echo Delete local mirror directory
IF EXIST %mirrorDirName% rd /S /Q %mirrorDirName%
echo Clone master repository to mirror directory
git clone --mirror %masterRepoUrl% %mirrorDirName%
IF NOT EXIST %mirrorDirName% GOTO ERROR
IF NOT %ERRORLEVEL% EQU 0 GOTO ERROR
cd %mirrorDirName%
echo Set remote push url to the mirror repository url
git remote set-url --push origin %mirrorRepoURL%
echo Fetch and prune refs from master repository
git fetch -p origin
IF NOT %ERRORLEVEL% EQU 0 GOTO ERROR
echo Push to the mirror repository
git push --mirror
IF NOT %ERRORLEVEL% EQU 0 GOTO ERROR
echo Delete local mirror directory
cd ..
rd /S /Q %mirrorDirName%
:END
exit /b %ERRORLEVEL%
:ERROR
echo Errors during script execution 1>&2
GOTO END
:USAGE
echo Invalid arguments passed to script 1>&2
echo MirrorChanges.bat MasterRepositoryURL MirrorRepositoryURL LocalRepoRootDir
echo MasterRepositoryURL is the remote URL of the Git repository which contains the changes to be mirrored
echo MirrorRepositoryURL is the remote UL of the Git repository which will mirror the changes in the master repository
echo LocalRepoRootDir (Optional) is the root directory where the repository will be cloned. Defaults to the current directory.
GOTO END