From 2aad53cf96e106ac12ca2d0baefa61cb1f095968 Mon Sep 17 00:00:00 2001 From: Stefan Tatschner Date: Thu, 19 Dec 2024 13:51:21 +0100 Subject: [PATCH] fix: Use pythonic error handling --- src/gallia/config.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gallia/config.py b/src/gallia/config.py index 4d678c460..cd9246ec8 100644 --- a/src/gallia/config.py +++ b/src/gallia/config.py @@ -3,7 +3,6 @@ # SPDX-License-Identifier: Apache-2.0 import os -import shutil import subprocess import tomllib from pathlib import Path @@ -29,13 +28,14 @@ def get_value(self, key: str, default: Any | None = None) -> Any | None: def get_git_root() -> Path | None: - git_path = shutil.which("git") - if git_path is None: - return None try: p = subprocess.run( - [git_path, "rev-parse", "--show-toplevel"], capture_output=True, check=True + ["git", "rev-parse", "--show-toplevel"], + capture_output=True, + check=True, ) + except FileNotFoundError: + return None except subprocess.CalledProcessError: return None return Path(p.stdout.decode().strip())