2019-06-13 06:30:51 +00:00
|
|
|
# -*- coding:utf-8 -*-
|
2008-10-21 14:00:00 +00:00
|
|
|
#
|
|
|
|
# Copyright (C) 2008 The Android Open Source Project
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2012-11-02 05:59:27 +00:00
|
|
|
from __future__ import print_function
|
2008-10-21 14:00:00 +00:00
|
|
|
import os
|
2012-04-16 18:02:21 +00:00
|
|
|
import platform
|
2012-04-16 17:36:08 +00:00
|
|
|
import re
|
2008-10-21 14:00:00 +00:00
|
|
|
import sys
|
2013-05-17 01:49:33 +00:00
|
|
|
|
|
|
|
from pyversion import is_python3
|
|
|
|
if is_python3():
|
2012-10-05 10:37:58 +00:00
|
|
|
import urllib.parse
|
2013-05-17 01:49:33 +00:00
|
|
|
else:
|
2012-10-05 10:37:58 +00:00
|
|
|
import imp
|
|
|
|
import urlparse
|
|
|
|
urllib = imp.new_module('urllib')
|
2015-06-03 16:21:56 +00:00
|
|
|
urllib.parse = urlparse
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
from color import Coloring
|
2009-03-04 01:47:06 +00:00
|
|
|
from command import InteractiveCommand, MirrorSafeCommand
|
2008-10-21 14:00:00 +00:00
|
|
|
from error import ManifestParseError
|
2015-03-17 18:29:58 +00:00
|
|
|
from project import SyncBuffer
|
2011-09-19 21:50:58 +00:00
|
|
|
from git_config import GitConfig
|
2020-02-11 23:51:08 +00:00
|
|
|
from git_command import git_require, MIN_GIT_VERSION_SOFT, MIN_GIT_VERSION_HARD
|
2016-11-03 17:37:53 +00:00
|
|
|
import platform_utils
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2020-02-12 06:20:19 +00:00
|
|
|
|
2009-03-04 01:47:06 +00:00
|
|
|
class Init(InteractiveCommand, MirrorSafeCommand):
|
2008-10-21 14:00:00 +00:00
|
|
|
common = True
|
|
|
|
helpSummary = "Initialize repo in the current directory"
|
|
|
|
helpUsage = """
|
|
|
|
%prog [options]
|
|
|
|
"""
|
|
|
|
helpDescription = """
|
|
|
|
The '%prog' command is run once to install and initialize repo.
|
|
|
|
The latest repo source code and manifest collection is downloaded
|
|
|
|
from the server and is installed in the .repo/ directory in the
|
|
|
|
current working directory.
|
|
|
|
|
2009-04-18 18:33:32 +00:00
|
|
|
The optional -b argument can be used to select the manifest branch
|
|
|
|
to checkout and use. If no branch is specified, master is assumed.
|
|
|
|
|
|
|
|
The optional -m argument can be used to specify an alternate manifest
|
|
|
|
to be used. If no manifest is specified, the manifest default.xml
|
|
|
|
will be used.
|
|
|
|
|
2010-10-08 08:02:09 +00:00
|
|
|
The --reference option can be used to point to a directory that
|
|
|
|
has the content of a --mirror sync. This will make the working
|
|
|
|
directory use as much data as possible from the local reference
|
|
|
|
directory when fetching from the server. This will make the sync
|
|
|
|
go a lot faster by reducing data traffic on the network.
|
|
|
|
|
2018-10-19 10:07:05 +00:00
|
|
|
The --dissociate option can be used to borrow the objects from
|
|
|
|
the directory specified with the --reference option only to reduce
|
|
|
|
network transfer, and stop borrowing from them after a first clone
|
|
|
|
is made by making necessary local copies of borrowed objects.
|
|
|
|
|
2015-12-11 03:16:41 +00:00
|
|
|
The --no-clone-bundle option disables any attempt to use
|
|
|
|
$URL/clone.bundle to bootstrap a new Git repository from a
|
|
|
|
resumeable bundle file on a content delivery network. This
|
|
|
|
may be necessary if there are problems with the local Python
|
|
|
|
HTTP client or proxy configuration, but the Git binary works.
|
2010-10-08 08:02:09 +00:00
|
|
|
|
2018-10-10 05:05:11 +00:00
|
|
|
# Switching Manifest Branches
|
2009-04-18 18:33:32 +00:00
|
|
|
|
|
|
|
To switch to another manifest branch, `repo init -b otherbranch`
|
|
|
|
may be used in an existing client. However, as this only updates the
|
|
|
|
manifest, a subsequent `repo sync` (or `repo sync -d`) is necessary
|
|
|
|
to update the working directory files.
|
2008-10-21 14:00:00 +00:00
|
|
|
"""
|
|
|
|
|
2020-02-05 05:01:59 +00:00
|
|
|
def _Options(self, p, gitc_init=False):
|
2008-10-21 14:00:00 +00:00
|
|
|
# Logging
|
|
|
|
g = p.add_option_group('Logging options')
|
|
|
|
g.add_option('-q', '--quiet',
|
|
|
|
dest="quiet", action="store_true", default=False,
|
|
|
|
help="be quiet")
|
|
|
|
|
|
|
|
# Manifest
|
|
|
|
g = p.add_option_group('Manifest options')
|
|
|
|
g.add_option('-u', '--manifest-url',
|
2011-11-30 21:41:02 +00:00
|
|
|
dest='manifest_url',
|
2008-10-21 14:00:00 +00:00
|
|
|
help='manifest repository location', metavar='URL')
|
|
|
|
g.add_option('-b', '--manifest-branch',
|
|
|
|
dest='manifest_branch',
|
|
|
|
help='manifest branch or revision', metavar='REVISION')
|
2020-02-05 05:01:59 +00:00
|
|
|
cbr_opts = ['--current-branch']
|
|
|
|
# The gitc-init subcommand allocates -c itself, but a lot of init users
|
|
|
|
# want -c, so try to satisfy both as best we can.
|
2020-02-07 01:00:00 +00:00
|
|
|
if not gitc_init:
|
2020-02-05 05:01:59 +00:00
|
|
|
cbr_opts += ['-c']
|
|
|
|
g.add_option(*cbr_opts,
|
2016-12-01 23:49:54 +00:00
|
|
|
dest='current_branch_only', action='store_true',
|
|
|
|
help='fetch only current manifest branch from server')
|
2008-10-21 14:00:00 +00:00
|
|
|
g.add_option('-m', '--manifest-name',
|
|
|
|
dest='manifest_name', default='default.xml',
|
|
|
|
help='initial manifest file', metavar='NAME.xml')
|
2008-11-04 15:37:10 +00:00
|
|
|
g.add_option('--mirror',
|
|
|
|
dest='mirror', action='store_true',
|
2012-08-15 05:22:08 +00:00
|
|
|
help='create a replica of the remote repositories '
|
|
|
|
'rather than a client working directory')
|
2010-10-08 08:02:09 +00:00
|
|
|
g.add_option('--reference',
|
|
|
|
dest='reference',
|
|
|
|
help='location of mirror directory', metavar='DIR')
|
2018-10-19 10:07:05 +00:00
|
|
|
g.add_option('--dissociate',
|
|
|
|
dest='dissociate', action='store_true',
|
|
|
|
help='dissociate from reference mirrors after clone')
|
2011-05-04 22:01:04 +00:00
|
|
|
g.add_option('--depth', type='int', default=None,
|
|
|
|
dest='depth',
|
|
|
|
help='create a shallow clone with given depth; see git clone')
|
2019-06-03 18:24:30 +00:00
|
|
|
g.add_option('--partial-clone', action='store_true',
|
|
|
|
dest='partial_clone',
|
|
|
|
help='perform partial clone (https://git-scm.com/'
|
|
|
|
'docs/gitrepository-layout#_code_partialclone_code)')
|
|
|
|
g.add_option('--clone-filter', action='store', default='blob:none',
|
|
|
|
dest='clone_filter',
|
|
|
|
help='filter for use with --partial-clone [default: %default]')
|
2013-10-16 09:02:35 +00:00
|
|
|
g.add_option('--archive',
|
|
|
|
dest='archive', action='store_true',
|
|
|
|
help='checkout an archive instead of a git repository for '
|
|
|
|
'each project. See git archive.')
|
2017-03-21 23:05:12 +00:00
|
|
|
g.add_option('--submodules',
|
|
|
|
dest='submodules', action='store_true',
|
|
|
|
help='sync any submodules associated with the manifest repo')
|
2012-03-29 03:15:45 +00:00
|
|
|
g.add_option('-g', '--groups',
|
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
|
|
|
dest='groups', default='default',
|
|
|
|
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
|
|
|
g.add_option('-p', '--platform',
|
|
|
|
dest='platform', default='auto',
|
2012-08-13 20:11:18 +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')
|
2015-12-11 03:16:41 +00:00
|
|
|
g.add_option('--no-clone-bundle',
|
2020-02-17 19:36:08 +00:00
|
|
|
dest='clone_bundle', default=True, action='store_false',
|
2015-12-11 03:16:41 +00:00
|
|
|
help='disable use of /clone.bundle on HTTP/HTTPS')
|
2016-12-01 23:49:54 +00:00
|
|
|
g.add_option('--no-tags',
|
2020-02-17 19:36:08 +00:00
|
|
|
dest='tags', default=True, action='store_false',
|
2016-12-01 23:49:54 +00:00
|
|
|
help="don't fetch tags in the manifest")
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
# Tool
|
2009-04-18 18:28:57 +00:00
|
|
|
g = p.add_option_group('repo Version options')
|
2008-10-21 14:00:00 +00:00
|
|
|
g.add_option('--repo-url',
|
|
|
|
dest='repo_url',
|
|
|
|
help='repo repository location', metavar='URL')
|
|
|
|
g.add_option('--repo-branch',
|
|
|
|
dest='repo_branch',
|
|
|
|
help='repo branch or revision', metavar='REVISION')
|
|
|
|
g.add_option('--no-repo-verify',
|
2020-02-17 19:36:08 +00:00
|
|
|
dest='repo_verify', default=True, action='store_false',
|
2008-10-21 14:00:00 +00:00
|
|
|
help='do not verify repo source code')
|
|
|
|
|
2011-04-05 09:31:10 +00:00
|
|
|
# Other
|
|
|
|
g = p.add_option_group('Other options')
|
|
|
|
g.add_option('--config-name',
|
|
|
|
dest='config_name', action="store_true", default=False,
|
|
|
|
help='Always prompt for name/e-mail')
|
|
|
|
|
2012-11-16 18:13:09 +00:00
|
|
|
def _RegisteredEnvironmentOptions(self):
|
|
|
|
return {'REPO_MANIFEST_URL': 'manifest_url',
|
|
|
|
'REPO_MIRROR_LOCATION': 'reference'}
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
def _SyncManifest(self, opt):
|
|
|
|
m = self.manifest.manifestProject
|
2009-03-10 01:51:58 +00:00
|
|
|
is_new = not m.Exists
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2009-03-10 01:51:58 +00:00
|
|
|
if is_new:
|
2011-11-30 21:41:02 +00:00
|
|
|
if not opt.manifest_url:
|
2012-11-02 05:59:27 +00:00
|
|
|
print('fatal: manifest url (-u) is required.', file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if not opt.quiet:
|
2012-11-02 05:59:27 +00:00
|
|
|
print('Get %s' % GitConfig.ForUser().UrlInsteadOf(opt.manifest_url),
|
|
|
|
file=sys.stderr)
|
2012-10-05 10:37:58 +00:00
|
|
|
|
|
|
|
# The manifest project object doesn't keep track of the path on the
|
|
|
|
# server where this git is located, so let's save that here.
|
|
|
|
mirrored_manifest_git = None
|
|
|
|
if opt.reference:
|
2015-06-03 16:21:56 +00:00
|
|
|
manifest_git_path = urllib.parse.urlparse(opt.manifest_url).path[1:]
|
2012-10-05 10:37:58 +00:00
|
|
|
mirrored_manifest_git = os.path.join(opt.reference, manifest_git_path)
|
|
|
|
if not mirrored_manifest_git.endswith(".git"):
|
|
|
|
mirrored_manifest_git += ".git"
|
|
|
|
if not os.path.exists(mirrored_manifest_git):
|
2018-01-22 17:00:24 +00:00
|
|
|
mirrored_manifest_git = os.path.join(opt.reference,
|
|
|
|
'.repo/manifests.git')
|
2012-10-05 10:37:58 +00:00
|
|
|
|
|
|
|
m._InitGitDir(mirror_git=mirrored_manifest_git)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
if opt.manifest_branch:
|
2009-05-30 01:38:17 +00:00
|
|
|
m.revisionExpr = opt.manifest_branch
|
2008-10-21 14:00:00 +00:00
|
|
|
else:
|
2009-05-30 01:38:17 +00:00
|
|
|
m.revisionExpr = 'refs/heads/master'
|
2008-10-21 14:00:00 +00:00
|
|
|
else:
|
|
|
|
if opt.manifest_branch:
|
2009-05-30 01:38:17 +00:00
|
|
|
m.revisionExpr = opt.manifest_branch
|
2008-10-21 14:00:00 +00:00
|
|
|
else:
|
|
|
|
m.PreSync()
|
|
|
|
|
2019-05-21 16:41:35 +00:00
|
|
|
self._ConfigureDepth(opt)
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
if opt.manifest_url:
|
|
|
|
r = m.GetRemote(m.remote.name)
|
|
|
|
r.url = opt.manifest_url
|
|
|
|
r.ResetFetch()
|
|
|
|
r.Save()
|
|
|
|
|
2012-10-25 03:23:11 +00:00
|
|
|
groups = re.split(r'[,\s]+', opt.groups)
|
2015-10-22 20:26:36 +00:00
|
|
|
all_platforms = ['linux', 'darwin', 'windows']
|
2012-04-16 18:02:21 +00:00
|
|
|
platformize = lambda x: 'platform-' + x
|
|
|
|
if opt.platform == 'auto':
|
|
|
|
if (not opt.mirror and
|
2020-02-12 05:58:39 +00:00
|
|
|
not m.config.GetString('repo.mirror') == 'true'):
|
2012-04-16 18:02:21 +00:00
|
|
|
groups.append(platformize(platform.system().lower()))
|
|
|
|
elif opt.platform == 'all':
|
2012-04-23 20:39:48 +00:00
|
|
|
groups.extend(map(platformize, all_platforms))
|
2012-04-16 18:02:21 +00:00
|
|
|
elif opt.platform in all_platforms:
|
2015-10-22 20:26:36 +00:00
|
|
|
groups.append(platformize(opt.platform))
|
2012-04-16 18:02:21 +00:00
|
|
|
elif opt.platform != 'none':
|
2012-11-02 05:59:27 +00:00
|
|
|
print('fatal: invalid platform flag', file=sys.stderr)
|
2012-04-16 18:02:21 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2012-04-16 17:36:08 +00:00
|
|
|
groups = [x for x in groups if x]
|
|
|
|
groupstr = ','.join(groups)
|
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
|
|
|
if opt.platform == 'auto' and groupstr == 'default,platform-' + platform.system().lower():
|
2012-04-16 17:36:08 +00:00
|
|
|
groupstr = None
|
|
|
|
m.config.SetString('manifest.groups', groupstr)
|
2012-03-29 03:15:45 +00:00
|
|
|
|
2010-10-08 08:02:09 +00:00
|
|
|
if opt.reference:
|
|
|
|
m.config.SetString('repo.reference', opt.reference)
|
|
|
|
|
2018-10-19 10:07:05 +00:00
|
|
|
if opt.dissociate:
|
|
|
|
m.config.SetString('repo.dissociate', 'true')
|
|
|
|
|
2013-10-16 09:02:35 +00:00
|
|
|
if opt.archive:
|
|
|
|
if is_new:
|
|
|
|
m.config.SetString('repo.archive', 'true')
|
|
|
|
else:
|
|
|
|
print('fatal: --archive is only supported when initializing a new '
|
|
|
|
'workspace.', file=sys.stderr)
|
|
|
|
print('Either delete the .repo folder in this workspace, or initialize '
|
|
|
|
'in another location.', file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2008-11-04 15:37:10 +00:00
|
|
|
if opt.mirror:
|
2009-03-10 01:51:58 +00:00
|
|
|
if is_new:
|
|
|
|
m.config.SetString('repo.mirror', 'true')
|
|
|
|
else:
|
2012-11-21 05:41:58 +00:00
|
|
|
print('fatal: --mirror is only supported when initializing a new '
|
|
|
|
'workspace.', file=sys.stderr)
|
|
|
|
print('Either delete the .repo folder in this workspace, or initialize '
|
|
|
|
'in another location.', file=sys.stderr)
|
2009-03-10 01:51:58 +00:00
|
|
|
sys.exit(1)
|
2008-11-04 15:37:10 +00:00
|
|
|
|
2019-06-03 18:24:30 +00:00
|
|
|
if opt.partial_clone:
|
|
|
|
if opt.mirror:
|
|
|
|
print('fatal: --mirror and --partial-clone are mutually exclusive',
|
|
|
|
file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
m.config.SetString('repo.partialclone', 'true')
|
|
|
|
if opt.clone_filter:
|
|
|
|
m.config.SetString('repo.clonefilter', opt.clone_filter)
|
|
|
|
else:
|
|
|
|
opt.clone_filter = None
|
|
|
|
|
2017-03-21 23:05:12 +00:00
|
|
|
if opt.submodules:
|
|
|
|
m.config.SetString('repo.submodules', 'true')
|
|
|
|
|
2015-12-11 03:16:41 +00:00
|
|
|
if not m.Sync_NetworkHalf(is_new=is_new, quiet=opt.quiet,
|
2020-02-17 19:36:08 +00:00
|
|
|
clone_bundle=opt.clone_bundle,
|
2020-02-12 05:58:39 +00:00
|
|
|
current_branch_only=opt.current_branch_only,
|
2020-02-17 19:36:08 +00:00
|
|
|
tags=opt.tags, submodules=opt.submodules,
|
2020-02-12 05:58:39 +00:00
|
|
|
clone_filter=opt.clone_filter):
|
2009-03-17 15:06:18 +00:00
|
|
|
r = m.GetRemote(m.remote.name)
|
2012-11-02 05:59:27 +00:00
|
|
|
print('fatal: cannot obtain manifest %s' % r.url, file=sys.stderr)
|
2011-04-07 20:36:30 +00:00
|
|
|
|
|
|
|
# Better delete the manifest git dir if we created it; otherwise next
|
|
|
|
# time (when user fixes problems) we won't go through the "is_new" logic.
|
|
|
|
if is_new:
|
2016-11-03 17:37:53 +00:00
|
|
|
platform_utils.rmtree(m.gitdir)
|
2009-03-17 15:06:18 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2012-06-07 15:19:26 +00:00
|
|
|
if opt.manifest_branch:
|
2017-07-10 21:46:25 +00:00
|
|
|
m.MetaBranchSwitch(submodules=opt.submodules)
|
2012-06-07 15:19:26 +00:00
|
|
|
|
Change repo sync to be more friendly when updating the tree
We now try to sync all projects that can be done safely first, before
we start rebasing user commits over the upstream. This has the nice
effect of making the local tree as close to the upstream as possible
before the user has to start resolving merge conflicts, as that extra
information in other projects may aid in the conflict resolution.
Informational output is buffered and delayed until calculation for
all projects has been done, so that the user gets one concise list
of notice messages, rather than it interrupting the progress meter.
Fast-forward output is now prefixed with the project header, so the
user can see which project that update is taking place in, and make
some relation of the diffstat back to the project name.
Rebase output is now prefixed with the project header, so that if
the rebase fails, the user can see which project we were operating
on and can try to address the failure themselves.
Since rebase sits on a detached HEAD, we now look for an in-progress
rebase during sync, so we can alert the user that the given project
is in a state we cannot handle.
Signed-off-by: Shawn O. Pearce <sop@google.com>
2009-04-16 18:21:18 +00:00
|
|
|
syncbuf = SyncBuffer(m.config)
|
2017-03-21 23:05:12 +00:00
|
|
|
m.Sync_LocalHalf(syncbuf, submodules=opt.submodules)
|
Change repo sync to be more friendly when updating the tree
We now try to sync all projects that can be done safely first, before
we start rebasing user commits over the upstream. This has the nice
effect of making the local tree as close to the upstream as possible
before the user has to start resolving merge conflicts, as that extra
information in other projects may aid in the conflict resolution.
Informational output is buffered and delayed until calculation for
all projects has been done, so that the user gets one concise list
of notice messages, rather than it interrupting the progress meter.
Fast-forward output is now prefixed with the project header, so the
user can see which project that update is taking place in, and make
some relation of the diffstat back to the project name.
Rebase output is now prefixed with the project header, so that if
the rebase fails, the user can see which project we were operating
on and can try to address the failure themselves.
Since rebase sits on a detached HEAD, we now look for an in-progress
rebase during sync, so we can alert the user that the given project
is in a state we cannot handle.
Signed-off-by: Shawn O. Pearce <sop@google.com>
2009-04-16 18:21:18 +00:00
|
|
|
syncbuf.Finish()
|
|
|
|
|
2009-03-17 15:15:27 +00:00
|
|
|
if is_new or m.CurrentBranch is None:
|
2009-04-10 23:21:18 +00:00
|
|
|
if not m.StartBranch('default'):
|
2012-11-02 05:59:27 +00:00
|
|
|
print('fatal: cannot create default in manifest', file=sys.stderr)
|
2009-04-10 23:21:18 +00:00
|
|
|
sys.exit(1)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
def _LinkManifest(self, name):
|
|
|
|
if not name:
|
2012-11-02 05:59:27 +00:00
|
|
|
print('fatal: manifest name (-m) is required.', file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.manifest.Link(name)
|
2012-09-09 22:37:57 +00:00
|
|
|
except ManifestParseError as e:
|
2012-11-02 05:59:27 +00:00
|
|
|
print("fatal: manifest '%s' not available" % name, file=sys.stderr)
|
|
|
|
print('fatal: %s' % str(e), file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2009-07-02 17:53:04 +00:00
|
|
|
def _Prompt(self, prompt, value):
|
2019-07-04 21:35:11 +00:00
|
|
|
print('%-10s [%s]: ' % (prompt, value), end='')
|
|
|
|
# TODO: When we require Python 3, use flush=True w/print above.
|
|
|
|
sys.stdout.flush()
|
2008-10-21 14:00:00 +00:00
|
|
|
a = sys.stdin.readline().strip()
|
2009-07-02 17:53:04 +00:00
|
|
|
if a == '':
|
|
|
|
return value
|
|
|
|
return a
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2011-04-05 09:31:10 +00:00
|
|
|
def _ShouldConfigureUser(self):
|
|
|
|
gc = self.manifest.globalConfig
|
|
|
|
mp = self.manifest.manifestProject
|
|
|
|
|
|
|
|
# If we don't have local settings, get from global.
|
|
|
|
if not mp.config.Has('user.name') or not mp.config.Has('user.email'):
|
|
|
|
if not gc.Has('user.name') or not gc.Has('user.email'):
|
|
|
|
return True
|
|
|
|
|
|
|
|
mp.config.SetString('user.name', gc.GetString('user.name'))
|
|
|
|
mp.config.SetString('user.email', gc.GetString('user.email'))
|
|
|
|
|
2012-11-02 05:59:27 +00:00
|
|
|
print()
|
|
|
|
print('Your identity is: %s <%s>' % (mp.config.GetString('user.name'),
|
|
|
|
mp.config.GetString('user.email')))
|
|
|
|
print('If you want to change this, please re-run \'repo init\' with --config-name')
|
2011-04-05 09:31:10 +00:00
|
|
|
return False
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
def _ConfigureUser(self):
|
|
|
|
mp = self.manifest.manifestProject
|
|
|
|
|
2009-07-02 17:53:04 +00:00
|
|
|
while True:
|
2012-11-02 05:59:27 +00:00
|
|
|
print()
|
2020-02-12 05:31:05 +00:00
|
|
|
name = self._Prompt('Your Name', mp.UserName)
|
2009-07-02 17:53:04 +00:00
|
|
|
email = self._Prompt('Your Email', mp.UserEmail)
|
|
|
|
|
2012-11-02 05:59:27 +00:00
|
|
|
print()
|
|
|
|
print('Your identity is: %s <%s>' % (name, email))
|
2019-07-04 21:35:11 +00:00
|
|
|
print('is this correct [y/N]? ', end='')
|
|
|
|
# TODO: When we require Python 3, use flush=True w/print above.
|
|
|
|
sys.stdout.flush()
|
2012-11-14 00:19:39 +00:00
|
|
|
a = sys.stdin.readline().strip().lower()
|
2010-04-01 18:03:53 +00:00
|
|
|
if a in ('yes', 'y', 't', 'true'):
|
2009-07-02 17:53:04 +00:00
|
|
|
break
|
|
|
|
|
|
|
|
if name != mp.UserName:
|
|
|
|
mp.config.SetString('user.name', name)
|
|
|
|
if email != mp.UserEmail:
|
|
|
|
mp.config.SetString('user.email', email)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
def _HasColorSet(self, gc):
|
|
|
|
for n in ['ui', 'diff', 'status']:
|
|
|
|
if gc.Has('color.%s' % n):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def _ConfigureColor(self):
|
|
|
|
gc = self.manifest.globalConfig
|
|
|
|
if self._HasColorSet(gc):
|
|
|
|
return
|
|
|
|
|
|
|
|
class _Test(Coloring):
|
|
|
|
def __init__(self):
|
|
|
|
Coloring.__init__(self, gc, 'test color display')
|
|
|
|
self._on = True
|
|
|
|
out = _Test()
|
|
|
|
|
2012-11-02 05:59:27 +00:00
|
|
|
print()
|
|
|
|
print("Testing colorized output (for 'repo diff', 'repo status'):")
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2012-11-14 03:09:38 +00:00
|
|
|
for c in ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan']:
|
2008-10-21 14:00:00 +00:00
|
|
|
out.write(' ')
|
|
|
|
out.printer(fg=c)(' %-6s ', c)
|
|
|
|
out.write(' ')
|
|
|
|
out.printer(fg='white', bg='black')(' %s ' % 'white')
|
|
|
|
out.nl()
|
|
|
|
|
2012-11-14 03:09:38 +00:00
|
|
|
for c in ['bold', 'dim', 'ul', 'reverse']:
|
2008-10-21 14:00:00 +00:00
|
|
|
out.write(' ')
|
|
|
|
out.printer(fg='black', attr=c)(' %-6s ', c)
|
|
|
|
out.nl()
|
|
|
|
|
2019-07-04 21:35:11 +00:00
|
|
|
print('Enable color display in this user account (y/N)? ', end='')
|
|
|
|
# TODO: When we require Python 3, use flush=True w/print above.
|
|
|
|
sys.stdout.flush()
|
2008-10-21 14:00:00 +00:00
|
|
|
a = sys.stdin.readline().strip().lower()
|
|
|
|
if a in ('y', 'yes', 't', 'true', 'on'):
|
|
|
|
gc.SetString('color.ui', 'auto')
|
|
|
|
|
2011-05-04 22:01:04 +00:00
|
|
|
def _ConfigureDepth(self, opt):
|
|
|
|
"""Configure the depth we'll sync down.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
opt: Options from optparse. We care about opt.depth.
|
|
|
|
"""
|
|
|
|
# Opt.depth will be non-None if user actually passed --depth to repo init.
|
|
|
|
if opt.depth is not None:
|
|
|
|
if opt.depth > 0:
|
|
|
|
# Positive values will set the depth.
|
|
|
|
depth = str(opt.depth)
|
|
|
|
else:
|
|
|
|
# Negative numbers will clear the depth; passing None to SetString
|
|
|
|
# will do that.
|
|
|
|
depth = None
|
|
|
|
|
|
|
|
# We store the depth in the main manifest project.
|
|
|
|
self.manifest.manifestProject.config.SetString('repo.depth', depth)
|
|
|
|
|
2012-10-23 07:41:54 +00:00
|
|
|
def _DisplayResult(self):
|
|
|
|
if self.manifest.IsMirror:
|
|
|
|
init_type = 'mirror '
|
|
|
|
else:
|
|
|
|
init_type = ''
|
|
|
|
|
2012-11-02 05:59:27 +00:00
|
|
|
print()
|
|
|
|
print('repo %shas been initialized in %s'
|
|
|
|
% (init_type, self.manifest.topdir))
|
2012-10-23 07:41:54 +00:00
|
|
|
|
|
|
|
current_dir = os.getcwd()
|
|
|
|
if current_dir != self.manifest.topdir:
|
2013-01-29 00:49:48 +00:00
|
|
|
print('If this is not the directory in which you want to initialize '
|
2012-11-02 05:59:27 +00:00
|
|
|
'repo, please run:')
|
|
|
|
print(' rm -r %s/.repo' % self.manifest.topdir)
|
|
|
|
print('and try again.')
|
2012-10-23 07:41:54 +00:00
|
|
|
|
2019-08-27 05:10:59 +00:00
|
|
|
def ValidateOptions(self, opt, args):
|
2012-10-05 12:50:05 +00:00
|
|
|
if opt.reference:
|
2018-01-22 16:57:29 +00:00
|
|
|
opt.reference = os.path.expanduser(opt.reference)
|
2012-10-05 12:50:05 +00:00
|
|
|
|
2013-10-16 09:02:35 +00:00
|
|
|
# Check this here, else manifest will be tagged "not new" and init won't be
|
|
|
|
# possible anymore without removing the .repo/manifests directory.
|
|
|
|
if opt.archive and opt.mirror:
|
2019-08-27 05:10:59 +00:00
|
|
|
self.OptionParser.error('--mirror and --archive cannot be used together.')
|
|
|
|
|
|
|
|
def Execute(self, opt, args):
|
2020-02-11 23:51:08 +00:00
|
|
|
git_require(MIN_GIT_VERSION_HARD, fail=True)
|
|
|
|
if not git_require(MIN_GIT_VERSION_SOFT):
|
|
|
|
print('repo: warning: git-%s+ will soon be required; please upgrade your '
|
|
|
|
'version of git to maintain support.'
|
|
|
|
% ('.'.join(str(x) for x in MIN_GIT_VERSION_SOFT),),
|
|
|
|
file=sys.stderr)
|
2013-10-16 09:02:35 +00:00
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
self._SyncManifest(opt)
|
|
|
|
self._LinkManifest(opt.manifest_name)
|
|
|
|
|
2009-03-19 17:17:12 +00:00
|
|
|
if os.isatty(0) and os.isatty(1) and not self.manifest.IsMirror:
|
2011-04-05 09:31:10 +00:00
|
|
|
if opt.config_name or self._ShouldConfigureUser():
|
|
|
|
self._ConfigureUser()
|
2008-10-21 14:00:00 +00:00
|
|
|
self._ConfigureColor()
|
|
|
|
|
2012-10-23 07:41:54 +00:00
|
|
|
self._DisplayResult()
|