Improve git_describe() (#2633)
Browse filesCatch 'fatal: not a git repository' returns and return '' instead (observed in GCP Hub checks).
- 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 |
-
|
|
|
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 |
|