branch: elpa/projectile
commit ac37c2c96b1296b147aed021273efdd20e3b4938
Author: Bozhidar Batsov <[email protected]>
Commit: Bozhidar Batsov <[email protected]>
Strip "./" prefix from fd output in projectile-files-via-ext-command
Newer fd versions (8.3.0+) prepend "./" to output. The --strip-cwd-prefix
flag was already added to projectile-generic-command and
projectile-git-fd-args,
but this flag doesn't exist in older fd versions, causing errors.
Add post-processing in projectile-files-via-ext-command to strip the "./"
prefix from results as a defensive fallback, matching the existing pattern
in projectile-files-from-cmd.
Fixes #1749
---
CHANGELOG.md | 1 +
projectile.el | 6 +++++-
test/projectile-test.el | 6 +++++-
3 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9f0ac7a25d..2af852cd38 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@
### Bugs fixed
* [#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).
+* [#1749](https://github.com/bbatsov/projectile/issues/1749): Strip `./`
prefix from `fd` output in `projectile-files-via-ext-command`, fixing
compatibility with older `fd` versions that don't support `--strip-cwd-prefix`.
### Changes
diff --git a/projectile.el b/projectile.el
index 7f0c581881..90e2d48dfe 100644
--- a/projectile.el
+++ b/projectile.el
@@ -1661,7 +1661,11 @@ Only text sent to standard output is taken into account."
(with-temp-buffer
(shell-command command t "*projectile-files-errors*")
(let ((shell-output (buffer-substring (point-min) (point-max))))
- (split-string (string-trim shell-output) "\0" t))))))
+ (mapcar (lambda (f)
+ (if (string-prefix-p "./" f)
+ (substring f 2)
+ f))
+ (split-string (string-trim shell-output) "\0" t)))))))
(defun projectile-adjust-files (project vcs files)
"First remove ignored files from FILES, then add back unignored files."
diff --git a/test/projectile-test.el b/test/projectile-test.el
index 33c50e4b2c..0880d6d40d 100644
--- a/test/projectile-test.el
+++ b/test/projectile-test.el
@@ -546,7 +546,11 @@ Just delegates OPERATION and ARGS for all operations
except for`shell-command`'.
(expect (projectile-files-via-ext-command "" "echo filename")
:to-equal '("filename")))
(it "supports magic file handlers"
- (expect (projectile-files-via-ext-command "#magic#" "echo
filename") :to-equal '("magic"))))
+ (expect (projectile-files-via-ext-command "#magic#" "echo
filename") :to-equal '("magic")))
+
+ (it "strips ./ prefix from results"
+ (expect (projectile-files-via-ext-command "" "printf
'./foo\\0./bar/baz\\0quux'")
+ :to-equal '("foo" "bar/baz" "quux"))))
(describe "projectile-mode"
(before-each