Skip to content

Commit

Permalink
Catch GitCommandError instead
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-z committed Jun 30, 2024
1 parent ae6fa51 commit 410a21a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import boto3
import typer
from git import Repo
from git import GitCommandError, Repo

from watcloud_uri import WATcloudURI

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 410a21a

Please sign in to comment.