Bug 561341 - jGit misinterprets "* text=auto eol=lf" treating all files as text files
Summary: jGit misinterprets "* text=auto eol=lf" treating all files as text files
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 5.7   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 5.8   Edit
Assignee: Thomas Wolf CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-03-22 13:51 EDT by Rafał Sumisławski CLA
Modified: 2020-05-22 18:27 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rafał Sumisławski CLA 2020-03-22 13:51:22 EDT
I think this is the same issue as git used to have prior to version 2.10 https://github.com/git/git/blob/master/Documentation/RelNotes/2.10.0.txt#L248

A "* text=auto eol=lf" set in .gitattributes should be interpreted as "automatically detect which files are text files and use lf". Instead, when jGit sees it, it uses lf in all files.

Here's a minimal example demonstrating the inconsistency of git (2.16.6) and jGit (5.7.0.202003110725-r) behaviours:


This works fine:
git clone https://github.com/RafalSumislawski/jgit-text-auto-issue.git .
git checkout test-branch




This (usually) fails with a CheckoutConflictException, because when checking for modifications, jGit replaces a \r\n in the png header of whitepixel.png with a \n and then sees it as a modification/conflict:

Code:

package aaa;

import org.eclipse.jgit.api.CreateBranchCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Ref;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Test {

    public static void main(String[] args) throws GitAPIException, IOException {
        String url = "https://github.com/RafalSumislawski/jgit-text-auto-issue.git";
        String branch = "test-branch";
        Path dir = Paths.get(args[0]);

        Git git = Git.cloneRepository()
            .setCloneAllBranches(false)
            .setURI(url)
            .setDirectory(dir.toFile())
            .setBranch("master")
            .call();


        Ref headsRef = git.getRepository().findRef("refs/heads/" + branch);

        if (headsRef == null) {
            git.branchCreate()
                .setName(branch)
                .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK)
                .setStartPoint("origin/" + branch)
                .setForce(true)
                .call();
        }

        git.checkout().setName("refs/heads/" + branch).call();
    }
}



Output:
Exception in thread "main" whitepixel.png
        at org.eclipse.jgit.api.CheckoutCommand.call(CheckoutCommand.java:252)
        at aaa.Test.main(Test.java:38)
Caused by: org.eclipse.jgit.errors.CheckoutConflictException: Checkout conflict with files:
whitepixel.png
        at org.eclipse.jgit.dircache.DirCacheCheckout.doCheckout(DirCacheCheckout.java:502)
        at org.eclipse.jgit.dircache.DirCacheCheckout.checkout(DirCacheCheckout.java:467)
        at org.eclipse.jgit.api.CheckoutCommand.call(CheckoutCommand.java:248)
        ... 1 more
Comment 1 Eclipse Genie CLA 2020-03-23 12:00:02 EDT
New Gerrit change created: https://git.eclipse.org/r/159904
Comment 2 Thomas Wolf CLA 2020-04-04 16:01:42 EDT
See also https://www.eclipse.org/forums/index.php/t/1103192/
Comment 3 Eclipse Genie CLA 2020-05-22 18:26:20 EDT
Gerrit change https://git.eclipse.org/r/159904 was merged to [master].
Commit: http://git.eclipse.org/c/jgit/jgit.git/commit/?id=3c34e0acbfcac236daaf746690130c6e99a8e524