diff options
| author | Bozhidar Batsov <bozhidar@batsov.dev> | 2026-02-13 14:21:04 +0200 |
|---|---|---|
| committer | Bozhidar Batsov <bozhidar@batsov.dev> | 2026-02-13 14:21:04 +0200 |
| commit | 4dbcda27d6870990421e217c8379b14037d9239f (patch) | |
| tree | c9b767b3d7d5c2f2ea4c7969f77507dd0af17ae7 /projectile.el | |
| parent | 5560f083b69d40eb1a0e359fdd4ba9712f8a1bd8 (diff) | |
Filter deleted-but-unstaged files from git ls-files output (#1897)
When fd is unavailable or disabled, `git ls-files -zco --exclude-standard`
returns files still tracked in the index even if deleted from disk. This
causes projectile-dir-files-alien to list ghost files. Fix by running
`git ls-files -zd` and removing those entries from the result.
Diffstat (limited to 'projectile.el')
| -rw-r--r-- | projectile.el | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/projectile.el b/projectile.el index 0acc7f4..574c5bd 100644 --- a/projectile.el +++ b/projectile.el @@ -1539,10 +1539,21 @@ IGNORED-DIRECTORIES may optionally be provided." (let ((vcs (projectile-project-vcs directory))) (cond ((eq vcs 'git) - (nconc (projectile-files-via-ext-command directory (projectile-get-ext-command vcs)) - (projectile-get-sub-projects-files directory vcs))) + (let* ((files (nconc (projectile-files-via-ext-command directory (projectile-get-ext-command vcs)) + (projectile-get-sub-projects-files directory vcs))) + ;; When using git ls-files (not fd), deleted but unstaged + ;; files are still reported. Remove them. + (deleted (unless (and projectile-git-use-fd projectile-fd-executable) + (projectile-git-deleted-files directory)))) + (if deleted + (seq-remove (lambda (f) (member f deleted)) files) + files))) (t (projectile-files-via-ext-command directory (projectile-get-ext-command vcs)))))) +(defun projectile-git-deleted-files (directory) + "Get a list of deleted but unstaged files in DIRECTORY." + (projectile-files-via-ext-command directory "git ls-files -zd")) + (defun projectile-get-ext-command (vcs) "Determine which external command to invoke based on the project's VCS. Fallback to a generic command when not in a VCS-controlled project." |
