[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 5f4e944 057/399: counsel.el: Fix finding dominating file

From: Oleh Krehel
Subject: [elpa] master 5f4e944 057/399: counsel.el: Fix finding dominating file
Date: Sat, 20 Jul 2019 14:56:48 -0400 (EDT)

branch: master
commit 5f4e9444eeb254f1511e071cca819d1ad52c103a
Author: Basil L. Contovounesios <address@hidden>
Commit: Basil L. Contovounesios <address@hidden>

    counsel.el: Fix finding dominating file
    (counsel--dominating-file): Rename from...
    (counsel--find-project-root): ...this; change all callers.
    Fix error when locate-dominating-file returns nil.
    (counsel-git): Remove redundant file name expansion.
 counsel.el | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/counsel.el b/counsel.el
index 36c2f54..cd98456 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1172,18 +1172,16 @@ selected face."
  '(("j" find-file-other-window "other window")
    ("x" counsel-find-file-extern "open externally")))
-;; Common helper for counsel
-(defun counsel--find-project-root (domfile &optional startdir)
-  "Traverse up from `default-directory' or STARTDIR until we find DOMFILE.
-Return a fully expanded path."
-  (expand-file-name
-   (locate-dominating-file
-    (or startdir default-directory)
-    domfile)))
+(defun counsel--dominating-file (file &optional dir)
+  "Look up directory hierarchy for FILE, starting in DIR.
+Like `locate-dominating-file', but DIR defaults to
+`default-directory' and the return value is expanded."
+  (and (setq dir (locate-dominating-file (or dir default-directory) file))
+       (expand-file-name dir)))
 (defun counsel-locate-git-root ()
   "Locate the root of the git repository containing the current buffer."
-  (or (counsel--find-project-root ".git")
+  (or (counsel--dominating-file ".git")
       (error "Not in a git repository")))
@@ -1192,7 +1190,7 @@ Return a fully expanded path."
 INITIAL-INPUT can be given as the initial minibuffer input."
   (counsel-require-program counsel-git-cmd)
-  (let* ((default-directory (expand-file-name (counsel-locate-git-root)))
+  (let* ((default-directory (counsel-locate-git-root))
          (cands (split-string
                  (shell-command-to-string counsel-git-cmd)
@@ -5128,8 +5126,8 @@ to variable to `savehist-additional-variables'.")
   "Locate the root of the project by trying a series of things."
   (or (when (fboundp 'project-current)
         (cdr (project-current)))
-      (counsel--find-project-root ".dir-locals.el")
-      (counsel--find-project-root ".git")
+      (counsel--dominating-file ".dir-locals.el")
+      (counsel--dominating-file ".git")
       (error "Couldn't find project root")))
 (defvar counsel-compile-local-builds

reply via email to

[Prev in Thread] Current Thread [Next in Thread]