branch: elpa/projectile
commit 7a3708f146fdc4c483b276fa1bc749278cfdb82b
Author: Bozhidar Batsov <[email protected]>
Commit: Bozhidar Batsov <[email protected]>

    Don't cache nonexistent files & fix grep/git-grep with special chars 
(#1551, #1554)
    
    Two unrelated small fixes:
    
    1. projectile-cache-current-file now checks file-exists-p before adding
       a file to the cache.  This prevents ghost entries when visiting a new
       file with find-file and abandoning the buffer without saving.
    
    2. Add -F (fixed-string) flag to the grep and git-grep commands used by
       projectile-files-with-string, matching what rg, ag, and ack already
       do.  This fixes errors when the search string contains regex special
       characters like [ ] and @.
---
 CHANGELOG.md  | 2 ++
 projectile.el | 9 ++++++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4f0b0a09d7..7e196f25c6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,8 @@
 
 * [#1748](https://github.com/bbatsov/projectile/issues/1748): Fix 
`projectile-replace` falling back to the legacy Emacs 25/26 code path on Emacs 
27+ because `fileloop` was not loaded.
 * [#1741](https://github.com/bbatsov/projectile/issues/1741): Fix 
`projectile-replace` treating the search string as a regexp instead of a 
literal string on Emacs 27+.
+* [#1551](https://github.com/bbatsov/projectile/issues/1551): Don't add 
nonexistent files to the project cache (e.g. when visiting a new file with 
`find-file` and then abandoning the buffer).
+* [#1554](https://github.com/bbatsov/projectile/issues/1554): Fix 
`projectile-files-with-string` failing on special characters when using `grep` 
or `git-grep` by adding the `-F` (fixed-string) flag.
 * [#1897](https://github.com/bbatsov/projectile/issues/1897): Filter 
deleted-but-unstaged files from `git ls-files` output in alien/hybrid indexing 
(when `fd` is not used).
 * [#1873](https://github.com/bbatsov/projectile/issues/1873): Skip unreadable 
directories during native indexing instead of aborting with a permission error.
 * [#1961](https://github.com/bbatsov/projectile/issues/1961): Prevent 
directories from matching file-type project root markers (e.g., a `workspace` 
directory no longer matches the `WORKSPACE` Bazel marker on case-insensitive 
filesystems).
diff --git a/projectile.el b/projectile.el
index ed78865b86..6a342daa4f 100644
--- a/projectile.el
+++ b/projectile.el
@@ -1187,7 +1187,9 @@ The cache is created both in memory and on the hard 
drive."
   "Add the currently visited file to the cache."
   (interactive)
   (let ((current-project (projectile-project-root)))
-    (when (and (buffer-file-name) (gethash (projectile-project-root) 
projectile-projects-cache))
+    (when (and (buffer-file-name)
+               (file-exists-p (buffer-file-name))
+               (gethash (projectile-project-root) projectile-projects-cache))
       (let* ((abs-current-file (file-truename (buffer-file-name)))
              (current-file (file-relative-name abs-current-file 
current-project)))
         (unless (or (projectile-file-cached-p current-file current-project)
@@ -4842,12 +4844,13 @@ Returns a list of expanded filenames."
   '((rg . "rg -lF --no-heading --color never ")
     (ag . "ag --literal --nocolor --noheading -l ")
     (ack . "ack --literal --nocolor -l ")
-    (git . "git grep -HlI ")
+    (git . "git grep -HlIF ")
     ;; -r: recursive
     ;; -H: show filename for each match
     ;; -l: show only file names with matches
     ;; -I: no binary files
-    (grep . "grep -rHlI %s .")))
+    ;; -F: interpret pattern as fixed string, not regexp
+    (grep . "grep -rHlIF %s .")))
 
 (defun projectile--rg-construct-command (search-term &optional file-ext)
   "Construct Rg option to search files by the extension FILE-EXT."

Reply via email to