.gitignore rules evaluated incorrectly
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.
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
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
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.
$ 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.
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.
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
Just came to say same thing! You likely need to use a second negate pattern with an end slash to get the desired behaviour.
Hmm, strange. I wonder why the files aren't ignored when I change them from the command line.
what should we do with this one? close?