forked from DTUComputeCognitiveSystems/mirrorSetup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetupRemoteMirror.py
More file actions
30 lines (25 loc) · 870 Bytes
/
setupRemoteMirror.py
File metadata and controls
30 lines (25 loc) · 870 Bytes
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
#!/usr/bin/env python
import git
import re
from shutil import copyfile
# organizations to mirror into
organizations = ['DTUComputeCognitiveSystems']
repo = git.Repo('.')
assert not repo.bare
repoGit = repo.git
# for remoteName in repo.remotes:
# print(remoteName)
# Get name of repository from the origin
urlOrigin = repoGit.remote('get-url', 'origin')
pattern = '.*/(.*).git'
repoName = re.match(pattern, urlOrigin)
repoName = repoName.group(1)
# print(repoName)
for organizationName in organizations:
# Set URL for mirror
remoteMirrorURL = 'https://github.com/' + organizationName + '/' + repoName
# Add mirror as remote to local repository
repoGit.remote('add', '--mirror=push', 'mirror_repo_' + organizationName,
remoteMirrorURL)
# Install pre-push hook
copyfile('mirrorSetup/hooks/pre-push-python', '.git/hooks/pre-push')