]> code.delx.au - gnu-emacs-elpa/commitdiff
counsel.el (counsel-git-grep): Warn if not in a repository
authorOleh Krehel <ohwoeowho@gmail.com>
Sat, 16 May 2015 12:39:10 +0000 (14:39 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Sat, 16 May 2015 12:39:10 +0000 (14:39 +0200)
counsel.el

index 23c9f0a6f12225c6f635c7789bc96ebdb5717c31..ea5496e8218b4f0a1903badcb49a3304a8bf2b2b 100644 (file)
   (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)