projectile icon indicating copy to clipboard operation
projectile copied to clipboard

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

Open Yevgnen opened this issue 9 years ago • 19 comments

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

Yevgnen avatar Oct 23 '16 16:10 Yevgnen

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?

seagle0128 avatar May 06 '17 09:05 seagle0128

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.

mpolden avatar May 31 '17 18:05 mpolden

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

fengfengChina avatar Jan 19 '18 16:01 fengfengChina

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

mpolden avatar Jan 19 '18 18:01 mpolden

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.

jsirex avatar Jan 19 '18 18:01 jsirex

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

seagle0128 avatar Jan 20 '18 09:01 seagle0128

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!

stale[bot] avatar May 08 '19 18:05 stale[bot]

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

jijingg avatar May 16 '19 09:05 jijingg

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

divs1210 avatar Jun 07 '19 20:06 divs1210

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

nvkv avatar Nov 06 '19 17:11 nvkv

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)
  ...)

nvkv avatar Nov 06 '19 17:11 nvkv

Any updates on this issue? it is getting very frustrating

hisnawi avatar Feb 13 '20 06:02 hisnawi

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

guraltsev avatar Jun 30 '20 02:06 guraltsev

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

wminshew avatar Aug 06 '20 23:08 wminshew

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.

Aeyk avatar Nov 12 '20 18:11 Aeyk

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 avatar Dec 04 '20 17:12 bbatsov

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/

bbatsov avatar Dec 04 '20 17:12 bbatsov

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

sammorley-short avatar Apr 21 '21 23:04 sammorley-short

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)

soanvig avatar Jan 02 '22 23:01 soanvig