atom / tree-view

🌳 Explore and open project files in Atom
MIT License
561 stars 364 forks source link

.gitignore cascaded negations not working correctly #196

Open rafitorres opened 10 years ago

rafitorres commented 10 years ago

Let's say I add the following rules to my .gitignore to ignore everything in the root except the wp-content directory:

/*
!.gitignore
!wp-content/

So far this works correctly (only .gitignore and wp-content/ are shown in the tree view). Now I add the following rules to ignore everything in the wp-content directory, except the plugins and themes directories

wp-content/*
!wp-content/plugins/
!wp-content/themes/

Before Atom 0.116.0, the plugins and themes directories were shown correctly in the tree view, but now the wp-content directory disappears completely. My machine's git (v2.0.0) parses the .gitignore correctly and sees changes in plugins and themes.

I see that 0.116.0 moved to libgit2 0.21.0. If this is what's causing this behavior I'll open an issue with them.

kevinsawicki commented 10 years ago

I'd like to try an reproduce this and then open an issue on libgit2 if it is an issue there.

Does your repo have multiple .gitignore files in different folders or is the example all in the .gitignore file at the root of the repo with the content:

/*
!.gitignore
!wp-content/
wp-content/*
!wp-content/plugins/
!wp-content/themes/
rafitorres commented 10 years ago

Just one .gitignore on the root with that content, yes.

moretti commented 10 years ago

I have a similar problem. I'm not sure if I should create a new issue. With the following .gitignore:

node_modules/*
!node_modules/mylib

mylib appears grayed out, even if it's not ignored:

screen

I'm pretty sure that this was working in the previous versions.

kylehotchkiss commented 9 years ago

+1, still getting this in latest version ( atom 0.169.0 / tree view 0.147.0 )

50Wliu commented 9 years ago

I think I may be having the opposite problem (or it could just be that my gitignore skills are bad). I have the following in my .gitignore file:

addons/sourcemod/scripting/**
addons/sourcemod/scripting/include/**
!addons/sourcemod/scripting/include/
!addons/sourcemod/scripting/include/freak_fortress_2*.inc

freak_fortress_2.inc etc. show up properly and respond to changes correctly, but any other file in /include/ shows up as newly added (aka green).

Oh noes

The full .gitignore file is available here.

ghost commented 9 years ago

Ubuntu 14.04 LTS, tree-view 0.162.0, atom 0.184.0 atom_tree

stramel commented 9 years ago

I believe this is related to this issue. I have a git ignored folder with a negated git ignore folder inside it. When clicking Hide VCS Ignored Files it hides the highest ignored file and all of its contents. I don't think it should be hiding that folder if it contains project files still.

#.gitignore (snippet)
/dist/src/main/webapp/
/dist/target
!/dist/src/main/webapp/WEB-INF/

Showing VCS Ignored Files: Shown VCS Files

Hiding VCS Ignored Files Hidden VCS Files

acontreras89 commented 9 years ago

:+1:

ghost commented 9 years ago

Hi everyone !

Same issue here, with this .gitignore file.

/*
!/.gitignore

!/components
/components/*
!/components/com_hello

!/media
/media/*
!/media/com_hello

...

Files in both /components/com_hello and /media/com_hello were ignored in the tree view. So I changed it for this :

/*
!/.gitignore

!/components
/components/*
!/components/com_hello
!/components/com_hello/*

!/media
/media/*
!/media/com_hello
!/media/com_hello/*

...

Those two new lines are useless for git but allow the tree view to track files in both folders. However if the file /components/com_hello/hello.php is modified the components/ folder will not be displayed as modified (but com_hello/ AND hello.php will be).

[UPDATE]

Ok, I think I have found something !

Just switch some lines and everything seems to work like a charm !

/*
!/.gitignore

/components/*
!/components

!/components/com_hello
!/components/com_hello/*

/media/*
!/media
!/media/com_hello
!/media/com_hello/*

...
jfrazier commented 8 years ago

I was having the same issue, where the negated file ignore entries (using !) were not being picked up by fuzzy finder or in the tree view. Using the work around that @KevinHivert suggested fixes the issue.

Original: node_modules !src/node_modules

changed it to: !src/node_modules node_modules/*

Clue: I changed my original to:

node_modules !src/node_modules

to:

node_modules/* !src/nodemodules

and it shows up as not grayed-out in tree view, but does not show up in the fuzzyfinder

dead-claudia commented 8 years ago

Me thinks this is not a bug with this, since there's nothing modifying file statuses in transit here, but a bug in Atom or one of its dependencies. I traced the dependency chain from there to this:

One of these files (or libgit2) has to have the bug, and I don't think tree-view has it.

BTW I'm affected as well.

samirfor commented 8 years ago

+1

joshaber commented 8 years ago

Thanks all, this is almost certainly a bug in libgit2.

pablasso commented 8 years ago

If I remember correctly, @albertein tested the response of libgit2 and it was working correctly.

The issue is that every folder is lazy loaded hence you won't know if there's a file that shouldn't be ignored inside an ignored one. See #524.

Ajedi32 commented 8 years ago

@pablasso If that's the issue, then I think what should happen is that tree-view should only ignore the directory if the directory itself is matched by .gitignore. Just because all the files currently in a directory are matched by .gitignore, doesn't necessarily mean that all files will be.

No idea what functions tree-view is using under the hood, but the git check-ignore command can get this information trivially. (If running it on a directory returns 0, the directory is ignored. Otherwise it's not.)

albertein commented 8 years ago

@Ajedi32 The problem is that the directory itself its matched, but you also have a rule to not match subdirectories of that directory, so asking libgit2 for wether the pater directory is ignored returns true and tree-view never gets to know there are files inside that directory which are not ignored.

Ajedi32 commented 8 years ago

@albertein If the directory itself is matched, then even the standard git CLI will ignore the negated matchers matching files inside the directory. From the docs:

  • An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again. It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn’t list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined. Put a backslash ("\") in front of the first "!" for patterns that begin with a literal "!", for example, "!important!.txt".

git distinguishes between ignoring all files in a directory, and ignoring the directory itself. tree-view, for whatever reason, apparently doesn't.

oomathias commented 5 years ago

Here is (another) case:

Steps to reproduce

.gitignore

*           # Ignore all files
!/**/       # Allow directories
!*.keep     # Allow .keep files
!.gitignore # Allow .gitignore

files

.
β”œβ”€β”€ .gitignore
└── src
    β”œβ”€β”€ A
    └── A.keep

Actual Behavior

screenshot 21

Expected Behavior

Proof

screenshot 23
oomathias commented 5 years ago

Looks like libgit2 is causing the bug. See my referenced issue. https://github.com/libgit2/libgit2/pull/5020 might help (not released yet)

oomathias commented 5 years ago

A fix has been written for libgit2 (not merged yet).

So isPathIgnored will treat paths with trailing "/" as directories. So we need to ensure that Atom passes a trailing "/" when checking for a directory.

Should I create another issue in the main repo to make sure of this ?

Also, some bugs present in this thread are resolved inside the latest version of libgit2. https://github.com/atom/git-utils is the one including libgit2 and there was a version bump from v0.27.0 to v0.28.1 which will fix them.

Looks like this 5 years old issue might close soonish.

50Wliu commented 5 years ago

Should I create another issue in the main repo to make sure of this ?

Yes, I think this would be helpful.

rbianchi-ittweb commented 4 years ago

I think that all of these issues could be solved adding this immediately after the symbol: `!/`

Then, add all the subfolders and file...

baloe commented 3 years ago

I think that all of these issues could be solved adding this immediately after the symbol: `!/`

Then, add all the subfolders and file...

you mean, a .gitignore file like so?

*
!*/
!some_folder/**

Nope, that does not help. Files in some_folder are still hidden by tree-view.

baloe commented 3 years ago
*
!some_folder
!some_folder/**

actually works, with files and folders in some_folder being shown.