bbatsov / projectile

Project Interaction Library for Emacs
https://docs.projectile.mx
GNU General Public License v3.0
3.99k stars 585 forks source link

Projectile does not ignore contents in .gitignore after opening respective the file directly #1075

Open Yevgnen opened 7 years ago

Yevgnen commented 7 years ago

Expected behavior

Projectile will ignore the file when projectile-enable-caching is set to t.

Actual behavior

Projectile dose not ignore the file when projectile-enable-caching is set to t after open a ignored file directly in project.

Steps to reproduce the problem

Minimal test config

(setq package-archives '(("marmalade" . "http://marmalade-repo.org/packages/")
                         ("gnu" . "http://elpa.gnu.org/packages/")
                         ("melpa" . "https://melpa.org/packages/")
                         ("org" . "http://orgmode.org/elpa/")))

(package-initialize)
(setq package-enable-at-startup nil)

(unless (and (file-exists-p (expand-file-name "elpa/archives/marmalade" user-emacs-directory))
             (file-exists-p (expand-file-name "elpa/archives/gnu" user-emacs-directory))
             (file-exists-p (expand-file-name "elpa/archives/melpa" user-emacs-directory))
             (file-exists-p (expand-file-name "elpa/archives/org" user-emacs-directory)))
  (package-refresh-contents))

(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

(setq use-package-verbose t
      use-package-enable-imenu-support t)
(require 'use-package)

(use-package projectile
  :ensure t
  :diminish projectile-mode
  :commands (projectile-global-mode)
  :init (setq projectile-enable-caching t)
  :config (projectile-global-mode 1))

Run the setup config

mkdir /tmp/project
cd /tmp/project
git init .
mkdir ignore
touch ignore/i
touch ignore/j
touch ignore/k
touch a
touch b
touch c
echo "ignore" >> .gitignore
git add .
git commit -m "first commit"

Run

(progn
  (find-file "/tmp/project/a")
  (projectile-find-file))

then C-g and run

(progn
  (find-file "/tmp/project/a")
  (find-file "/tmp/project/j")
  (projectile-find-file))

to see the difference, and will get a message File j added to project /private/tmp/project/ cache.

Environment & Version information

Projectile version information

Projectile 20161008.47

Emacs version

GNU Emacs 25.1.1 (x86_64-apple-darwin16.0.0, Carbon Version 157 AppKit 1504) of 2016-09-21

Operating system

macOS 10.12

seagle0128 commented 7 years ago

I am experiencing this painful issue on Windows. It's very slow if disabling cache. I think it's a bug. All files in .gitignore and .ignore should not be cached in a git project, in my opinion. Can anyone fix this defect?

mpolden commented 7 years ago

I'm experiencing this bug as well. I was wondering why ignored files were being added to the cache. After a quick look at the code, it looks like only ignores in .projectile are considered in this case.

Adding to the confusion: Clearing the cache (e.g. projectile-find-file with prefix arg) will get rid of those files until they are opened again.

fengfengChina commented 6 years ago

.gitignore can work well in master version.My Mac version is macOS 10.13.1.check again? confirm projectile version is up to date.

mpolden commented 6 years ago

I can still reproduce this bug on Projectile version 20180118.745 from Melpa.

jsirex commented 6 years ago

Let me add something here. It is very annoying when projectile doesn't ignore git-ignored files while doing projectile-grep. But for me projectile-find-file works as expected on latest and previous versions.

seagle0128 commented 6 years ago

@jsirex So, I am using projectile-ag and rg-projectile instead.

stale[bot] commented 5 years ago

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!

jijingg commented 5 years ago

.gitignore not worked in windows , use .projectile instead . but .gitignore work well on macos and linux

divs1210 commented 5 years ago

facing this on mac. projectile-find-file works fine, but projectile-grep includes ignored files, flooding the results buffer.

nvkv commented 4 years ago

Is there any news on this one? Extremely frustrating on Windows :(

nvkv commented 4 years ago

Okay, I have found a workaround for windows. You have to have Msys64 or any other "posix userspace" installed.

(setenv "PATH" (concat "C:\\msys64\\usr\\bin;" (getenv "PATH")))

...

(use-package projectile
  :ensure t
  :custom
  (projectile-indexing-method 'alien)
  ...)
hisnawi commented 4 years ago

Any updates on this issue? it is getting very frustrating

guraltsev commented 4 years ago

Same here: problem under windows. Invalidating cache does not help.

wminshew commented 4 years ago

I suspect a lot of these issues will be resolved by setting projectile-indexing-method (as nvkv showed) -- if set to native (default on windows), it is very slow and also ignores .gitignore; if set to alien it follows .gitignore & ignores .projectile. If set to hybrid it pays attention to both .gitignore & .projectile

Aeyk commented 3 years ago

I suspect a lot of these issues will be resolved by setting projectile-indexing-method (as nvkv showed) -- if set to native (default on windows), it is very slow and also ignores .gitignore; if set to alien it follows .gitignore & ignores .projectile. If set to hybrid it pays attention to both .gitignore & .projectile

I am on manjaro linux and changing those had no consequence for me. Anyway, the workaround above of using ag / rg works for me, they follow my .gitignore.

bbatsov commented 3 years ago

Btw, the native indexing was made quite a bit faster a few months ago.

As for the rest - check out https://docs.projectile.mx/projectile/configuration.html#project-indexing-method

Basically, Projectile doesn't know anything about .gitignore, but if you're using hybrid/alien indexing the tool that Projectile will shell out to might know about .gitignore (e.g. by default it defers to git ls-files).

bbatsov commented 3 years ago

Also - on Windows I think it's best to run Emacs in WSL as described here https://emacsredux.com/blog/2020/09/23/using-emacs-on-windows-with-wsl2/

sammorley-short commented 3 years ago

facing this on mac. projectile-find-file works fine, but projectile-grep includes ignored files, flooding the results buffer.

I am having this issue also

soanvig commented 2 years ago

Bump on projectile-grep issue not ignoring .gitignore.

Workaround: (setq projectile-use-git-grep t) - this will work in git repositories, since it uses git grep version, which ignores .gitignore.

Also, Emacs produces find (+ grep) command for looking for files. If it could use fd app (which is "better" find) it would also ignore files from.gitignore(because this is howfd` works by default)