Skip to content

counsel-git-grep fails if there are unreadable directories #1502

@icarus-sparry

Description

@icarus-sparry

If du outputs an error message, e.g. du: cannot read directory './doc': Permission denied then counsel-git-grep fails with Wrong type argument: number-or-marker-p, du:

Reproduction steps.

git clone https://github.com/abo-abo/swiper/
cd swiper
chmod 111 doc
make plain

and then invoke counsel-git-grep (C-c j) and observe the error.

Possible fix:

diff --git a/counsel.el b/counsel.el
index b601b90..5b4e992 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1232,7 +1232,7 @@ files in a project.")
   "Default defun to calculate `counsel--git-grep-count'."
   (if (eq system-type 'windows-nt)
       0
-    (read (shell-command-to-string "du -s"))))
+    (read (shell-command-to-string "du -s 2>/dev/null"))))
 
 (defvar counsel--git-grep-count-func #'counsel--git-grep-count-func-default
   "Defun to calculate `counsel--git-grep-count' for `counsel-git-grep'.")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions