From 45f9b8b6f69db9c4464507e0c1ba013d3eba8038 Mon Sep 17 00:00:00 2001 From: Eric Engestrom Date: Tue, 5 Apr 2022 12:02:06 +0200 Subject: [PATCH] ask git what its root is, instead of trying to figure it out ourselves --- dunk/dunk.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/dunk/dunk.py b/dunk/dunk.py index 92a857b..0d7974e 100644 --- a/dunk/dunk.py +++ b/dunk/dunk.py @@ -1,5 +1,6 @@ import functools import os +import subprocess import sys from collections import defaultdict from difflib import SequenceMatcher @@ -32,15 +33,10 @@ # TODO: Use rich pager here? def find_git_root() -> Path: - cwd = Path.cwd() - if (cwd / ".git").exists(): - return Path.cwd() - - for directory in cwd.parents: - if (directory / ".git").exists(): - return directory - - return cwd + return Path(subprocess.check_output( + ['git', 'rev-parse', '--show-toplevel'], + stderr=subprocess.DEVNULL, + ).decode().strip()) class ContiguousStreak(NamedTuple):