From 44311671f84d26baf5465aa2b414894f268c1574 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Thu, 15 Aug 2024 07:44:22 -0700 Subject: [PATCH] [upstream_utils] Use git to get repo root (#6967) --- upstream_utils/upstream_utils.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/upstream_utils/upstream_utils.py b/upstream_utils/upstream_utils.py index f715d66277..3872ee9960 100644 --- a/upstream_utils/upstream_utils.py +++ b/upstream_utils/upstream_utils.py @@ -65,12 +65,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() def walk_if(top, pred):