From 410a21a80ad3bc1900db66dfbf77b928b373f93e Mon Sep 17 00:00:00 2001 From: Ben Zhang Date: Sun, 30 Jun 2024 01:42:56 +0000 Subject: [PATCH] Catch GitCommandError instead --- src/utils.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/utils.py b/src/utils.py index cf491a5..0cee020 100644 --- a/src/utils.py +++ b/src/utils.py @@ -8,7 +8,7 @@ import boto3 import typer -from git import Repo +from git import GitCommandError, Repo from watcloud_uri import WATcloudURI @@ -93,9 +93,14 @@ def get_raw_watcloud_uris(repo_path: Path): ["git", "grep", "--only-matching", "-h", "watcloud://[^\"' ]*"] + [r.name for r in repo.remote().refs] ) - except FileNotFoundError: - # when `git grep` can't find any matches, it throws a FileNotFoundError - pass + except GitCommandError as e: + # when `git grep` doesn't find any matches, it throws a GitCommandError with status 1 + if e.status == 1: + logging.debug(f"{repo.working_dir} does not contain any WATcloud URIs") + out = "" + else: + raise + uris = set(u.strip() for u in out.splitlines() if u.strip()) return uris