Skip to content

Git operations don't perform EOL conversion on text files #8504

Open
@nmatt

Description

@nmatt

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    git[ci] enable versioning jobkind:bugBug report or fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions