|
|
|
@ -44,9 +44,7 @@
|
|
|
|
|
package org.eclipse.jgit.api; |
|
|
|
|
|
|
|
|
|
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; |
|
|
|
@ -63,7 +61,6 @@ import org.eclipse.jgit.lib.Constants;
|
|
|
|
|
import org.eclipse.jgit.lib.FileMode; |
|
|
|
|
import org.eclipse.jgit.lib.ObjectId; |
|
|
|
|
import org.eclipse.jgit.lib.ObjectInserter; |
|
|
|
|
import org.eclipse.jgit.lib.Repository; |
|
|
|
|
import org.eclipse.jgit.lib.RepositoryTestCase; |
|
|
|
|
import org.eclipse.jgit.lib.StoredConfig; |
|
|
|
|
import org.eclipse.jgit.revwalk.RevCommit; |
|
|
|
@ -114,7 +111,7 @@ public class AddCommandTest extends RepositoryTestCase {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testAddExistingSingleFileWithNewLine() throws IOException, |
|
|
|
|
public void testAddExistingSingleSmallFileWithNewLine() throws IOException, |
|
|
|
|
NoFilepatternException { |
|
|
|
|
File file = new File(db.getWorkTree(), "a.txt"); |
|
|
|
|
FileUtils.createNewFile(file); |
|
|
|
@ -137,6 +134,35 @@ public class AddCommandTest extends RepositoryTestCase {
|
|
|
|
|
indexState(CONTENT)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testAddExistingSingleMediumSizeFileWithNewLine() |
|
|
|
|
throws IOException, NoFilepatternException { |
|
|
|
|
File file = new File(db.getWorkTree(), "a.txt"); |
|
|
|
|
FileUtils.createNewFile(file); |
|
|
|
|
StringBuilder data = new StringBuilder(); |
|
|
|
|
for (int i = 0; i < 1000; ++i) { |
|
|
|
|
data.append("row1\r\nrow2"); |
|
|
|
|
} |
|
|
|
|
String crData = data.toString(); |
|
|
|
|
PrintWriter writer = new PrintWriter(file); |
|
|
|
|
writer.print(crData); |
|
|
|
|
writer.close(); |
|
|
|
|
String lfData = data.toString().replaceAll("\r", ""); |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
db.getConfig().setString("core", null, "autocrlf", "false"); |
|
|
|
|
git.add().addFilepattern("a.txt").call(); |
|
|
|
|
assertEquals("[a.txt, mode:100644, content:" + data + "]", |
|
|
|
|
indexState(CONTENT)); |
|
|
|
|
db.getConfig().setString("core", null, "autocrlf", "true"); |
|
|
|
|
git.add().addFilepattern("a.txt").call(); |
|
|
|
|
assertEquals("[a.txt, mode:100644, content:" + lfData + "]", |
|
|
|
|
indexState(CONTENT)); |
|
|
|
|
db.getConfig().setString("core", null, "autocrlf", "input"); |
|
|
|
|
git.add().addFilepattern("a.txt").call(); |
|
|
|
|
assertEquals("[a.txt, mode:100644, content:" + lfData + "]", |
|
|
|
|
indexState(CONTENT)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testAddExistingSingleBinaryFile() throws IOException, |
|
|
|
|
NoFilepatternException { |
|
|
|
@ -658,40 +684,6 @@ public class AddCommandTest extends RepositoryTestCase {
|
|
|
|
|
assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testSubmoduleDeleteNotStagedWithUpdate() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
writeTrashFile("file.txt", "content"); |
|
|
|
|
git.add().addFilepattern("file.txt").call(); |
|
|
|
|
assertNotNull(git.commit().setMessage("create file").call()); |
|
|
|
|
|
|
|
|
|
SubmoduleAddCommand command = new SubmoduleAddCommand(db); |
|
|
|
|
String path = "sub"; |
|
|
|
|
command.setPath(path); |
|
|
|
|
String uri = db.getDirectory().toURI().toString(); |
|
|
|
|
command.setURI(uri); |
|
|
|
|
Repository repo = command.call(); |
|
|
|
|
assertNotNull(repo); |
|
|
|
|
assertNotNull(git.commit().setMessage("add submodule").call()); |
|
|
|
|
|
|
|
|
|
assertTrue(git.status().call().isClean()); |
|
|
|
|
|
|
|
|
|
FileUtils.delete(repo.getWorkTree(), FileUtils.RECURSIVE); |
|
|
|
|
FileUtils.mkdir(new File(db.getWorkTree(), path), false); |
|
|
|
|
|
|
|
|
|
assertNotNull(git.add().addFilepattern(".").setUpdate(true).call()); |
|
|
|
|
|
|
|
|
|
Status status = git.status().call(); |
|
|
|
|
assertFalse(status.isClean()); |
|
|
|
|
assertTrue(status.getAdded().isEmpty()); |
|
|
|
|
assertTrue(status.getChanged().isEmpty()); |
|
|
|
|
assertTrue(status.getRemoved().isEmpty()); |
|
|
|
|
assertTrue(status.getUntracked().isEmpty()); |
|
|
|
|
assertTrue(status.getModified().isEmpty()); |
|
|
|
|
assertEquals(1, status.getMissing().size()); |
|
|
|
|
assertEquals(path, status.getMissing().iterator().next()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private DirCacheEntry addEntryToBuilder(String path, File file, |
|
|
|
|
ObjectInserter newObjectInserter, DirCacheBuilder builder, int stage) |
|
|
|
|
throws IOException { |
|
|
|
|