branch: master
commit beee0b7bd1c935f2eb369709031d7bc274a6a926
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
counsel.el (counsel-git): Add better error message
When not in a git directory.
Fixes #537
---
counsel.el | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/counsel.el b/counsel.el
index 94cc98e..73ffa21 100644
--- a/counsel.el
+++ b/counsel.el
@@ -748,18 +748,21 @@ Describe the selected candidate."
(defun counsel-git ()
"Find file in the current Git repository."
(interactive)
- (setq counsel--git-dir (expand-file-name
- (locate-dominating-file
- default-directory ".git")))
- (let* ((default-directory counsel--git-dir)
- (cands (split-string
- (shell-command-to-string
- "git ls-files --full-name --")
- "\n"
- t)))
- (ivy-read (funcall counsel-prompt-function "Find file")
- cands
- :action #'counsel-git-action)))
+ (setq counsel--git-dir (locate-dominating-file
+ default-directory ".git"))
+ (if (null counsel--git-dir)
+ (error "Not in a git repository")
+ (setq counsel--git-dir (expand-file-name
+ counsel--git-dir))
+ (let* ((default-directory counsel--git-dir)
+ (cands (split-string
+ (shell-command-to-string
+ "git ls-files --full-name --")
+ "\n"
+ t)))
+ (ivy-read (funcall counsel-prompt-function "Find file")
+ cands
+ :action #'counsel-git-action))))
(defun counsel-git-action (x)
(with-ivy-window