branch: master
commit 10f995468b6d97ea4034109a15e623aebfcf412b
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
counsel.el (counsel-git-grep): Warn if not in a repository
---
counsel.el | 20 +++++++++++---------
1 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/counsel.el b/counsel.el
index 23c9f0a..ea5496e 100644
--- a/counsel.el
+++ b/counsel.el
@@ -237,15 +237,17 @@
(interactive)
(setq counsel--git-grep-dir
(locate-dominating-file default-directory ".git"))
- (setq counsel--git-grep-count (counsel-git-grep-count ""))
- (ivy-read "pattern: " 'counsel-git-grep-function
- :initial-input initial-input
- :matcher #'counsel-git-grep-matcher
- :dynamic-collection (when (> counsel--git-grep-count 20000)
- 'counsel-git-grep-function)
- :keymap counsel-git-grep-map
- :action #'counsel-git-grep-action
- :unwind #'swiper--cleanup))
+ (if (null counsel--git-grep-dir)
+ (error "Not in a git repository")
+ (setq counsel--git-grep-count (counsel-git-grep-count ""))
+ (ivy-read "pattern: " 'counsel-git-grep-function
+ :initial-input initial-input
+ :matcher #'counsel-git-grep-matcher
+ :dynamic-collection (when (> counsel--git-grep-count 20000)
+ 'counsel-git-grep-function)
+ :keymap counsel-git-grep-map
+ :action #'counsel-git-grep-action
+ :unwind #'swiper--cleanup)))
(defun counsel-git-grep-matcher (x)
(when (string-match "^[^:]+:[^:]+:" x)