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):