summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Green <greenc@fnal.gov>2019-08-21 11:31:27 -0500
committerTodd Gamblin <tgamblin@llnl.gov>2019-08-21 09:31:27 -0700
commit2441c0bad7d21765142525bd1f80221a0e77c92c (patch)
tree425efa6c3e51a41d56d2a5a7bf11ea34615d0bbf /lib
parent3b115fffb132ee3a247079e8b6043c33707d20c5 (diff)
downloadspack-2441c0bad7d21765142525bd1f80221a0e77c92c.tar.gz
spack-2441c0bad7d21765142525bd1f80221a0e77c92c.tar.bz2
spack-2441c0bad7d21765142525bd1f80221a0e77c92c.tar.xz
spack-2441c0bad7d21765142525bd1f80221a0e77c92c.zip
pkg command uses a working directory for git invocations rather than -C. (#12491)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/cmd/pkg.py28
1 files changed, 23 insertions, 5 deletions
diff --git a/lib/spack/spack/cmd/pkg.py b/lib/spack/spack/cmd/pkg.py
index b81641febc..534e7b9c69 100644
--- a/lib/spack/spack/cmd/pkg.py
+++ b/lib/spack/spack/cmd/pkg.py
@@ -11,6 +11,7 @@ import re
import llnl.util.tty as tty
from llnl.util.tty.colify import colify
+from llnl.util.filesystem import working_dir
import spack.cmd
import spack.paths
@@ -79,12 +80,28 @@ def packages_path():
return spack.repo.path.get_repo('builtin').packages_path
+class GitExe:
+ # Wrapper around Executable for git to set working directory for all
+ # invocations.
+ #
+ # Not using -C as that is not supported for git < 1.8.5.
+ def __init__(self):
+ self._git_cmd = which('git', required=True)
+
+ def __call__(self, *args, **kwargs):
+ with working_dir(packages_path()):
+ return self._git_cmd(*args, **kwargs)
+
+
+_git = None
+
+
def get_git():
"""Get a git executable that runs *within* the packages path."""
- git = which('git', required=True)
- git.add_default_arg('-C')
- git.add_default_arg(packages_path())
- return git
+ global _git
+ if _git is None:
+ _git = GitExe()
+ return _git
def list_packages(rev):
@@ -102,13 +119,14 @@ def list_packages(rev):
def pkg_add(args):
"""add a package to the git stage with `git add`"""
+ git = get_git()
+
for pkg_name in args.packages:
filename = spack.repo.path.filename_for_package_name(pkg_name)
if not os.path.isfile(filename):
tty.die("No such package: %s. Path does not exist:" %
pkg_name, filename)
- git = get_git()
git('add', filename)