diff --git a/magit.el b/magit.el index ff33f7c0..f47356e5 100644 --- a/magit.el +++ b/magit.el @@ -401,13 +401,11 @@ Many Magit faces inherit from this one by default." (defun magit-get-top-dir (cwd) (let ((cwd (expand-file-name cwd))) - (and (file-directory-p cwd) - (let* ((default-directory cwd) - (magit-dir - (magit-git-string "rev-parse" "--git-dir"))) - (and magit-dir - (file-name-as-directory - (or (file-name-directory magit-dir) cwd))))))) + (when (file-directory-p cwd) + (let* ((default-directory cwd) + (cdup (magit-git-string "rev-parse" "--show-cdup"))) + (when cdup + (file-name-as-directory (expand-file-name cdup cwd))))))) (defun magit-get-ref (ref) (magit-git-string "symbolic-ref" "-q" ref))