Compare commits

...

8 Commits

Author SHA1 Message Date
Gregory Becker
26e38d9b26 flake 2021-02-19 01:21:54 -08:00
Gregory Becker
f279ce2e7f update completion 2021-02-19 01:14:58 -08:00
Gregory Becker
3ac497dfec add capability to pull subcomponents 2021-02-19 01:10:40 -08:00
Gregory Becker
9810572411 run git from proper directory 2021-02-19 00:48:35 -08:00
Gregory Becker
d4895435f1 update bash completions 2021-02-19 00:37:22 -08:00
Gregory Becker
ae7ca04997 flake 2021-02-19 00:36:28 -08:00
Gregory Becker
29562596c3 fixup imports 2021-02-19 00:36:28 -08:00
Gregory Becker
892dd4d97f add spack checkout command 2021-02-19 00:36:28 -08:00
2 changed files with 118 additions and 1 deletions

View File

@@ -0,0 +1,108 @@
# Copyright 2013-2021 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import llnl.util.filesystem as fs
import llnl.util.tty as tty
import spack.environment as ev
import spack.paths
import spack.repo
from spack.util.executable import which
_SPACK_UPSTREAM = 'https://github.com/spack/spack'
description = "update the spack prefix or subcomponent to a git ref"
section = "admin"
level = "long"
git = None
def setup_parser(subparser):
subparser.add_argument(
'-r', '--remote', action='store', default='origin',
help="name of the git remote from which to fetch")
subparser.add_argument(
'--url', action='store', default=None,
help="url to use if the remote does not already exist")
subrepo_subparser = subparser.add_mutually_exclusive_group()
subrepo_subparser.add_argument(
'--env', action='store', default=None,
help="checkout an environment instead of the Spack source")
subrepo_subparser.add_argument(
'--repo', action='store', default=None,
help="checkout a Spack repo instead of the Spack source")
subparser.add_argument(
'ref', help="git reference to checkout")
def fetch_remote(remote, url):
# Ensure we have the appropriate remote configured
remotes = git('remote', output=str, errror=str).split('\n')
if remote in remotes:
remote_url = git('remote', 'get-url', remote, output=str, error=str)
remote_url = remote_url.strip('\n')
if url and remote_url != url:
msg = "Git url %s does not match given url %s" % (remote_url, url)
msg += " for remote '%s'. Either use the git url or" % remote
msg += " specify a new remote name for the new url."
tty.die(msg)
elif not url:
msg = "Spack requires url to checkout from unknown remote %s" % remote
tty.die(msg)
else:
git('remote', 'add', remote, url)
git('fetch', remote)
def known_commit_or_tag(ref):
# No need to fetch for tags and commits if we have the ref already
# Fetch on other types rather than failing here because a tree ref could
# be ambiguous with a commit ref after fetching
ref_type = git('cat-file', '-t', ref,
output=str, error=str, fail_on_error=False).strip('\n ')
return ref_type in ('commit', 'tag')
def checkout(parser, args):
remote = args.remote or 'origin'
url = args.url
ref = args.ref
global git # make git available to called methods
git = which('git', required=True)
work_dir = spack.paths.prefix
# Set the appropriate workdir if we are modifying an environment or repo
# instead of Spack itself
if args.env:
if ev.exists(args.env):
work_dir = ev.read(args.env).path
elif ev.is_env_dir(args.env):
work_dir = ev.Environment(args.env)
else:
raise ValueError("'%s' is not a valid Spack environment." %
args.env)
elif args.repo:
if args.repo in spack.repo.path.by_namespace:
work_dir = spack.repo.path.by_namespace[args.repo]
else:
raise ValueError("'%s' is not a valid Spack repo namespace." %
args.repo)
with fs.working_dir(work_dir):
# Always fetch branches
# branches includes emptry string; since ref cannot be empty string,
# this does not cause a bug and fixing it reduces code legibility
branches = map(lambda b: b.strip('* '),
git('branch', output=str, error=str).split('\n'))
if ref in branches or not known_commit_or_tag(ref):
fetch_remote(remote, url)
# For branches, ensure we're getting the version from the correct remote
full_ref = '%s/%s' % (remote, ref) if ref in branches else ref
git('checkout', full_ref)

View File

@@ -333,7 +333,7 @@ _spack() {
then then
SPACK_COMPREPLY="-h --help -H --all-help --color -C --config-scope -d --debug --timestamp --pdb -e --env -D --env-dir -E --no-env --use-env-repo -k --insecure -l --enable-locks -L --disable-locks -m --mock -p --profile --sorted-profile --lines -v --verbose --stacktrace -V --version --print-shell-vars" SPACK_COMPREPLY="-h --help -H --all-help --color -C --config-scope -d --debug --timestamp --pdb -e --env -D --env-dir -E --no-env --use-env-repo -k --insecure -l --enable-locks -L --disable-locks -m --mock -p --profile --sorted-profile --lines -v --verbose --stacktrace -V --version --print-shell-vars"
else else
SPACK_COMPREPLY="activate add arch blame build-env buildcache cd checksum ci clean clone commands compiler compilers concretize config containerize create deactivate debug dependencies dependents deprecate dev-build develop docs edit env extensions external fetch find flake8 gc gpg graph help info install license list load location log-parse maintainers mark mirror module patch pkg providers pydoc python reindex remove rm repo resource restage solve spec stage style test test-env tutorial undevelop uninstall unit-test unload url verify versions view" SPACK_COMPREPLY="activate add arch blame build-env buildcache cd checkout checksum ci clean clone commands compiler compilers concretize config containerize create deactivate debug dependencies dependents deprecate dev-build develop docs edit env extensions external fetch find flake8 gc gpg graph help info install license list load location log-parse maintainers mark mirror module patch pkg providers pydoc python reindex remove rm repo resource restage solve spec stage style test test-env tutorial undevelop uninstall unit-test unload url verify versions view"
fi fi
} }
@@ -459,6 +459,15 @@ _spack_cd() {
fi fi
} }
_spack_checkout() {
if $list_options
then
SPACK_COMPREPLY="-h --help -r --remote --url --env --repo"
else
SPACK_COMPREPLY=""
fi
}
_spack_checksum() { _spack_checksum() {
if $list_options if $list_options
then then