Browse Source

Ensure EOL stream type is DIRECT when -text attribute is present

Otherwise fancy combinations of attributes (binary or -text in
combination with crlf or eol) may result in the corruption of binary
data.

Bug: 520910
Change-Id: I3ffc666c13d1b9d2ed987b69a67bfc7f42ccdbfc
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
stable-4.9
Thomas Wolf 7 years ago
parent
commit
a489a8ae9a
  1. 15
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java
  2. 16
      org.eclipse.jgit/src/org/eclipse/jgit/util/io/EolStreamTypeUtil.java

15
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java

@ -302,6 +302,21 @@ public class AddCommandTest extends RepositoryTestCase {
}
}
@Test
public void testAttributesConflictingMatch() throws Exception {
writeTrashFile(".gitattributes", "foo/** crlf=input\n*.jar binary");
writeTrashFile("foo/bar.jar", "\r\n");
// We end up with attributes [binary -diff -merge -text crlf=input].
// crlf should have no effect when -text is present.
try (Git git = new Git(db)) {
git.add().addFilepattern(".").call();
assertEquals(
"[.gitattributes, mode:100644, content:foo/** crlf=input\n*.jar binary]"
+ "[foo/bar.jar, mode:100644, content:\r\n]",
indexState(CONTENT));
}
}
@Test
public void testCleanFilterEnvironment()
throws IOException, GitAPIException {

16
org.eclipse.jgit/src/org/eclipse/jgit/util/io/EolStreamTypeUtil.java

@ -144,6 +144,11 @@ public final class EolStreamTypeUtil {
private static EolStreamType checkInStreamType(WorkingTreeOptions options,
Attributes attrs) {
if (attrs.isUnset("text")) {//$NON-NLS-1$
// "binary" or "-text" (which is included in the binary expansion)
return EolStreamType.DIRECT;
}
// old git system
if (attrs.isSet("crlf")) {//$NON-NLS-1$
return EolStreamType.TEXT_LF;
@ -154,9 +159,6 @@ public final class EolStreamTypeUtil {
}
// new git system
if (attrs.isUnset("text")) {//$NON-NLS-1$
return EolStreamType.DIRECT;
}
String eol = attrs.getValue("eol"); //$NON-NLS-1$
if (eol != null)
// check-in is always normalized to LF
@ -183,6 +185,11 @@ public final class EolStreamTypeUtil {
private static EolStreamType checkOutStreamType(WorkingTreeOptions options,
Attributes attrs) {
if (attrs.isUnset("text")) {//$NON-NLS-1$
// "binary" or "-text" (which is included in the binary expansion)
return EolStreamType.DIRECT;
}
// old git system
if (attrs.isSet("crlf")) {//$NON-NLS-1$
return FORCE_EOL_LF_ON_CHECKOUT ? EolStreamType.TEXT_LF
@ -194,9 +201,6 @@ public final class EolStreamTypeUtil {
}
// new git system
if (attrs.isUnset("text")) {//$NON-NLS-1$
return EolStreamType.DIRECT;
}
String eol = attrs.getValue("eol"); //$NON-NLS-1$
if (eol != null && "crlf".equals(eol)) //$NON-NLS-1$
return EolStreamType.TEXT_CRLF;

Loading…
Cancel
Save