Skip to content

Commit

Permalink
Explicitly handle case that we aren’t in a git repo
Browse files Browse the repository at this point in the history
Let’s be slightly more conservative. This avoids shelling out to git when we know it’s not a repo.

Avoids too much dependency on git behavior that may change between versions.

Signed-off-by: Stefan Marr <git@stefan-marr.de>
  • Loading branch information
smarr committed Oct 1, 2020
1 parent 748d6f7 commit bdd42ac
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions rebench/environment.py
Expand Up @@ -23,8 +23,8 @@ def _encode_str(out):

def _exec(cmd):
try:
with open(os.devnull, 'w') as fnull:
out = subprocess.check_output(cmd, stderr=fnull)
with open(os.devnull, 'w') as dev_null_f:
out = subprocess.check_output(cmd, stderr=dev_null_f)
except subprocess.CalledProcessError:
return None
return _encode_str(out)
Expand All @@ -39,7 +39,21 @@ def determine_source_details():
return _source

result = dict()
repo_url = _exec(['git', 'ls-remote', '--get-url'])

is_git_repo = _exec(['git', 'rev-parse']) is not None
if not is_git_repo:
result['repoURL'] = None
result['branchOrTag'] = None
result['commitId'] = None
result['commitMsg'] = None
result['authorName'] = None
result['committerName'] = None
result['authorEmail'] = None
result['committerEmail'] = None
_source = result
return result

repo_url = _exec(['git', 'ls-remote', '--get-url']) if is_git_repo else None
if repo_url is None:
repo_url = ''

Expand All @@ -59,7 +73,6 @@ def determine_source_details():
result['committerEmail'] = _exec(['git', 'show', '-s', '--format=%cE', 'HEAD'])

_source = result

return result


Expand Down

0 comments on commit bdd42ac

Please sign in to comment.