[upstream_utils] Use git to get repo root (#6967)

This commit is contained in:
Tyler Veness
2024-08-15 07:44:22 -07:00
committed by GitHub
parent d3421a7c89
commit 44311671f8

View File

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