From 6a1bb4f644cb0ac19ecfc9e01bf30966c5b4651d Mon Sep 17 00:00:00 2001 From: Hannu Koivisto Date: Wed, 14 Oct 2009 21:28:07 +0300 Subject: [PATCH] Fix magit-get-top-dir from ruining paths with symlinks. One might argue that this also makes it work better in a case when GIT_DIR points outside of a work tree, but because in that case any directory is a valid "top dir" from GIT's point of view, that is debatable. But at least one can use Magit in that case by first making sure that default-directory is the top dir and then executing magit-status. --- magit.el | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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))