Projectile: Deleted files are still shown in projectile-find-file

Created on 1 Jul 2017  路  17Comments  路  Source: bbatsov/projectile

Expected behavior

Suppose that I have a Git repository with some files committed to it. When I delete one of those files in my working directory, it should no longer show up in projectile-find-file.

Actual behavior

All files in Git's index are shown in projectile-find-file. When I have renamed a file, this causes both the old path and the new path to show up in projectile-find-file. If the old path is listed earlier than the new path, this causes me to inadvertently re-create a file at the old path.

Steps to reproduce the problem

$ mkdir example-git-repo
$ cd example-git-repo
$ git init
$ touch existing-file nonexistent-file
$ git add existing-file nonexistent-file
$ git commit -m "Add two files"
$ rm nonexistent-file
$ emacs -Q
M-x projectile-find-file

Observe that both existing-file and nonexistent-file are listed, whereas only existing-file should be listed.

$ git add nonexistent-file
$ emacs -Q
M-x projectile-find-file

Observe that nonexistent-file is no longer listed if its deletion is added to the index.

Cause

This is because Projectile uses git ls-files in projectile-git-command, and git ls-files shows files in the index, not files in the working directory.

Environment & Version information

Projectile version information

Revision 56e262dd3b5998d0dc6a590d06bc11058839c588, version 0.15.0snapshot.

Emacs version

GNU Emacs 25.2.1 from brew cask install emacs.

Operating system

                -/+:.           
               :++++.           
              /+++/.            OS: macOS Sierra 10.12.5 16F73 x86_64
      .:-::- .+/:-``.::-        Model: MacBookPro11,4
   .:/++++++/::::/++++++/:`     Kernel: 16.6.0
 .:///////////////////////:`    Uptime: 2 days, 8 hours, 4 mins
 ////////////////////////`      Packages: 203
-+++++++++++++++++++++++`       Shell: zsh 5.3.1
/++++++++++++++++++++++/        Resolution: 1440x900
/sssssssssssssssssssssss.       DE: Aqua
:ssssssssssssssssssssssss-      WM: Quartz Compositor
 osssssssssssssssssssssssso/`   Terminal: iTerm2
 `syyyyyyyyyyyyyyyyyyyyyyyy+`   Terminal Font: InputMono-Medium 12
  `ossssssssssssssssssssss/     CPU: Intel i7-4980HQ (8) @ 2.80GHz
    :ooooooooooooooooooo+.      GPU: Intel Iris Pro
     `:+oo+/:-..-:/+o+/-        Memory: 3607MiB / 16384MiB
Bug Good First Issue

Most helpful comment

To my knowledge this is still a bug.

All 17 comments

Try M-x projectile-invalidate-cache to clear out deleted files

@lfender6445 This makes no difference.

Same problem, projectile-invalidate-cache doesn't help, restarting emacs doesn't help too,
the file disappears when I stage it with git (I mean using git add). That's definitely related to git, just checked one more time: deleted files dissapear after git adding them. Sorry, I don't have enough knowledge to dig into it any further

you have to do both, i.e. stage deletion with git along with cache invalidation afterwards

This is not true, as far as I can tell from the tests I just did. If you haven't staged the deletion, then invalidating the cache does nothing鈥攖he file will be shown regardless. If you _have_ staged the deletion, then invalidating the cache also does nothing鈥攖he file will not be shown regardless.

commenting here just to keep track of it!

@Andsbf There is a "subscribe to notifications" button that you can use to follow an issue without commenting.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

Just confirming that this issue is still reproducible with the current version of projectile. As I (like the original poster) find the current behavior confusing, I'm curious if anyone has found any workaround?

This is still reproducible. I just found out about it using Projectile 2.1.0snapshot. In the meantime as a workaround i set projectile-git-command to comm -23 <(git ls-files -co --exclude-standard | sort) <(git ls-files -d | sort) | tr '\n' '\0'

My workaround was to replace git ls-files with fd:

  1. Add this to init.el:
(setq projectile-git-command "fd . -0 --type f --hidden --color=never")
  1. Add this to ~/.fdignore to ignore .git directories while --hidden is used as proposed here:
**/.git/

Still have to find out how to deal with the files forcefully checked-in into Git despite being ignored by .gitignore..

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

To my knowledge this is still a bug.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

Unless I am mistaken, nothing has changed with regard to this bug.

This is because Projectile uses git ls-files in projectile-git-command, and git ls-files shows files in the index, not files in the working directory.

Yeah, that's true.

Seems to me the simplest way to solve this would be to adjust the command in question, although I'm not sure what would be the optimal replacement.

Relying on software such as fd might be an option, as suggested in https://github.com/bbatsov/projectile/issues/1148#issuecomment-555505464. I am not terribly familiar with the ecosystem of options, but I think it is likely that something suitable may exist.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sweord picture sweord  路  3Comments

Compro-Prasad picture Compro-Prasad  路  7Comments

yangchenyun picture yangchenyun  路  8Comments

DougBeney picture DougBeney  路  3Comments

ghost picture ghost  路  4Comments