bootstrap: allow using alternate remotes

If you want to bootstrap from a fork, the `--remote` option may be used
to select it.

Also limit the branches to 'develop' and 'master' if the remote is
'origin' since those are the actual integration branches used (other
branches on 'origin' are just PR branches).
This commit is contained in:
Ben Boeckel 2016-05-31 10:49:24 -04:00
parent 7ec191ce0b
commit 89bf5f4045

View File

@ -36,10 +36,13 @@
description = "Create a new installation of spack in another prefix" description = "Create a new installation of spack in another prefix"
def setup_parser(subparser): def setup_parser(subparser):
subparser.add_argument(
'-r', '--remote', action='store', dest='remote',
help="name of the remote to bootstrap from", default='origin')
subparser.add_argument('prefix', help="names of prefix where we should install spack") subparser.add_argument('prefix', help="names of prefix where we should install spack")
def get_origin_info(): def get_origin_info(remote):
git_dir = join_path(spack.prefix, '.git') git_dir = join_path(spack.prefix, '.git')
git = which('git', required=True) git = which('git', required=True)
try: try:
@ -47,10 +50,14 @@ def get_origin_info():
except ProcessError: except ProcessError:
branch = 'develop' branch = 'develop'
tty.warn('No branch found; using default branch: %s' % branch) tty.warn('No branch found; using default branch: %s' % branch)
if remote == 'origin' and \
branch not in ('master', 'develop'):
branch = 'develop'
tty.warn('Unknown branch found; using default branch: %s' % branch)
try: try:
origin_url = git( origin_url = git(
'--git-dir=%s' % git_dir, '--git-dir=%s' % git_dir,
'config', '--get', 'remote.origin.url', 'config', '--get', 'remote.%s.url' % remote,
output=str) output=str)
except ProcessError: except ProcessError:
origin_url = _SPACK_UPSTREAM origin_url = _SPACK_UPSTREAM
@ -60,10 +67,10 @@ def get_origin_info():
def bootstrap(parser, args): def bootstrap(parser, args):
origin_url, branch = get_origin_info() origin_url, branch = get_origin_info(args.remote)
prefix = args.prefix prefix = args.prefix
tty.msg("Fetching spack from origin: %s" % origin_url) tty.msg("Fetching spack from '%s': %s" % (args.remote, origin_url))
if os.path.isfile(prefix): if os.path.isfile(prefix):
tty.die("There is already a file at %s" % prefix) tty.die("There is already a file at %s" % prefix)