|
|
@@ -47,12 +47,19 @@ import static org.junit.Assert.assertEquals; |
|
|
|
import static org.junit.Assert.assertFalse; |
|
|
|
import static org.junit.Assert.assertNotNull; |
|
|
|
import static org.junit.Assert.assertTrue; |
|
|
|
import static org.junit.Assert.fail; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.text.MessageFormat; |
|
|
|
|
|
|
|
import org.eclipse.jgit.errors.CorruptObjectException; |
|
|
|
import org.eclipse.jgit.internal.JGitText; |
|
|
|
import org.eclipse.jgit.junit.MockSystemReader; |
|
|
|
import org.eclipse.jgit.junit.RepositoryTestCase; |
|
|
|
import org.eclipse.jgit.lib.Constants; |
|
|
|
import org.eclipse.jgit.lib.FileMode; |
|
|
|
import org.eclipse.jgit.lib.ObjectInserter; |
|
|
|
import org.eclipse.jgit.util.SystemReader; |
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
public class DirCacheBasicTest extends RepositoryTestCase { |
|
|
@@ -234,4 +241,41 @@ public class DirCacheBasicTest extends RepositoryTestCase { |
|
|
|
final byte[] path = Constants.encode("a"); |
|
|
|
assertEquals(-1, dc.findEntry(path, path.length)); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testRejectInvalidWindowsPaths() throws Exception { |
|
|
|
SystemReader.setInstance(new MockSystemReader() { |
|
|
|
{ |
|
|
|
setUnix(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
String path = "src/con.txt"; |
|
|
|
DirCache dc = db.lockDirCache(); |
|
|
|
DirCacheBuilder b = dc.builder(); |
|
|
|
DirCacheEntry e = new DirCacheEntry(path); |
|
|
|
e.setFileMode(FileMode.REGULAR_FILE); |
|
|
|
e.setObjectId(new ObjectInserter.Formatter().idFor( |
|
|
|
Constants.OBJ_BLOB, |
|
|
|
Constants.encode(path))); |
|
|
|
b.add(e); |
|
|
|
b.commit(); |
|
|
|
db.readDirCache(); |
|
|
|
|
|
|
|
SystemReader.setInstance(new MockSystemReader() { |
|
|
|
{ |
|
|
|
setWindows(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
try { |
|
|
|
db.readDirCache(); |
|
|
|
fail("should have rejected " + path); |
|
|
|
} catch (CorruptObjectException err) { |
|
|
|
assertEquals(MessageFormat.format(JGitText.get().invalidPath, path), |
|
|
|
err.getMessage()); |
|
|
|
assertNotNull(err.getCause()); |
|
|
|
assertEquals("invalid name 'CON'", err.getCause().getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |