netbeans icon indicating copy to clipboard operation
netbeans copied to clipboard

.gitignore rules evaluated incorrectly

Open pressing-buttons opened this issue 1 year ago • 8 comments

Apache NetBeans version

Apache NetBeans 21

What happened

When a git repository contains a .gitignore file, rules with wildcards that should only be applied to files are interpreted for directories NetBeans.

E.g. the rule:

**/*out*

only ignores files that contain the string out, but not files in directories, where the directory name contains the string out

Language / Project Type / NetBeans Component

Java Maven Project

How to reproduce

Please open the attached ZIP archive containing a sample git repository.

In the Projects window SomeService.java is displayed as an ignored file, even though it's not ignored by git. git check-ignore -v -- * will not report that file as ignored.

project display

git-ignore-bug.zip

Did this work correctly in an earlier version?

No / Don't know

Operating System

Windows 10

JDK

Adoptium OpenJDK 17

Apache NetBeans packaging

Apache NetBeans binary zip

Anything else

No response

Are you willing to submit a pull request?

No

pressing-buttons avatar Apr 22 '24 19:04 pressing-buttons

In the Projects window SomeService.java is displayed as an ignored file, even though it's not ignored by git.

i removed .git and ran git init + commit again as precaution and it committed only the following files:

$ git log --name-status                                                                                                                                                       
commit 9c90b0c4f2ffeb9436028cc84c02e9853b6fbda1 (HEAD -> master)
Author: test <test@test>
Date:   Tue Apr 23 03:15:16 2024 +0200

    init

A       .gitignore
A       pom.xml
A       src/main/java/com/example/GitIgnoreSample.java
$ git --version
git version 2.44.0

$ tree                                                                                                                                                     
.
├── pom.xml
└── src
    └── main
        └── java
            └── com
                └── example
                    ├── GitIgnoreSample.java
                    └── router
                        ├── newfile
                        └── SomeService.java

7 directories, 4 files

$ cat .gitignore                                                                                                                                           
**/build/
**/*.tmp
**/*out*

$ git status
On branch master
nothing to commit, working tree clean

this seems to work as expected.

In NB: rightclick -> git -> show changes is also empty

mbien avatar Apr 23 '24 01:04 mbien

What does git check-ignore show for you? For me, it doesn't list the files in the router directory which means (at least in my understanding) that git doesn't ignore them.

pressing-buttons avatar Apr 23 '24 05:04 pressing-buttons

$ git check-ignore -v src/main/java/com/example/router/SomeService.java 
.gitignore:3:**/*out*	src/main/java/com/example/router/SomeService.java

the "router" folder matches the *out* rule and everything in it is ignored. That is what you want, right?

Since you are on windows: how are you using git? It could be a windows specific issue since file systems and paths are very different.

mbien avatar Apr 23 '24 06:04 mbien

According to the git documentation **/*out* should only exclude files, not directories (that would require a / at the end of the expression). I can modify and commit the files inside the directory without problems through git on the command line, so they are clearly not ignored. I expected NetBeans to not display them as ignored files.

pressing-buttons avatar Apr 23 '24 16:04 pressing-buttons

According to the git documentation **/out should only exclude files, not directories (that would require a / at the end of the expression).

quote from the doc:

"If there is a separator at the end of the pattern then the pattern will only match directories, otherwise the pattern can match both files and directories."

https://git-scm.com/docs/gitignore#_pattern_format

mbien avatar Apr 23 '24 16:04 mbien

Just came to say same thing! You likely need to use a second negate pattern with an end slash to get the desired behaviour.

neilcsmith-net avatar Apr 23 '24 16:04 neilcsmith-net

Hmm, strange. I wonder why the files aren't ignored when I change them from the command line.

pressing-buttons avatar Apr 23 '24 18:04 pressing-buttons

what should we do with this one? close?

mbien avatar May 06 '24 18:05 mbien