fix annoying 'fatal: Not a git repository' error message (#3657)
fix annoying 'fatal: Not a git repository' error message produced by 'spack list' when Spack is not run from a Git repository (#3657)
This commit is contained in:
parent
f982cd78ae
commit
fb98f9ee19
@ -73,13 +73,16 @@ def setup_parser(subparser):
|
|||||||
help="revision to compare to rev1 (default is HEAD)")
|
help="revision to compare to rev1 (default is HEAD)")
|
||||||
|
|
||||||
|
|
||||||
def get_git():
|
def get_git(fatal=True):
|
||||||
# cd to spack prefix to do git operations
|
# cd to spack prefix to do git operations
|
||||||
os.chdir(spack.prefix)
|
os.chdir(spack.prefix)
|
||||||
|
|
||||||
# If this is a non-git version of spack, give up.
|
# If this is a non-git version of spack, give up.
|
||||||
if not os.path.isdir('.git'):
|
if not os.path.isdir('.git'):
|
||||||
|
if fatal:
|
||||||
tty.die("No git repo in %s. Can't use 'spack pkg'" % spack.prefix)
|
tty.die("No git repo in %s. Can't use 'spack pkg'" % spack.prefix)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
return which("git", required=True)
|
return which("git", required=True)
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
from llnl.util.filesystem import *
|
from llnl.util.filesystem import *
|
||||||
|
|
||||||
import spack
|
import spack
|
||||||
|
from spack.cmd.pkg import get_git
|
||||||
from spack.util.executable import *
|
from spack.util.executable import *
|
||||||
|
|
||||||
|
|
||||||
@ -61,8 +62,8 @@ def git_case_consistency_check(path):
|
|||||||
"""
|
"""
|
||||||
with working_dir(path):
|
with working_dir(path):
|
||||||
# Don't bother fixing case if Spack isn't in a git repository
|
# Don't bother fixing case if Spack isn't in a git repository
|
||||||
git = which('git')
|
git = get_git(fatal=False)
|
||||||
if not git:
|
if git is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user