glenn-jocher commited on
Commit
6e8c5b7
·
unverified ·
1 Parent(s): 9b92d3e

Improve git_describe() (#2633)

Browse files

Catch 'fatal: not a git repository' returns and return '' instead (observed in GCP Hub checks).

Files changed (1) hide show
  1. utils/torch_utils.py +2 -1
utils/torch_utils.py CHANGED
@@ -55,7 +55,8 @@ def git_describe(path=Path(__file__).parent): # path must be a directory
55
  # return human-readable git description, i.e. v5.0-5-g3e25f1e https://git-scm.com/docs/git-describe
56
  s = f'git -C {path} describe --tags --long --always'
57
  try:
58
- return subprocess.check_output(s, shell=True).decode()[:-1]
 
59
  except subprocess.CalledProcessError as e:
60
  return ''
61
 
 
55
  # return human-readable git description, i.e. v5.0-5-g3e25f1e https://git-scm.com/docs/git-describe
56
  s = f'git -C {path} describe --tags --long --always'
57
  try:
58
+ r = subprocess.check_output(s, shell=True).decode()[:-1]
59
+ return '' if r.startswith('fatal: not a git repository') else r
60
  except subprocess.CalledProcessError as e:
61
  return ''
62