forked from mozilla-conduit/autoland-transplant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclone-repo
executable file
·42 lines (36 loc) · 1.18 KB
/
clone-repo
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
#!/usr/bin/env python2
import ConfigParser
import StringIO
import os
import subprocess
import sys
ROOT = os.path.abspath(os.path.dirname(__file__))
if 'VIRTUAL_ENV' not in os.environ:
activate = os.path.join(ROOT, 'venv', 'bin', 'activate_this.py')
execfile(activate, dict(__file__=activate))
sys.executable = os.path.join(ROOT, 'venv', 'bin', 'python')
os.chdir(ROOT)
# Load .env file.
env = ConfigParser.ConfigParser()
with open('.env', 'r') as f:
env.readfp(StringIO.StringIO('[config]\n%s' % f.read()))
output_path = 'dev-repo'
if os.path.exists(output_path):
print('%s already exists' % output_path)
sys.exit(1)
# Clone
print('cloning into %s' % output_path)
os.environ['HGRCPATH'] = ''
subprocess.check_call([
'hg',
'clone', 'http://localhost:%s/test-repo' % env.get('config', 'HOST_HGWEB'),
output_path
])
# Set pushurl so you can't push directly to the repo (must use autoland).
hgrc_file = os.path.join(output_path, '.hg', 'hgrc')
hgrc = ConfigParser.ConfigParser()
hgrc.read(hgrc_file)
hgrc.set('paths', 'default:pushurl', 'file:///dev/null')
hgrc.set('ui', 'username', 'Autoland Dev <autoland@example.com>')
with open(hgrc_file, 'w') as f:
hgrc.write(f)