2012-11-13 22:51:03 +00:00
|
|
|
#!/usr/bin/env python
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2016-02-10 17:44:30 +00:00
|
|
|
# repo default configuration
|
|
|
|
#
|
2016-02-03 22:49:43 +00:00
|
|
|
import os
|
|
|
|
REPO_URL = os.environ.get('REPO_URL', None)
|
|
|
|
if not REPO_URL:
|
|
|
|
REPO_URL = 'https://gerrit.googlesource.com/git-repo'
|
2012-11-14 03:09:38 +00:00
|
|
|
REPO_REV = 'stable'
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
# Copyright (C) 2008 Google Inc.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
# increment this whenever we make important changes to this script
|
2015-09-02 19:36:30 +00:00
|
|
|
VERSION = (1, 22)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
# increment this if the MAINTAINER_KEYS block is modified
|
2013-07-01 18:05:32 +00:00
|
|
|
KEYRING_VERSION = (1, 2)
|
2008-10-21 14:00:00 +00:00
|
|
|
MAINTAINER_KEYS = """
|
|
|
|
|
|
|
|
Repo Maintainer <repo@android.kernel.org>
|
|
|
|
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
|
|
Version: GnuPG v1.4.2.2 (GNU/Linux)
|
|
|
|
|
|
|
|
mQGiBEj3ugERBACrLJh/ZPyVSKeClMuznFIrsQ+hpNnmJGw1a9GXKYKk8qHPhAZf
|
|
|
|
WKtrBqAVMNRL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6KG+5hpsREstFX2wK1yKeraz
|
|
|
|
5xGrFy8tfAaeBMIQ17gvFSp/suc9DYO0ICK2BISzq+F+ZiAKsjMYOBNdH/h0zobQ
|
|
|
|
HTHs37+/QLMomGEGKZMWi0dShU2J5mNRQu3Hhxl3hHDVbt5CeJBb26aQcQrFz69W
|
|
|
|
zE3GNvmJosh6leayjtI9P2A6iEkEGBECAAkFAkj3uiACGwwACgkQFlMNXpIPXGWp
|
|
|
|
TACbBS+Up3RpfYVfd63c1cDdlru13pQAn3NQy/SN858MkxN+zym86UBgOad2
|
|
|
|
=CMiZ
|
2012-10-01 23:12:28 +00:00
|
|
|
-----END PGP PUBLIC KEY BLOCK-----
|
|
|
|
|
|
|
|
Conley Owens <cco3@android.com>
|
|
|
|
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
|
|
Version: GnuPG v1.4.11 (GNU/Linux)
|
|
|
|
|
2013-07-01 18:05:32 +00:00
|
|
|
mQENBFHRvc8BCADFg45Xx/y6QDC+T7Y/gGc7vx0ww7qfOwIKlAZ9xG3qKunMxo+S
|
|
|
|
hPCnzEl3cq+6I1Ww/ndop/HB3N3toPXRCoN8Vs4/Hc7by+SnaLFnacrm+tV5/OgT
|
|
|
|
V37Lzt8lhay1Kl+YfpFwHYYpIEBLFV9knyfRXS/428W2qhdzYfvB15/AasRmwmor
|
|
|
|
py4NIzSs8UD/SPr1ihqNCdZM76+MQyN5HMYXW/ALZXUFG0pwluHFA7hrfPG74i8C
|
|
|
|
zMiP7qvMWIl/r/jtzHioH1dRKgbod+LZsrDJ8mBaqsZaDmNJMhss9g76XvfMyLra
|
|
|
|
9DI9/iFuBpGzeqBv0hwOGQspLRrEoyTeR6n1ABEBAAG0H0NvbmxleSBPd2VucyA8
|
|
|
|
Y2NvM0BhbmRyb2lkLmNvbT6JATgEEwECACIFAlHRvc8CGwMGCwkIBwMCBhUIAgkK
|
|
|
|
CwQWAgMBAh4BAheAAAoJEGe35EhpKzgsP6AIAJKJmNtn4l7h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iSLoeWP3aq/k+/GRGOR+S6F6BBSl0SQ2EF2+dIywb1x
|
|
|
|
JuinEP+AwLAUZ1Bsx9ISC0Agpk2VeHXPL3FGhroEmoMvBzO0kTFGyoeT7PR/BfKv
|
|
|
|
+H/g3HsL2LOB9uoIm8/5p2TTU5ttYCXMHhQZ81AY
|
|
|
|
=AUp4
|
2008-10-21 14:00:00 +00:00
|
|
|
-----END PGP PUBLIC KEY BLOCK-----
|
|
|
|
"""
|
|
|
|
|
2016-02-10 17:44:30 +00:00
|
|
|
GIT = 'git' # our git command
|
|
|
|
MIN_GIT_VERSION = (1, 7, 2) # minimum supported git version
|
|
|
|
repodir = '.repo' # name of repo's private directory
|
|
|
|
S_repo = 'repo' # special repo repository
|
|
|
|
S_manifests = 'manifests' # special manifest repository
|
|
|
|
REPO_MAIN = S_repo + '/main.py' # main script
|
|
|
|
MIN_PYTHON_VERSION = (2, 6) # minimum supported python version
|
2015-08-28 21:25:44 +00:00
|
|
|
GITC_CONFIG_FILE = '/gitc/.config'
|
2015-10-06 22:23:19 +00:00
|
|
|
GITC_FS_ROOT_DIR = '/gitc/manifest-rw/'
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
|
2013-12-26 22:20:13 +00:00
|
|
|
import errno
|
2008-10-21 14:00:00 +00:00
|
|
|
import optparse
|
|
|
|
import re
|
2014-03-12 17:48:15 +00:00
|
|
|
import shutil
|
2012-10-26 00:53:09 +00:00
|
|
|
import stat
|
2008-10-21 14:00:00 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
2013-05-17 01:49:33 +00:00
|
|
|
|
|
|
|
if sys.version_info[0] == 3:
|
2012-10-31 16:21:55 +00:00
|
|
|
import urllib.request
|
|
|
|
import urllib.error
|
|
|
|
else:
|
|
|
|
import imp
|
2013-05-17 01:49:33 +00:00
|
|
|
import urllib2
|
2012-10-31 16:21:55 +00:00
|
|
|
urllib = imp.new_module('urllib')
|
|
|
|
urllib.request = urllib2
|
|
|
|
urllib.error = urllib2
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2013-09-26 22:50:49 +00:00
|
|
|
|
|
|
|
def _print(*objects, **kwargs):
|
|
|
|
sep = kwargs.get('sep', ' ')
|
|
|
|
end = kwargs.get('end', '\n')
|
|
|
|
out = kwargs.get('file', sys.stdout)
|
|
|
|
out.write(sep.join(objects) + end)
|
|
|
|
|
|
|
|
|
2013-04-16 14:06:09 +00:00
|
|
|
# Python version check
|
|
|
|
ver = sys.version_info
|
|
|
|
if (ver[0], ver[1]) < MIN_PYTHON_VERSION:
|
2013-09-26 22:50:49 +00:00
|
|
|
_print('error: Python version %s unsupported.\n'
|
|
|
|
'Please use Python 2.6 - 2.7 instead.'
|
|
|
|
% sys.version.split(' ')[0], file=sys.stderr)
|
2013-04-16 14:06:09 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
home_dot_repo = os.path.expanduser('~/.repoconfig')
|
|
|
|
gpg_dir = os.path.join(home_dot_repo, 'gnupg')
|
|
|
|
|
|
|
|
extra_args = []
|
|
|
|
init_optparse = optparse.OptionParser(usage="repo init -u url [options]")
|
|
|
|
|
|
|
|
# Logging
|
|
|
|
group = init_optparse.add_option_group('Logging options')
|
|
|
|
group.add_option('-q', '--quiet',
|
|
|
|
dest="quiet", action="store_true", default=False,
|
|
|
|
help="be quiet")
|
|
|
|
|
|
|
|
# Manifest
|
|
|
|
group = init_optparse.add_option_group('Manifest options')
|
|
|
|
group.add_option('-u', '--manifest-url',
|
|
|
|
dest='manifest_url',
|
|
|
|
help='manifest repository location', metavar='URL')
|
|
|
|
group.add_option('-b', '--manifest-branch',
|
|
|
|
dest='manifest_branch',
|
|
|
|
help='manifest branch or revision', metavar='REVISION')
|
|
|
|
group.add_option('-m', '--manifest-name',
|
|
|
|
dest='manifest_name',
|
|
|
|
help='initial manifest file', metavar='NAME.xml')
|
2008-11-04 15:37:10 +00:00
|
|
|
group.add_option('--mirror',
|
|
|
|
dest='mirror', action='store_true',
|
2012-11-14 21:17:30 +00:00
|
|
|
help='create a replica of the remote repositories '
|
|
|
|
'rather than a client working directory')
|
2010-10-08 08:02:09 +00:00
|
|
|
group.add_option('--reference',
|
|
|
|
dest='reference',
|
|
|
|
help='location of mirror directory', metavar='DIR')
|
2011-06-14 04:42:06 +00:00
|
|
|
group.add_option('--depth', type='int', default=None,
|
|
|
|
dest='depth',
|
|
|
|
help='create a shallow clone with given depth; see git clone')
|
2013-10-16 09:02:35 +00:00
|
|
|
group.add_option('--archive',
|
|
|
|
dest='archive', action='store_true',
|
|
|
|
help='checkout an archive instead of a git repository for '
|
|
|
|
'each project. See git archive.')
|
2012-03-29 03:15:45 +00:00
|
|
|
group.add_option('-g', '--groups',
|
2012-04-16 17:36:08 +00:00
|
|
|
dest='groups', default='default',
|
Special handling for manifest group "default"
Change Details:
* Make "default" a special manifest group that matches any project that
does not have the special project group "notdefault"
* Use "default" instead of "all,-notdefault" when user does not specify
manifest group
* Expand -g option help to include example usage of manifest groups
Change Benefits:
* Allow a more intuitive and expressive manifest groups specification:
* "default" instead of "all,-notdefault"
* "default,foo" instead of "all,-notdefault,foo"
* "default,-foo" instead of "all,-notdefault,-foo"
* "foo,-default" which has no equivalent
* Default manifest groups behavior can be restored by the command
'repo init -g default'. This is significantly more intuitive than the
current equivalent command 'repo init -g all,-notdefault'.
Change-Id: I6d0673791d64a650110a917c248bcebb23b279d3
2012-11-15 00:19:00 +00:00
|
|
|
help='restrict manifest projects to ones with specified '
|
|
|
|
'group(s) [default|all|G1,G2,G3|G4,-G5,-G6]',
|
2012-03-29 03:15:45 +00:00
|
|
|
metavar='GROUP')
|
2012-04-16 18:02:21 +00:00
|
|
|
group.add_option('-p', '--platform',
|
|
|
|
dest='platform', default="auto",
|
2012-10-01 23:12:28 +00:00
|
|
|
help='restrict manifest projects to ones with a specified '
|
2012-04-16 18:02:21 +00:00
|
|
|
'platform group [auto|all|none|linux|darwin|...]',
|
|
|
|
metavar='PLATFORM')
|
2011-06-14 04:42:06 +00:00
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
# Tool
|
2009-04-18 18:28:57 +00:00
|
|
|
group = init_optparse.add_option_group('repo Version options')
|
2008-10-21 14:00:00 +00:00
|
|
|
group.add_option('--repo-url',
|
|
|
|
dest='repo_url',
|
|
|
|
help='repo repository location', metavar='URL')
|
|
|
|
group.add_option('--repo-branch',
|
|
|
|
dest='repo_branch',
|
|
|
|
help='repo branch or revision', metavar='REVISION')
|
|
|
|
group.add_option('--no-repo-verify',
|
|
|
|
dest='no_repo_verify', action='store_true',
|
|
|
|
help='do not verify repo source code')
|
|
|
|
|
2011-04-05 09:31:10 +00:00
|
|
|
# Other
|
|
|
|
group = init_optparse.add_option_group('Other options')
|
|
|
|
group.add_option('--config-name',
|
|
|
|
dest='config_name', action="store_true", default=False,
|
|
|
|
help='Always prompt for name/e-mail')
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2016-02-10 17:44:30 +00:00
|
|
|
|
|
|
|
def _GitcInitOptions(init_optparse_arg):
|
|
|
|
init_optparse_arg.set_usage("repo gitc-init -u url -c client [options]")
|
|
|
|
g = init_optparse_arg.add_option_group('GITC options')
|
2015-08-05 22:04:22 +00:00
|
|
|
g.add_option('-f', '--manifest-file',
|
|
|
|
dest='manifest_file',
|
|
|
|
help='Optional manifest file to use for this GITC client.')
|
|
|
|
g.add_option('-c', '--gitc-client',
|
|
|
|
dest='gitc_client',
|
2015-10-06 22:23:19 +00:00
|
|
|
help='The name of the gitc_client instance to create or modify.')
|
2015-08-05 22:04:22 +00:00
|
|
|
|
2015-08-28 21:25:44 +00:00
|
|
|
_gitc_manifest_dir = None
|
2016-02-10 17:44:30 +00:00
|
|
|
|
|
|
|
|
2015-08-28 21:25:44 +00:00
|
|
|
def get_gitc_manifest_dir():
|
|
|
|
global _gitc_manifest_dir
|
|
|
|
if _gitc_manifest_dir is None:
|
2015-08-31 22:45:06 +00:00
|
|
|
_gitc_manifest_dir = ''
|
2015-08-28 21:25:44 +00:00
|
|
|
try:
|
|
|
|
with open(GITC_CONFIG_FILE, 'r') as gitc_config:
|
|
|
|
for line in gitc_config:
|
|
|
|
match = re.match('gitc_dir=(?P<gitc_manifest_dir>.*)', line)
|
|
|
|
if match:
|
|
|
|
_gitc_manifest_dir = match.group('gitc_manifest_dir')
|
|
|
|
except IOError:
|
2015-08-31 22:45:06 +00:00
|
|
|
pass
|
2015-08-28 21:25:44 +00:00
|
|
|
return _gitc_manifest_dir
|
|
|
|
|
2016-02-10 17:44:30 +00:00
|
|
|
|
2015-10-06 22:23:19 +00:00
|
|
|
def gitc_parse_clientdir(gitc_fs_path):
|
|
|
|
"""Parse a path in the GITC FS and return its client name.
|
|
|
|
|
|
|
|
@param gitc_fs_path: A subdirectory path within the GITC_FS_ROOT_DIR.
|
|
|
|
|
|
|
|
@returns: The GITC client name
|
|
|
|
"""
|
|
|
|
if gitc_fs_path == GITC_FS_ROOT_DIR:
|
|
|
|
return None
|
|
|
|
if not gitc_fs_path.startswith(GITC_FS_ROOT_DIR):
|
|
|
|
manifest_dir = get_gitc_manifest_dir()
|
|
|
|
if manifest_dir == '':
|
|
|
|
return None
|
|
|
|
if manifest_dir[-1] != '/':
|
|
|
|
manifest_dir += '/'
|
|
|
|
if gitc_fs_path == manifest_dir:
|
|
|
|
return None
|
|
|
|
if not gitc_fs_path.startswith(manifest_dir):
|
|
|
|
return None
|
|
|
|
return gitc_fs_path.split(manifest_dir)[1].split('/')[0]
|
|
|
|
return gitc_fs_path.split(GITC_FS_ROOT_DIR)[1].split('/')[0]
|
|
|
|
|
2016-02-10 17:44:30 +00:00
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
class CloneFailure(Exception):
|
2016-02-10 17:44:30 +00:00
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
"""Indicate the remote clone of repo itself failed.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2015-08-05 22:04:22 +00:00
|
|
|
def _Init(args, gitc_init=False):
|
2008-10-21 14:00:00 +00:00
|
|
|
"""Installs repo by cloning it over the network.
|
|
|
|
"""
|
2015-08-05 22:04:22 +00:00
|
|
|
if gitc_init:
|
|
|
|
_GitcInitOptions(init_optparse)
|
2008-10-21 14:00:00 +00:00
|
|
|
opt, args = init_optparse.parse_args(args)
|
2012-01-31 03:10:09 +00:00
|
|
|
if args:
|
2008-10-21 14:00:00 +00:00
|
|
|
init_optparse.print_usage()
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
url = opt.repo_url
|
|
|
|
if not url:
|
|
|
|
url = REPO_URL
|
|
|
|
extra_args.append('--repo-url=%s' % url)
|
|
|
|
|
|
|
|
branch = opt.repo_branch
|
|
|
|
if not branch:
|
|
|
|
branch = REPO_REV
|
|
|
|
extra_args.append('--repo-branch=%s' % branch)
|
|
|
|
|
|
|
|
if branch.startswith('refs/heads/'):
|
|
|
|
branch = branch[len('refs/heads/'):]
|
|
|
|
if branch.startswith('refs/'):
|
2013-09-26 22:50:49 +00:00
|
|
|
_print("fatal: invalid branch name '%s'" % branch, file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
raise CloneFailure()
|
|
|
|
|
2013-12-26 22:20:13 +00:00
|
|
|
try:
|
2015-08-05 22:04:22 +00:00
|
|
|
if gitc_init:
|
2015-08-28 21:25:44 +00:00
|
|
|
gitc_manifest_dir = get_gitc_manifest_dir()
|
|
|
|
if not gitc_manifest_dir:
|
2015-08-31 22:45:06 +00:00
|
|
|
_print('fatal: GITC filesystem is not available. Exiting...',
|
2015-08-28 21:25:44 +00:00
|
|
|
file=sys.stderr)
|
|
|
|
sys.exit(1)
|
2015-10-06 22:23:19 +00:00
|
|
|
gitc_client = opt.gitc_client
|
|
|
|
if not gitc_client:
|
|
|
|
gitc_client = gitc_parse_clientdir(os.getcwd())
|
|
|
|
if not gitc_client:
|
2015-08-31 22:45:06 +00:00
|
|
|
_print('fatal: GITC client (-c) is required.', file=sys.stderr)
|
|
|
|
sys.exit(1)
|
2015-10-06 22:23:19 +00:00
|
|
|
client_dir = os.path.join(gitc_manifest_dir, gitc_client)
|
2015-08-05 22:04:22 +00:00
|
|
|
if not os.path.exists(client_dir):
|
|
|
|
os.makedirs(client_dir)
|
|
|
|
os.chdir(client_dir)
|
|
|
|
if os.path.exists(repodir):
|
|
|
|
# This GITC Client has already initialized repo so continue.
|
|
|
|
return
|
|
|
|
|
2013-12-26 22:20:13 +00:00
|
|
|
os.mkdir(repodir)
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno != errno.EEXIST:
|
2013-09-26 22:50:49 +00:00
|
|
|
_print('fatal: cannot make %s directory: %s'
|
|
|
|
% (repodir, e.strerror), file=sys.stderr)
|
2012-11-14 21:17:30 +00:00
|
|
|
# Don't raise CloneFailure; that would delete the
|
2008-10-21 14:00:00 +00:00
|
|
|
# name. Instead exit immediately.
|
|
|
|
#
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
_CheckGitVersion()
|
|
|
|
try:
|
2012-10-01 23:12:28 +00:00
|
|
|
if NeedSetupGnuPG():
|
|
|
|
can_verify = SetupGnuPG(opt.quiet)
|
2008-10-21 14:00:00 +00:00
|
|
|
else:
|
|
|
|
can_verify = True
|
|
|
|
|
|
|
|
dst = os.path.abspath(os.path.join(repodir, S_repo))
|
|
|
|
_Clone(url, dst, opt.quiet)
|
|
|
|
|
|
|
|
if can_verify and not opt.no_repo_verify:
|
|
|
|
rev = _Verify(dst, branch, opt.quiet)
|
|
|
|
else:
|
|
|
|
rev = 'refs/remotes/origin/%s^0' % branch
|
|
|
|
|
|
|
|
_Checkout(dst, branch, rev, opt.quiet)
|
|
|
|
except CloneFailure:
|
|
|
|
if opt.quiet:
|
2013-09-26 22:50:49 +00:00
|
|
|
_print('fatal: repo init failed; run without --quiet to see why',
|
|
|
|
file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
raise
|
|
|
|
|
|
|
|
|
2014-01-30 22:46:03 +00:00
|
|
|
def ParseGitVersion(ver_str):
|
|
|
|
if not ver_str.startswith('git version '):
|
|
|
|
return None
|
|
|
|
|
|
|
|
num_ver_str = ver_str[len('git version '):].strip().split('-')[0]
|
|
|
|
to_tuple = []
|
|
|
|
for num_str in num_ver_str.split('.')[:3]:
|
|
|
|
if num_str.isdigit():
|
|
|
|
to_tuple.append(int(num_str))
|
|
|
|
else:
|
|
|
|
to_tuple.append(0)
|
|
|
|
return tuple(to_tuple)
|
|
|
|
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
def _CheckGitVersion():
|
|
|
|
cmd = [GIT, '--version']
|
2012-06-05 14:55:07 +00:00
|
|
|
try:
|
|
|
|
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
2012-09-09 22:37:57 +00:00
|
|
|
except OSError as e:
|
2013-09-26 22:50:49 +00:00
|
|
|
_print(file=sys.stderr)
|
|
|
|
_print("fatal: '%s' is not available" % GIT, file=sys.stderr)
|
|
|
|
_print('fatal: %s' % e, file=sys.stderr)
|
|
|
|
_print(file=sys.stderr)
|
|
|
|
_print('Please make sure %s is installed and in your path.' % GIT,
|
|
|
|
file=sys.stderr)
|
2012-06-05 14:55:07 +00:00
|
|
|
raise CloneFailure()
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
ver_str = proc.stdout.read().strip()
|
|
|
|
proc.stdout.close()
|
2008-10-28 15:33:34 +00:00
|
|
|
proc.wait()
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2014-01-30 22:46:03 +00:00
|
|
|
ver_act = ParseGitVersion(ver_str)
|
|
|
|
if ver_act is None:
|
2013-09-26 22:50:49 +00:00
|
|
|
_print('error: "%s" unsupported' % ver_str, file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
raise CloneFailure()
|
|
|
|
|
|
|
|
if ver_act < MIN_GIT_VERSION:
|
2012-11-13 23:34:39 +00:00
|
|
|
need = '.'.join(map(str, MIN_GIT_VERSION))
|
2013-09-26 22:50:49 +00:00
|
|
|
_print('fatal: git %s or later required' % need, file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
raise CloneFailure()
|
|
|
|
|
|
|
|
|
2012-10-01 23:12:28 +00:00
|
|
|
def NeedSetupGnuPG():
|
2008-10-21 14:00:00 +00:00
|
|
|
if not os.path.isdir(home_dot_repo):
|
|
|
|
return True
|
|
|
|
|
|
|
|
kv = os.path.join(home_dot_repo, 'keyring-version')
|
|
|
|
if not os.path.exists(kv):
|
|
|
|
return True
|
|
|
|
|
|
|
|
kv = open(kv).read()
|
|
|
|
if not kv:
|
|
|
|
return True
|
|
|
|
|
2012-11-13 23:34:39 +00:00
|
|
|
kv = tuple(map(int, kv.split('.')))
|
2008-10-21 14:00:00 +00:00
|
|
|
if kv < KEYRING_VERSION:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2012-10-01 23:12:28 +00:00
|
|
|
def SetupGnuPG(quiet):
|
2013-12-26 22:20:13 +00:00
|
|
|
try:
|
|
|
|
os.mkdir(home_dot_repo)
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno != errno.EEXIST:
|
2013-09-26 22:50:49 +00:00
|
|
|
_print('fatal: cannot make %s directory: %s'
|
|
|
|
% (home_dot_repo, e.strerror), file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2013-12-26 22:20:13 +00:00
|
|
|
try:
|
|
|
|
os.mkdir(gpg_dir, stat.S_IRWXU)
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno != errno.EEXIST:
|
2013-09-26 22:50:49 +00:00
|
|
|
_print('fatal: cannot make %s directory: %s' % (gpg_dir, e.strerror),
|
|
|
|
file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2010-12-07 19:41:05 +00:00
|
|
|
env = os.environ.copy()
|
2016-07-16 18:11:11 +00:00
|
|
|
try:
|
|
|
|
env['GNUPGHOME'] = gpg_dir
|
|
|
|
except UnicodeEncodeError:
|
|
|
|
env['GNUPGHOME'] = gpg_dir.encode()
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
cmd = ['gpg', '--import']
|
|
|
|
try:
|
|
|
|
proc = subprocess.Popen(cmd,
|
2016-02-10 17:44:30 +00:00
|
|
|
env=env,
|
|
|
|
stdin=subprocess.PIPE)
|
2012-09-09 22:37:57 +00:00
|
|
|
except OSError as e:
|
2008-10-21 14:00:00 +00:00
|
|
|
if not quiet:
|
2013-09-26 22:50:49 +00:00
|
|
|
_print('warning: gpg (GnuPG) is not available.', file=sys.stderr)
|
|
|
|
_print('warning: Installing it is strongly encouraged.', file=sys.stderr)
|
|
|
|
_print(file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
proc.stdin.write(MAINTAINER_KEYS)
|
|
|
|
proc.stdin.close()
|
|
|
|
|
|
|
|
if proc.wait() != 0:
|
2013-09-26 22:50:49 +00:00
|
|
|
_print('fatal: registering repo maintainer keys failed', file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
sys.exit(1)
|
2013-09-26 22:50:49 +00:00
|
|
|
_print()
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
fd = open(os.path.join(home_dot_repo, 'keyring-version'), 'w')
|
2012-11-13 23:34:39 +00:00
|
|
|
fd.write('.'.join(map(str, KEYRING_VERSION)) + '\n')
|
2008-10-21 14:00:00 +00:00
|
|
|
fd.close()
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def _SetConfig(local, name, value):
|
|
|
|
"""Set a git configuration option to the specified value.
|
|
|
|
"""
|
|
|
|
cmd = [GIT, 'config', name, value]
|
2016-02-10 17:44:30 +00:00
|
|
|
if subprocess.Popen(cmd, cwd=local).wait() != 0:
|
2008-10-21 14:00:00 +00:00
|
|
|
raise CloneFailure()
|
|
|
|
|
|
|
|
|
2011-09-19 21:50:58 +00:00
|
|
|
def _InitHttp():
|
|
|
|
handlers = []
|
|
|
|
|
2012-10-31 16:21:55 +00:00
|
|
|
mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
|
2011-09-19 21:50:58 +00:00
|
|
|
try:
|
|
|
|
import netrc
|
|
|
|
n = netrc.netrc()
|
|
|
|
for host in n.hosts:
|
|
|
|
p = n.hosts[host]
|
2016-02-10 17:44:30 +00:00
|
|
|
mgr.add_password(p[1], 'http://%s/' % host, p[0], p[2])
|
2012-01-31 03:10:09 +00:00
|
|
|
mgr.add_password(p[1], 'https://%s/' % host, p[0], p[2])
|
2016-02-10 17:44:30 +00:00
|
|
|
except: # pylint: disable=bare-except
|
2011-09-19 21:50:58 +00:00
|
|
|
pass
|
2012-10-31 16:21:55 +00:00
|
|
|
handlers.append(urllib.request.HTTPBasicAuthHandler(mgr))
|
|
|
|
handlers.append(urllib.request.HTTPDigestAuthHandler(mgr))
|
2011-09-19 21:50:58 +00:00
|
|
|
|
|
|
|
if 'http_proxy' in os.environ:
|
|
|
|
url = os.environ['http_proxy']
|
2012-10-31 16:21:55 +00:00
|
|
|
handlers.append(urllib.request.ProxyHandler({'http': url, 'https': url}))
|
2011-09-19 21:50:58 +00:00
|
|
|
if 'REPO_CURL_VERBOSE' in os.environ:
|
2012-10-31 16:21:55 +00:00
|
|
|
handlers.append(urllib.request.HTTPHandler(debuglevel=1))
|
|
|
|
handlers.append(urllib.request.HTTPSHandler(debuglevel=1))
|
|
|
|
urllib.request.install_opener(urllib.request.build_opener(*handlers))
|
2011-09-19 21:50:58 +00:00
|
|
|
|
2016-02-10 17:44:30 +00:00
|
|
|
|
2011-09-19 21:50:58 +00:00
|
|
|
def _Fetch(url, local, src, quiet):
|
|
|
|
if not quiet:
|
2013-09-26 22:50:49 +00:00
|
|
|
_print('Get %s' % url, file=sys.stderr)
|
2011-09-19 21:50:58 +00:00
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
cmd = [GIT, 'fetch']
|
|
|
|
if quiet:
|
|
|
|
cmd.append('--quiet')
|
|
|
|
err = subprocess.PIPE
|
|
|
|
else:
|
|
|
|
err = None
|
2011-09-19 21:50:58 +00:00
|
|
|
cmd.append(src)
|
|
|
|
cmd.append('+refs/heads/*:refs/remotes/origin/*')
|
|
|
|
cmd.append('refs/tags/*:refs/tags/*')
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2016-02-10 17:44:30 +00:00
|
|
|
proc = subprocess.Popen(cmd, cwd=local, stderr=err)
|
2008-10-21 14:00:00 +00:00
|
|
|
if err:
|
|
|
|
proc.stderr.read()
|
|
|
|
proc.stderr.close()
|
|
|
|
if proc.wait() != 0:
|
|
|
|
raise CloneFailure()
|
|
|
|
|
2016-02-10 17:44:30 +00:00
|
|
|
|
2011-09-19 21:50:58 +00:00
|
|
|
def _DownloadBundle(url, local, quiet):
|
|
|
|
if not url.endswith('/'):
|
|
|
|
url += '/'
|
|
|
|
url += 'clone.bundle'
|
|
|
|
|
|
|
|
proc = subprocess.Popen(
|
2016-02-10 17:44:30 +00:00
|
|
|
[GIT, 'config', '--get-regexp', 'url.*.insteadof'],
|
|
|
|
cwd=local,
|
|
|
|
stdout=subprocess.PIPE)
|
2011-09-19 21:50:58 +00:00
|
|
|
for line in proc.stdout:
|
|
|
|
m = re.compile(r'^url\.(.*)\.insteadof (.*)$').match(line)
|
|
|
|
if m:
|
|
|
|
new_url = m.group(1)
|
|
|
|
old_url = m.group(2)
|
|
|
|
if url.startswith(old_url):
|
|
|
|
url = new_url + url[len(old_url):]
|
|
|
|
break
|
|
|
|
proc.stdout.close()
|
|
|
|
proc.wait()
|
|
|
|
|
|
|
|
if not url.startswith('http:') and not url.startswith('https:'):
|
|
|
|
return False
|
|
|
|
|
|
|
|
dest = open(os.path.join(local, '.git', 'clone.bundle'), 'w+b')
|
|
|
|
try:
|
|
|
|
try:
|
2012-10-31 16:21:55 +00:00
|
|
|
r = urllib.request.urlopen(url)
|
|
|
|
except urllib.error.HTTPError as e:
|
2015-08-12 18:12:51 +00:00
|
|
|
if e.code in [401, 403, 404, 501]:
|
2011-09-19 21:50:58 +00:00
|
|
|
return False
|
2013-09-26 22:50:49 +00:00
|
|
|
_print('fatal: Cannot get %s' % url, file=sys.stderr)
|
|
|
|
_print('fatal: HTTP error %s' % e.code, file=sys.stderr)
|
2011-09-19 21:50:58 +00:00
|
|
|
raise CloneFailure()
|
2012-10-31 16:21:55 +00:00
|
|
|
except urllib.error.URLError as e:
|
2013-09-26 22:50:49 +00:00
|
|
|
_print('fatal: Cannot get %s' % url, file=sys.stderr)
|
|
|
|
_print('fatal: error %s' % e.reason, file=sys.stderr)
|
2011-09-19 21:50:58 +00:00
|
|
|
raise CloneFailure()
|
|
|
|
try:
|
|
|
|
if not quiet:
|
2013-09-26 22:50:49 +00:00
|
|
|
_print('Get %s' % url, file=sys.stderr)
|
2011-09-19 21:50:58 +00:00
|
|
|
while True:
|
|
|
|
buf = r.read(8192)
|
|
|
|
if buf == '':
|
|
|
|
return True
|
|
|
|
dest.write(buf)
|
|
|
|
finally:
|
|
|
|
r.close()
|
|
|
|
finally:
|
|
|
|
dest.close()
|
|
|
|
|
2016-02-10 17:44:30 +00:00
|
|
|
|
2011-09-19 21:50:58 +00:00
|
|
|
def _ImportBundle(local):
|
|
|
|
path = os.path.join(local, '.git', 'clone.bundle')
|
|
|
|
try:
|
|
|
|
_Fetch(local, local, path, True)
|
|
|
|
finally:
|
|
|
|
os.remove(path)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2016-02-10 17:44:30 +00:00
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
def _Clone(url, local, quiet):
|
|
|
|
"""Clones a git repository to a new subdirectory of repodir
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
os.mkdir(local)
|
2012-09-09 22:37:57 +00:00
|
|
|
except OSError as e:
|
2013-09-26 22:50:49 +00:00
|
|
|
_print('fatal: cannot make %s directory: %s' % (local, e.strerror),
|
|
|
|
file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
raise CloneFailure()
|
|
|
|
|
|
|
|
cmd = [GIT, 'init', '--quiet']
|
|
|
|
try:
|
2016-02-10 17:44:30 +00:00
|
|
|
proc = subprocess.Popen(cmd, cwd=local)
|
2012-09-09 22:37:57 +00:00
|
|
|
except OSError as e:
|
2013-09-26 22:50:49 +00:00
|
|
|
_print(file=sys.stderr)
|
|
|
|
_print("fatal: '%s' is not available" % GIT, file=sys.stderr)
|
|
|
|
_print('fatal: %s' % e, file=sys.stderr)
|
|
|
|
_print(file=sys.stderr)
|
|
|
|
_print('Please make sure %s is installed and in your path.' % GIT,
|
2016-02-10 17:44:30 +00:00
|
|
|
file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
raise CloneFailure()
|
|
|
|
if proc.wait() != 0:
|
2013-09-26 22:50:49 +00:00
|
|
|
_print('fatal: could not create %s' % local, file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
raise CloneFailure()
|
|
|
|
|
2011-09-19 21:50:58 +00:00
|
|
|
_InitHttp()
|
2008-10-21 14:00:00 +00:00
|
|
|
_SetConfig(local, 'remote.origin.url', url)
|
2016-02-10 17:44:30 +00:00
|
|
|
_SetConfig(local,
|
|
|
|
'remote.origin.fetch',
|
|
|
|
'+refs/heads/*:refs/remotes/origin/*')
|
2011-09-19 21:50:58 +00:00
|
|
|
if _DownloadBundle(url, local, quiet):
|
|
|
|
_ImportBundle(local)
|
2015-09-02 19:36:30 +00:00
|
|
|
_Fetch(url, local, 'origin', quiet)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _Verify(cwd, branch, quiet):
|
|
|
|
"""Verify the branch has been signed by a tag.
|
|
|
|
"""
|
|
|
|
cmd = [GIT, 'describe', 'origin/%s' % branch]
|
|
|
|
proc = subprocess.Popen(cmd,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
2016-02-10 17:44:30 +00:00
|
|
|
cwd=cwd)
|
2008-10-21 14:00:00 +00:00
|
|
|
cur = proc.stdout.read().strip()
|
|
|
|
proc.stdout.close()
|
|
|
|
|
|
|
|
proc.stderr.read()
|
|
|
|
proc.stderr.close()
|
|
|
|
|
|
|
|
if proc.wait() != 0 or not cur:
|
2013-09-26 22:50:49 +00:00
|
|
|
_print(file=sys.stderr)
|
|
|
|
_print("fatal: branch '%s' has not been signed" % branch, file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
raise CloneFailure()
|
|
|
|
|
|
|
|
m = re.compile(r'^(.*)-[0-9]{1,}-g[0-9a-f]{1,}$').match(cur)
|
|
|
|
if m:
|
|
|
|
cur = m.group(1)
|
|
|
|
if not quiet:
|
2013-09-26 22:50:49 +00:00
|
|
|
_print(file=sys.stderr)
|
|
|
|
_print("info: Ignoring branch '%s'; using tagged release '%s'"
|
2016-02-10 17:44:30 +00:00
|
|
|
% (branch, cur), file=sys.stderr)
|
2013-09-26 22:50:49 +00:00
|
|
|
_print(file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2010-12-07 19:41:05 +00:00
|
|
|
env = os.environ.copy()
|
2016-07-16 18:11:11 +00:00
|
|
|
try:
|
|
|
|
env['GNUPGHOME'] = gpg_dir
|
|
|
|
except UnicodeEncodeError:
|
|
|
|
env['GNUPGHOME'] = gpg_dir.encode()
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
cmd = [GIT, 'tag', '-v', cur]
|
|
|
|
proc = subprocess.Popen(cmd,
|
2016-02-10 17:44:30 +00:00
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
cwd=cwd,
|
|
|
|
env=env)
|
2008-10-21 14:00:00 +00:00
|
|
|
out = proc.stdout.read()
|
|
|
|
proc.stdout.close()
|
|
|
|
|
|
|
|
err = proc.stderr.read()
|
|
|
|
proc.stderr.close()
|
|
|
|
|
|
|
|
if proc.wait() != 0:
|
2013-09-26 22:50:49 +00:00
|
|
|
_print(file=sys.stderr)
|
|
|
|
_print(out, file=sys.stderr)
|
|
|
|
_print(err, file=sys.stderr)
|
|
|
|
_print(file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
raise CloneFailure()
|
|
|
|
return '%s^0' % cur
|
|
|
|
|
|
|
|
|
|
|
|
def _Checkout(cwd, branch, rev, quiet):
|
|
|
|
"""Checkout an upstream branch into the repository and track it.
|
|
|
|
"""
|
|
|
|
cmd = [GIT, 'update-ref', 'refs/heads/default', rev]
|
2016-02-10 17:44:30 +00:00
|
|
|
if subprocess.Popen(cmd, cwd=cwd).wait() != 0:
|
2008-10-21 14:00:00 +00:00
|
|
|
raise CloneFailure()
|
|
|
|
|
|
|
|
_SetConfig(cwd, 'branch.default.remote', 'origin')
|
|
|
|
_SetConfig(cwd, 'branch.default.merge', 'refs/heads/%s' % branch)
|
|
|
|
|
|
|
|
cmd = [GIT, 'symbolic-ref', 'HEAD', 'refs/heads/default']
|
2016-02-10 17:44:30 +00:00
|
|
|
if subprocess.Popen(cmd, cwd=cwd).wait() != 0:
|
2008-10-21 14:00:00 +00:00
|
|
|
raise CloneFailure()
|
|
|
|
|
|
|
|
cmd = [GIT, 'read-tree', '--reset', '-u']
|
|
|
|
if not quiet:
|
|
|
|
cmd.append('-v')
|
|
|
|
cmd.append('HEAD')
|
2016-02-10 17:44:30 +00:00
|
|
|
if subprocess.Popen(cmd, cwd=cwd).wait() != 0:
|
2008-10-21 14:00:00 +00:00
|
|
|
raise CloneFailure()
|
|
|
|
|
|
|
|
|
|
|
|
def _FindRepo():
|
|
|
|
"""Look for a repo installation, starting at the current directory.
|
|
|
|
"""
|
2012-09-29 22:37:55 +00:00
|
|
|
curdir = os.getcwd()
|
2008-10-21 14:00:00 +00:00
|
|
|
repo = None
|
|
|
|
|
2011-01-10 01:31:57 +00:00
|
|
|
olddir = None
|
2012-09-29 22:37:55 +00:00
|
|
|
while curdir != '/' \
|
2016-02-10 17:44:30 +00:00
|
|
|
and curdir != olddir \
|
|
|
|
and not repo:
|
2012-09-29 22:37:55 +00:00
|
|
|
repo = os.path.join(curdir, repodir, REPO_MAIN)
|
2008-10-21 14:00:00 +00:00
|
|
|
if not os.path.isfile(repo):
|
|
|
|
repo = None
|
2012-09-29 22:37:55 +00:00
|
|
|
olddir = curdir
|
|
|
|
curdir = os.path.dirname(curdir)
|
|
|
|
return (repo, os.path.join(curdir, repodir))
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
|
2016-02-10 17:44:30 +00:00
|
|
|
class _Options(object):
|
2008-10-21 14:00:00 +00:00
|
|
|
help = False
|
|
|
|
|
|
|
|
|
|
|
|
def _ParseArguments(args):
|
|
|
|
cmd = None
|
|
|
|
opt = _Options()
|
|
|
|
arg = []
|
|
|
|
|
2012-11-01 20:36:50 +00:00
|
|
|
for i in range(len(args)):
|
2008-10-21 14:00:00 +00:00
|
|
|
a = args[i]
|
|
|
|
if a == '-h' or a == '--help':
|
|
|
|
opt.help = True
|
|
|
|
|
|
|
|
elif not a.startswith('-'):
|
|
|
|
cmd = a
|
|
|
|
arg = args[i + 1:]
|
|
|
|
break
|
|
|
|
return cmd, opt, arg
|
|
|
|
|
|
|
|
|
|
|
|
def _Usage():
|
2015-08-31 22:45:06 +00:00
|
|
|
gitc_usage = ""
|
|
|
|
if get_gitc_manifest_dir():
|
|
|
|
gitc_usage = " gitc-init Initialize a GITC Client.\n"
|
|
|
|
|
2013-09-26 22:50:49 +00:00
|
|
|
_print(
|
2016-02-10 17:44:30 +00:00
|
|
|
"""usage: repo COMMAND [ARGS]
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
repo is not yet installed. Use "repo init" to install it here.
|
|
|
|
|
|
|
|
The most commonly used repo commands are:
|
|
|
|
|
|
|
|
init Install repo in the current working directory
|
2015-08-31 22:45:06 +00:00
|
|
|
""" + gitc_usage +
|
2016-02-10 17:44:30 +00:00
|
|
|
""" help Display detailed help on a command
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
For access to the full online help, install repo ("repo init").
|
2012-11-02 05:59:27 +00:00
|
|
|
""", file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
def _Help(args):
|
|
|
|
if args:
|
|
|
|
if args[0] == 'init':
|
|
|
|
init_optparse.print_help()
|
2011-01-03 10:35:15 +00:00
|
|
|
sys.exit(0)
|
2015-08-31 22:45:06 +00:00
|
|
|
elif args[0] == 'gitc-init':
|
|
|
|
_GitcInitOptions(init_optparse)
|
|
|
|
init_optparse.print_help()
|
|
|
|
sys.exit(0)
|
2008-10-21 14:00:00 +00:00
|
|
|
else:
|
2013-09-26 22:50:49 +00:00
|
|
|
_print("error: '%s' is not a bootstrap command.\n"
|
|
|
|
' For access to online help, install repo ("repo init").'
|
|
|
|
% args[0], file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
else:
|
|
|
|
_Usage()
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
def _NotInstalled():
|
2013-09-26 22:50:49 +00:00
|
|
|
_print('error: repo is not installed. Use "repo init" to install it here.',
|
|
|
|
file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
def _NoCommands(cmd):
|
2013-09-26 22:50:49 +00:00
|
|
|
_print("""error: command '%s' requires repo to be installed first.
|
|
|
|
Use "repo init" to install it here.""" % cmd, file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
def _RunSelf(wrapper_path):
|
|
|
|
my_dir = os.path.dirname(wrapper_path)
|
|
|
|
my_main = os.path.join(my_dir, 'main.py')
|
|
|
|
my_git = os.path.join(my_dir, '.git')
|
|
|
|
|
|
|
|
if os.path.isfile(my_main) and os.path.isdir(my_git):
|
2009-05-18 20:19:57 +00:00
|
|
|
for name in ['git_config.py',
|
2008-10-21 14:00:00 +00:00
|
|
|
'project.py',
|
|
|
|
'subcmds']:
|
|
|
|
if not os.path.exists(os.path.join(my_dir, name)):
|
|
|
|
return None, None
|
|
|
|
return my_main, my_git
|
|
|
|
return None, None
|
|
|
|
|
|
|
|
|
|
|
|
def _SetDefaultsTo(gitdir):
|
|
|
|
global REPO_URL
|
|
|
|
global REPO_REV
|
|
|
|
|
|
|
|
REPO_URL = gitdir
|
|
|
|
proc = subprocess.Popen([GIT,
|
|
|
|
'--git-dir=%s' % gitdir,
|
|
|
|
'symbolic-ref',
|
|
|
|
'HEAD'],
|
2016-02-10 17:44:30 +00:00
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE)
|
2008-10-21 14:00:00 +00:00
|
|
|
REPO_REV = proc.stdout.read().strip()
|
|
|
|
proc.stdout.close()
|
|
|
|
|
|
|
|
proc.stderr.read()
|
|
|
|
proc.stderr.close()
|
|
|
|
|
|
|
|
if proc.wait() != 0:
|
2013-09-26 22:50:49 +00:00
|
|
|
_print('fatal: %s has no current branch' % gitdir, file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
def main(orig_args):
|
|
|
|
cmd, opt, args = _ParseArguments(orig_args)
|
|
|
|
|
2015-10-06 22:23:19 +00:00
|
|
|
repo_main, rel_repo_dir = None, None
|
|
|
|
# Don't use the local repo copy, make sure to switch to the gitc client first.
|
|
|
|
if cmd != 'gitc-init':
|
|
|
|
repo_main, rel_repo_dir = _FindRepo()
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
wrapper_path = os.path.abspath(__file__)
|
|
|
|
my_main, my_git = _RunSelf(wrapper_path)
|
|
|
|
|
2015-08-28 21:25:44 +00:00
|
|
|
cwd = os.getcwd()
|
2015-08-31 22:45:06 +00:00
|
|
|
if get_gitc_manifest_dir() and cwd.startswith(get_gitc_manifest_dir()):
|
2015-08-28 21:25:44 +00:00
|
|
|
_print('error: repo cannot be used in the GITC local manifest directory.'
|
|
|
|
'\nIf you want to work on this GITC client please rerun this '
|
2016-02-10 17:44:30 +00:00
|
|
|
'command from the corresponding client under /gitc/',
|
|
|
|
file=sys.stderr)
|
2015-08-28 21:25:44 +00:00
|
|
|
sys.exit(1)
|
2012-09-29 22:37:55 +00:00
|
|
|
if not repo_main:
|
2008-10-21 14:00:00 +00:00
|
|
|
if opt.help:
|
|
|
|
_Usage()
|
|
|
|
if cmd == 'help':
|
|
|
|
_Help(args)
|
|
|
|
if not cmd:
|
|
|
|
_NotInstalled()
|
2015-08-05 22:04:22 +00:00
|
|
|
if cmd == 'init' or cmd == 'gitc-init':
|
2008-10-21 14:00:00 +00:00
|
|
|
if my_git:
|
|
|
|
_SetDefaultsTo(my_git)
|
|
|
|
try:
|
2015-08-05 22:04:22 +00:00
|
|
|
_Init(args, gitc_init=(cmd == 'gitc-init'))
|
2008-10-21 14:00:00 +00:00
|
|
|
except CloneFailure:
|
2014-09-03 08:24:48 +00:00
|
|
|
shutil.rmtree(os.path.join(repodir, S_repo), ignore_errors=True)
|
2008-10-21 14:00:00 +00:00
|
|
|
sys.exit(1)
|
2012-09-29 22:37:55 +00:00
|
|
|
repo_main, rel_repo_dir = _FindRepo()
|
2008-10-21 14:00:00 +00:00
|
|
|
else:
|
|
|
|
_NoCommands(cmd)
|
|
|
|
|
|
|
|
if my_main:
|
2012-09-29 22:37:55 +00:00
|
|
|
repo_main = my_main
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2012-11-13 23:34:39 +00:00
|
|
|
ver_str = '.'.join(map(str, VERSION))
|
2013-09-21 16:29:10 +00:00
|
|
|
me = [sys.executable, repo_main,
|
2012-09-29 22:37:55 +00:00
|
|
|
'--repo-dir=%s' % rel_repo_dir,
|
2008-10-21 14:00:00 +00:00
|
|
|
'--wrapper-version=%s' % ver_str,
|
|
|
|
'--wrapper-path=%s' % wrapper_path,
|
|
|
|
'--']
|
|
|
|
me.extend(orig_args)
|
|
|
|
me.extend(extra_args)
|
|
|
|
try:
|
2013-09-21 16:29:10 +00:00
|
|
|
os.execv(sys.executable, me)
|
2012-09-09 22:37:57 +00:00
|
|
|
except OSError as e:
|
2013-09-26 22:50:49 +00:00
|
|
|
_print("fatal: unable to start %s" % repo_main, file=sys.stderr)
|
|
|
|
_print("fatal: %s" % e, file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
sys.exit(148)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2014-05-05 19:37:05 +00:00
|
|
|
if ver[0] == 3:
|
|
|
|
_print('warning: Python 3 support is currently experimental. YMMV.\n'
|
|
|
|
'Please use Python 2.6 - 2.7 instead.',
|
|
|
|
file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
main(sys.argv[1:])
|