From ae6fa51d3ed53873dfb2d2c186d337111bc6e6d4 Mon Sep 17 00:00:00 2001 From: Ben Zhang Date: Sun, 30 Jun 2024 01:31:38 +0000 Subject: [PATCH] Handle FileNotFoundError in git grep --- src/utils.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/utils.py b/src/utils.py index edc92b4..cf491a5 100644 --- a/src/utils.py +++ b/src/utils.py @@ -88,10 +88,14 @@ def get_raw_watcloud_uris(repo_path: Path): # -h suppresses filename output # --only-matching returns only the matched text - out = repo.git.execute( - ["git", "grep", "--only-matching", "-h", "watcloud://[^\"' ]*"] - + [r.name for r in repo.remote().refs] - ) + try: + out = repo.git.execute( + ["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 uris = set(u.strip() for u in out.splitlines() if u.strip()) return uris