From b3a8a94a97d7f1370f534c2bbe069ff0e24b2da9 Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Tue, 12 Oct 2021 22:14:33 +0200 Subject: Fix checkout of files with mixed line endings on text=auto eol=crlf Add tests for files having been checked in with mixed LF and CR-LF line endings, and then being checked out with text or text=auto and eol=lf or eol=crlf. These test cases were missing, and thus commit efd1cc05 missed that AutoCRLFOutputStream needs the same detection as AutoLFOutputStream. Fix AutoCRLFOutputStream to not convert line endings if the blob in the repository contains CR-LF. Bug: 575393 Change-Id: Id0c7ae772e282097e95fddcd3f1f9d82aae31e43 Signed-off-by: Thomas Wolf --- .../org/eclipse/jgit/lib/DirCacheCheckoutTest.java | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/lib') diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java index b943486b1b..af8a58f6f0 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java @@ -337,6 +337,34 @@ public class DirCacheCheckoutTest extends RepositoryTestCase { "first line\r\nsecond line\r\n", "f text=auto eol=crlf"); } + @Test + public void testCheckoutMixedAutoEolCrLf() throws Exception { + checkoutLineEndings("first line\nsecond line\r\n", + "first line\nsecond line\r\n", "f text=auto eol=crlf"); + } + + @Test + public void testCheckoutMixedAutoEolLf() throws Exception { + checkoutLineEndings("first line\nsecond line\r\n", + "first line\nsecond line\r\n", "f text=auto eol=lf"); + } + + @Test + public void testCheckoutMixedTextCrLf() throws Exception { + // Huh? Is this a bug in git? Both git 2.18.0 and git 2.33.0 do + // write the file with CRLF (and consequently report the file as + // modified in "git status" after check-out), however the CRLF in the + // repository is _not_ replaced by LF with eol=lf (see test below). + checkoutLineEndings("first line\nsecond line\r\n", + "first line\r\nsecond line\r\n", "f text eol=crlf"); + } + + @Test + public void testCheckoutMixedTextLf() throws Exception { + checkoutLineEndings("first line\nsecond line\r\nfoo", + "first line\nsecond line\r\nfoo", "f text eol=lf"); + } + private DirCacheCheckout resetHard(RevCommit commit) throws NoWorkTreeException, CorruptObjectException, IOException { -- cgit v1.2.3