diff --git a/reframe/utility/os_ext.py b/reframe/utility/os_ext.py index 290d095a7a..d3c57cf972 100644 --- a/reframe/utility/os_ext.py +++ b/reframe/utility/os_ext.py @@ -357,7 +357,7 @@ def git_repo_hash(branch='HEAD', short=True, wd=None): completed = run_command('git rev-parse %s' % branch, check=True, log=False) - except SpawnedProcessError: + except (SpawnedProcessError, FileNotFoundError): return None hash = completed.stdout.strip() diff --git a/unittests/test_utility.py b/unittests/test_utility.py index f8439ff47d..4cc1329334 100644 --- a/unittests/test_utility.py +++ b/unittests/test_utility.py @@ -187,13 +187,17 @@ def test_is_url(): assert not os_ext.is_url(repo_ssh) -def test_git_repo_hash(): +def test_git_repo_hash(monkeypatch): # A git branch hash consists of 8(short) or 40 characters. assert len(os_ext.git_repo_hash()) == 8 assert len(os_ext.git_repo_hash(short=False)) == 40 assert os_ext.git_repo_hash(branch='invalid') is None assert os_ext.git_repo_hash(branch='') is None + # Imitate a system with no git installed by emptying the PATH + monkeypatch.setenv('PATH', '') + assert os_ext.git_repo_hash() is None + def test_git_repo_exists(): assert os_ext.git_repo_exists('https://github.com/eth-cscs/reframe.git',