From 6e8c5b767866ecebe08dc1b673537348394680f3 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 28 Mar 2021 15:39:31 +0200 Subject: [PATCH] Improve git_describe() (#2633) Catch 'fatal: not a git repository' returns and return '' instead (observed in GCP Hub checks). --- utils/torch_utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/torch_utils.py b/utils/torch_utils.py index 0499da49782e..dfab83d5374a 100644 --- a/utils/torch_utils.py +++ b/utils/torch_utils.py @@ -55,7 +55,8 @@ def git_describe(path=Path(__file__).parent): # path must be a directory # return human-readable git description, i.e. v5.0-5-g3e25f1e https://git-scm.com/docs/git-describe s = f'git -C {path} describe --tags --long --always' try: - return subprocess.check_output(s, shell=True).decode()[:-1] + r = subprocess.check_output(s, shell=True).decode()[:-1] + return '' if r.startswith('fatal: not a git repository') else r except subprocess.CalledProcessError as e: return ''