@@ -692,27 +692,26 @@ def git_repo_exists(url, timeout=5):
692692 return True
693693
694694
695- def git_repo_hash (commit = 'HEAD' , short = True , wd = None ):
695+ def git_repo_hash (commit = 'HEAD' , short = True , wd = '.' ):
696696 '''Return the SHA1 hash of a Git commit.
697697
698698 :arg commit: The commit to look at.
699699 :arg short: Return a short hash. This always corresponds to the first 8
700700 characters of the long hash. We don't rely on Git for the short hash,
701701 since depending on the version it might return either 7 or 8
702702 characters.
703- :arg wd: Change to this directory before retrieving the hash. If ``None``,
704- ReFrame's install prefix will be used.
703+ :arg wd: Change to this directory before retrieving the hash.
705704 :returns: The Git commit hash or ``None`` if the hash could not be
706705 retrieved.
706+
707+ .. versionchanged:: 4.6.1
708+ Default working directory is now ``.``.
707709 '''
708710 try :
709- wd = wd or reframe .INSTALL_PREFIX
710- with change_dir (wd ):
711- # Do not log this command, since we need to call this function
712- # from the logger
713- completed = run_command (f'git rev-parse { commit } ' ,
714- check = True , log = False )
715-
711+ # Do not log this command, since we need to call this function
712+ # from the logger
713+ completed = run_command (f'git -C { wd } rev-parse { commit } ' ,
714+ check = True , log = False )
716715 except (SpawnedProcessError , FileNotFoundError ):
717716 return None
718717
@@ -730,13 +729,14 @@ def reframe_version():
730729 If ReFrame's installation contains the repository metadata and the current
731730 version is a pre-release version, the repository's hash will be appended
732731 to the actual version.
733-
734732 '''
735- repo_hash = git_repo_hash ()
736- if repo_hash and semver .VersionInfo .parse (reframe .VERSION ).prerelease :
737- return f'{ reframe .VERSION } +{ repo_hash } '
738- else :
739- return reframe .VERSION
733+ if (semver .VersionInfo .parse (reframe .VERSION ).prerelease and
734+ os .path .exists (os .path .join (reframe .INSTALL_PREFIX , '.git' ))):
735+ repo_hash = git_repo_hash (wd = reframe .INSTALL_PREFIX )
736+ if repo_hash :
737+ return f'{ reframe .VERSION } +{ repo_hash } '
738+
739+ return reframe .VERSION
740740
741741
742742def expandvars (s ):
0 commit comments