From 1d0aed81f7e93b9df5eb148070b4f0124b461e3a Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Thu, 15 Aug 2024 08:14:54 -0700 Subject: [PATCH] Use git to get repo root (#284) --- wpiformat/wpiformat/task.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/wpiformat/wpiformat/task.py b/wpiformat/wpiformat/task.py index ad8008a..2b03b02 100644 --- a/wpiformat/wpiformat/task.py +++ b/wpiformat/wpiformat/task.py @@ -1,7 +1,7 @@ """Task base classes for wpiformat.""" from abc import ABCMeta, abstractmethod -import os +import subprocess class Task(metaclass=ABCMeta): @@ -29,12 +29,12 @@ def get_repo_root(): An empty string is returned if no repository root was found. """ - current_dir = os.path.abspath(os.getcwd()) - while current_dir != os.path.dirname(current_dir): - if os.path.exists(current_dir + os.sep + ".git"): - return current_dir - current_dir = os.path.dirname(current_dir) - return "" + return subprocess.run( + ["git", "rev-parse", "--show-toplevel"], + stdout=subprocess.PIPE, + stderr=subprocess.DEVNULL, + encoding="ascii", + ).stdout.rstrip() @staticmethod def should_process_file(config_file, name):