apache / apache/netbeans

Git operations don't perform EOL conversion on text files

Open
#8,504 13 comments 0 reactions 0 assignees View on GitHub
git kind:bug
Dominant language
Java
Stars
3.1k
Forks
935
Avg merge
2d 3h
Merged PRs (30d)
17

Description

### Apache NetBeans version

Apache NetBeans 26 latest release candidate

### What happened

NetBeans' Git integration seems to not perform any EOL conversion on text files when *core.autocrlf* is set to *false* (or the default setting).

### Language / Project Type / NetBeans Component

VCS/Git

### How to reproduce

1. In your global _.gitconfig_, set:
```
[core]
eol = crlf
autocrlf = false # this is the default
```
The *core.eol = crlf* should force the default Windows behavior, even on Unix. The *autocrlf = false* is merely making the default explicit, it can also be left out.
3. Prepare a Git repository containing at least one non-empty text file containing line breaks, for example _Test.java_, and a *.gitattributes* file containing: `* text=auto`
`*.java text` # just to be sure
3. Clone the repository using NetBeans
4. In the terminal, check the line endings using `git ls-files --eol`. The result is:
```
i/lf w/lf attr/text=auto .gitattributes
i/lf w/lf attr/text Test.java
```
("i" are the line endings in the index/repository, "w" in the working directory.)
=> The files have been checked out as LF although according to the *core.eol* setting they should have been checked out as CRLF.
5. In the working directory, convert *Test.java* to CRLF using `unix2dos` or similar.
6. Make a dummy edit to *Test.java* so that NetBeans recognizes it as modified.
7. Commit the modification of *Test.java* using NetBeans (*Team* > *Commit...*)
8. Check again the line endings using `git ls-files --eol`. The result is:
```
i/lf w/lf attr/text=auto .gitattributes
i/crlf w/crlf attr/text Test.java
```
=> The file was committed with CRLF as-is, instead of being converted to LF.

The observed behavior is as if NetBeans/JGit is treating the files as binary files instead of text files.

Doing the checkouts/commits using command-line Git (specifically, version 2.39.0) does apply the expected EOL conversions.

### Did this work correctly in an earlier version?

No / Don't know

### Operating System

Windows 10

### JDK

JDK 21

### Apache NetBeans packaging

Apache NetBeans binary zip

### Anything else

For context, Git is supposed to work as follows, for files that are identified as text files (via *.gitattributes* or similar):
- The repository is expected to never contain CRLF line endings in text files.
- On check-in, CRLF line endings in text files are always converted to LF, regardless of *core.eol* or other settings.
- On checkout, LF line endings in text files are converted to CRLF iff *core.eol = crlf* (or equivalent settings in *.gitattributes*, or by means of *core.autocrlf*).

More details about the standard Git behavior here: https://dev.to/matthies/comment/2jeik

I don't know if this is a NetBeans issue or a JGit issue. However, it is an issue for cross-platform development with NetBeans.

### Are you willing to submit a pull request?

No

Contributor guide

Open the contributing guide

Research direction

Reproduce the behavior with the global .gitconfig, .gitattributes, and Test.java described in the issue, then compare NetBeans checkout and Team > Commit results using git ls-files --eol. Trace the NetBeans Git integration and its JGit handling of text attributes and core.eol. Done means checkout converts LF to CRLF when configured and commit converts CRLF back to LF.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, java
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.