From 6f69c01915aad8bb2d4b242ab7e5b185adf08b7d Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 27 Apr 2016 15:00:47 -0400 Subject: bootstrap: fall back to the default upstream URL Fixes #352. --- lib/spack/spack/cmd/bootstrap.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/spack/spack/cmd/bootstrap.py b/lib/spack/spack/cmd/bootstrap.py index bec11439b5..9fd428e6b1 100644 --- a/lib/spack/spack/cmd/bootstrap.py +++ b/lib/spack/spack/cmd/bootstrap.py @@ -31,6 +31,8 @@ from llnl.util.filesystem import join_path, mkdirp import spack from spack.util.executable import which +_SPACK_UPSTREAM = 'https://github.com/llnl/spack' + description = "Create a new installation of spack in another prefix" def setup_parser(subparser): @@ -40,9 +42,15 @@ def setup_parser(subparser): def get_origin_url(): git_dir = join_path(spack.prefix, '.git') git = which('git', required=True) - origin_url = git( - '--git-dir=%s' % git_dir, 'config', '--get', 'remote.origin.url', - output=str) + try: + origin_url = git( + '--git-dir=%s' % git_dir, + 'config', '--get', 'remote.origin.url', + output=str) + except ProcessError: + origin_url = _SPACK_UPSTREAM + tty.warn('No git repository found; ' + 'using default upstream URL: %s' % origin_url) return origin_url.strip() -- cgit v1.2.3-70-g09d2 From 7ec191ce0b82827013485a98db84cd66aa2ca1b4 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 31 May 2016 10:44:01 -0400 Subject: bootstrap: use the currently checked out branch The `master` branch is not really where Spack development happens, so default to it, but use the user's current branch if it's there. --- lib/spack/spack/cmd/bootstrap.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/spack/spack/cmd/bootstrap.py b/lib/spack/spack/cmd/bootstrap.py index 9fd428e6b1..16808b30b8 100644 --- a/lib/spack/spack/cmd/bootstrap.py +++ b/lib/spack/spack/cmd/bootstrap.py @@ -39,9 +39,14 @@ def setup_parser(subparser): subparser.add_argument('prefix', help="names of prefix where we should install spack") -def get_origin_url(): +def get_origin_info(): git_dir = join_path(spack.prefix, '.git') git = which('git', required=True) + try: + branch = git('symbolic-ref', '--short', 'HEAD', output=str) + except ProcessError: + branch = 'develop' + tty.warn('No branch found; using default branch: %s' % branch) try: origin_url = git( '--git-dir=%s' % git_dir, @@ -51,11 +56,11 @@ def get_origin_url(): origin_url = _SPACK_UPSTREAM tty.warn('No git repository found; ' 'using default upstream URL: %s' % origin_url) - return origin_url.strip() + return (origin_url.strip(), branch.strip()) def bootstrap(parser, args): - origin_url = get_origin_url() + origin_url, branch = get_origin_info() prefix = args.prefix tty.msg("Fetching spack from origin: %s" % origin_url) @@ -81,8 +86,9 @@ def bootstrap(parser, args): git = which('git', required=True) git('init', '--shared', '-q') git('remote', 'add', 'origin', origin_url) - git('fetch', 'origin', 'master:refs/remotes/origin/master', '-n', '-q') - git('reset', '--hard', 'origin/master', '-q') + git('fetch', 'origin', '%s:refs/remotes/origin/%s' % (branch, branch), + '-n', '-q') + git('reset', '--hard', 'origin/%s' % branch, '-q') tty.msg("Successfully created a new spack in %s" % prefix, "Run %s/bin/spack to use this installation." % prefix) -- cgit v1.2.3-70-g09d2 From 89bf5f4045eebdc1f40561dbb70a56e170411c20 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 31 May 2016 10:49:24 -0400 Subject: 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). --- lib/spack/spack/cmd/bootstrap.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/spack/spack/cmd/bootstrap.py b/lib/spack/spack/cmd/bootstrap.py index 16808b30b8..3480c96f39 100644 --- a/lib/spack/spack/cmd/bootstrap.py +++ b/lib/spack/spack/cmd/bootstrap.py @@ -36,10 +36,13 @@ _SPACK_UPSTREAM = 'https://github.com/llnl/spack' description = "Create a new installation of spack in another prefix" 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") -def get_origin_info(): +def get_origin_info(remote): git_dir = join_path(spack.prefix, '.git') git = which('git', required=True) try: @@ -47,10 +50,14 @@ def get_origin_info(): except ProcessError: branch = 'develop' 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: origin_url = git( '--git-dir=%s' % git_dir, - 'config', '--get', 'remote.origin.url', + 'config', '--get', 'remote.%s.url' % remote, output=str) except ProcessError: origin_url = _SPACK_UPSTREAM @@ -60,10 +67,10 @@ def get_origin_info(): def bootstrap(parser, args): - origin_url, branch = get_origin_info() + origin_url, branch = get_origin_info(args.remote) 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): tty.die("There is already a file at %s" % prefix) -- cgit v1.2.3-70-g09d2 From e3e94f0ac96db3c1ddd51555fec5a2bf71b867bf Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 31 May 2016 10:55:14 -0400 Subject: bootstrap: name the current branch the same as the remote --- lib/spack/spack/cmd/bootstrap.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/spack/spack/cmd/bootstrap.py b/lib/spack/spack/cmd/bootstrap.py index 3480c96f39..04892e258d 100644 --- a/lib/spack/spack/cmd/bootstrap.py +++ b/lib/spack/spack/cmd/bootstrap.py @@ -96,6 +96,7 @@ def bootstrap(parser, args): git('fetch', 'origin', '%s:refs/remotes/origin/%s' % (branch, branch), '-n', '-q') git('reset', '--hard', 'origin/%s' % branch, '-q') + git('checkout', '-B', branch, 'origin/%s' % branch, '-q') tty.msg("Successfully created a new spack in %s" % prefix, "Run %s/bin/spack to use this installation." % prefix) -- cgit v1.2.3-70-g09d2 From 5f720f9b7c0e507c2a0335ce9840036ad0b9262f Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 9 Jun 2016 10:51:29 -0400 Subject: flake8: appease the style checker --- lib/spack/spack/cmd/bootstrap.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/spack/spack/cmd/bootstrap.py b/lib/spack/spack/cmd/bootstrap.py index 04892e258d..60e2bd3a11 100644 --- a/lib/spack/spack/cmd/bootstrap.py +++ b/lib/spack/spack/cmd/bootstrap.py @@ -23,7 +23,6 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## import os -from subprocess import check_call import llnl.util.tty as tty from llnl.util.filesystem import join_path, mkdirp @@ -35,11 +34,14 @@ _SPACK_UPSTREAM = 'https://github.com/llnl/spack' description = "Create a new installation of spack in another prefix" + 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(remote): @@ -82,7 +84,8 @@ def bootstrap(parser, args): files_in_the_way = os.listdir(prefix) if files_in_the_way: - tty.die("There are already files there! Delete these files before boostrapping spack.", + tty.die("There are already files there! " + "Delete these files before boostrapping spack.", *files_in_the_way) tty.msg("Installing:", -- cgit v1.2.3-70-g09d2