diff options
Diffstat (limited to 'org.eclipse.jgit.test')
22 files changed, 456 insertions, 166 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java index 2fb228e01d..fd74098496 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java @@ -52,6 +52,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.PrintWriter; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.NoFilepatternException; import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCacheBuilder; @@ -72,7 +73,7 @@ import org.junit.Test; public class AddCommandTest extends RepositoryTestCase { @Test - public void testAddNothing() { + public void testAddNothing() throws GitAPIException { Git git = new Git(db); try { @@ -85,7 +86,7 @@ public class AddCommandTest extends RepositoryTestCase { } @Test - public void testAddNonExistingSingleFile() throws NoFilepatternException { + public void testAddNonExistingSingleFile() throws GitAPIException { Git git = new Git(db); DirCache dc = git.add().addFilepattern("a.txt").call(); @@ -94,7 +95,7 @@ public class AddCommandTest extends RepositoryTestCase { } @Test - public void testAddExistingSingleFile() throws IOException, NoFilepatternException { + public void testAddExistingSingleFile() throws IOException, GitAPIException { File file = new File(db.getWorkTree(), "a.txt"); FileUtils.createNewFile(file); PrintWriter writer = new PrintWriter(file); @@ -112,7 +113,7 @@ public class AddCommandTest extends RepositoryTestCase { @Test public void testAddExistingSingleSmallFileWithNewLine() throws IOException, - NoFilepatternException { + GitAPIException { File file = new File(db.getWorkTree(), "a.txt"); FileUtils.createNewFile(file); PrintWriter writer = new PrintWriter(file); @@ -136,7 +137,7 @@ public class AddCommandTest extends RepositoryTestCase { @Test public void testAddExistingSingleMediumSizeFileWithNewLine() - throws IOException, NoFilepatternException { + throws IOException, GitAPIException { File file = new File(db.getWorkTree(), "a.txt"); FileUtils.createNewFile(file); StringBuilder data = new StringBuilder(); @@ -165,7 +166,7 @@ public class AddCommandTest extends RepositoryTestCase { @Test public void testAddExistingSingleBinaryFile() throws IOException, - NoFilepatternException { + GitAPIException { File file = new File(db.getWorkTree(), "a.txt"); FileUtils.createNewFile(file); PrintWriter writer = new PrintWriter(file); @@ -188,7 +189,8 @@ public class AddCommandTest extends RepositoryTestCase { } @Test - public void testAddExistingSingleFileInSubDir() throws IOException, NoFilepatternException { + public void testAddExistingSingleFileInSubDir() throws IOException, + GitAPIException { FileUtils.mkdir(new File(db.getWorkTree(), "sub")); File file = new File(db.getWorkTree(), "sub/a.txt"); FileUtils.createNewFile(file); @@ -206,7 +208,8 @@ public class AddCommandTest extends RepositoryTestCase { } @Test - public void testAddExistingSingleFileTwice() throws IOException, NoFilepatternException { + public void testAddExistingSingleFileTwice() throws IOException, + GitAPIException { File file = new File(db.getWorkTree(), "a.txt"); FileUtils.createNewFile(file); PrintWriter writer = new PrintWriter(file); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java index 32d2e01b24..b000fe24e5 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java @@ -466,9 +466,7 @@ public class BranchCommandTest extends RepositoryTestCase { public Ref createBranch(Git actGit, String name, boolean force, String startPoint, SetupUpstreamMode mode) - throws JGitInternalException, RefAlreadyExistsException, - RefNotFoundException, - InvalidRefNameException { + throws JGitInternalException, GitAPIException { CreateBranchCommand cmd = actGit.branchCreate(); cmd.setName(name); cmd.setForce(force); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java index b1cac3a54d..9060cd5307 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java @@ -56,11 +56,11 @@ import java.io.FileInputStream; import java.io.IOException; import org.eclipse.jgit.api.CheckoutResult.Status; -import org.eclipse.jgit.api.errors.CheckoutConflictException; -import org.eclipse.jgit.api.errors.InvalidRefNameException; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.JGitInternalException; -import org.eclipse.jgit.api.errors.RefAlreadyExistsException; import org.eclipse.jgit.api.errors.RefNotFoundException; +import org.eclipse.jgit.dircache.DirCache; +import org.eclipse.jgit.dircache.DirCacheEntry; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.RefUpdate; @@ -127,9 +127,7 @@ public class CheckoutCommandTest extends RepositoryTestCase { } @Test - public void testCheckoutToNonExistingBranch() throws JGitInternalException, - RefAlreadyExistsException, InvalidRefNameException, - CheckoutConflictException { + public void testCheckoutToNonExistingBranch() throws GitAPIException { try { git.checkout().setName("badbranch").call(); fail("Should have failed"); @@ -223,8 +221,7 @@ public class CheckoutCommandTest extends RepositoryTestCase { @Test public void testDetachedHeadOnCheckout() throws JGitInternalException, - RefAlreadyExistsException, RefNotFoundException, - InvalidRefNameException, IOException, CheckoutConflictException { + IOException, GitAPIException { CheckoutCommand co = git.checkout(); co.setName("master").call(); @@ -236,4 +233,41 @@ public class CheckoutCommandTest extends RepositoryTestCase { assertFalse(head.isSymbolic()); assertSame(head, head.getTarget()); } + + @Test + public void testUpdateSmudgedEntries() throws Exception { + git.branchCreate().setName("test2").call(); + RefUpdate rup = db.updateRef(Constants.HEAD); + rup.link("refs/heads/test2"); + + File file = new File(db.getWorkTree(), "Test.txt"); + long size = file.length(); + long mTime = file.lastModified() - 5000L; + assertTrue(file.setLastModified(mTime)); + + DirCache cache = DirCache.lock(db.getIndexFile(), db.getFS()); + DirCacheEntry entry = cache.getEntry("Test.txt"); + assertNotNull(entry); + entry.setLength(0); + entry.setLastModified(0); + cache.write(); + assertTrue(cache.commit()); + + cache = DirCache.read(db.getIndexFile(), db.getFS()); + entry = cache.getEntry("Test.txt"); + assertNotNull(entry); + assertEquals(0, entry.getLength()); + assertEquals(0, entry.getLastModified()); + + db.getIndexFile().setLastModified( + db.getIndexFile().lastModified() - 5000); + + assertNotNull(git.checkout().setName("test").call()); + + cache = DirCache.read(db.getIndexFile(), db.getFS()); + entry = cache.getEntry("Test.txt"); + assertNotNull(entry); + assertEquals(size, entry.getLength()); + assertEquals(mTime, entry.getLastModified()); + } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java index a660a5292b..07387e4fa6 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java @@ -44,10 +44,10 @@ package org.eclipse.jgit.api; import static org.junit.Assert.assertTrue; -import java.io.IOException; import java.util.Set; import java.util.TreeSet; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.errors.NoWorkTreeException; import org.eclipse.jgit.lib.RepositoryTestCase; import org.junit.Before; @@ -75,7 +75,7 @@ public class CleanCommandTest extends RepositoryTestCase { } @Test - public void testClean() throws NoWorkTreeException, IOException { + public void testClean() throws NoWorkTreeException, GitAPIException { // create status StatusCommand command = git.status(); Status status = command.call(); @@ -94,7 +94,8 @@ public class CleanCommandTest extends RepositoryTestCase { } @Test - public void testCleanWithPaths() throws NoWorkTreeException, IOException { + public void testCleanWithPaths() throws NoWorkTreeException, + GitAPIException { // create status StatusCommand command = git.status(); Status status = command.call(); @@ -114,7 +115,8 @@ public class CleanCommandTest extends RepositoryTestCase { } @Test - public void testCleanWithDryRun() throws NoWorkTreeException, IOException { + public void testCleanWithDryRun() throws NoWorkTreeException, + GitAPIException { // create status StatusCommand command = git.status(); Status status = command.call(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java index 906a8966fa..4441ea9301 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java @@ -55,6 +55,7 @@ import java.util.List; import java.util.Map; import org.eclipse.jgit.api.ListBranchCommand.ListMode; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.lib.ConfigConstants; @@ -103,7 +104,8 @@ public class CloneCommandTest extends RepositoryTestCase { } @Test - public void testCloneRepository() throws IOException { + public void testCloneRepository() throws IOException, + JGitInternalException, GitAPIException { File directory = createTempDirectory("testCloneRepository"); CloneCommand command = Git.cloneRepository(); command.setDirectory(directory); @@ -131,7 +133,8 @@ public class CloneCommandTest extends RepositoryTestCase { } @Test - public void testCloneRepositoryWithBranch() throws IOException { + public void testCloneRepositoryWithBranch() throws IOException, + JGitInternalException, GitAPIException { File directory = createTempDirectory("testCloneRepositoryWithBranch"); CloneCommand command = Git.cloneRepository(); command.setBranch("refs/heads/master"); @@ -178,7 +181,8 @@ public class CloneCommandTest extends RepositoryTestCase { } @Test - public void testCloneRepositoryOnlyOneBranch() throws IOException { + public void testCloneRepositoryOnlyOneBranch() throws IOException, + JGitInternalException, GitAPIException { File directory = createTempDirectory("testCloneRepositoryWithBranch"); CloneCommand command = Git.cloneRepository(); command.setBranch("refs/heads/master"); @@ -222,7 +226,7 @@ public class CloneCommandTest extends RepositoryTestCase { @Test public void testCloneRepositoryWhenDestinationDirectoryExistsAndIsNotEmpty() - throws IOException { + throws IOException, JGitInternalException, GitAPIException { String dirName = "testCloneTargetDirectoryNotEmpty"; File directory = createTempDirectory(dirName); CloneCommand command = Git.cloneRepository(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java index e6b6a096fa..ed32e27b0a 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java @@ -50,15 +50,12 @@ import static org.junit.Assert.fail; import java.io.File; import java.io.IOException; import java.io.PrintWriter; -import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException; + +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.JGitInternalException; -import org.eclipse.jgit.api.errors.NoFilepatternException; -import org.eclipse.jgit.api.errors.NoHeadException; import org.eclipse.jgit.api.errors.NoMessageException; -import org.eclipse.jgit.api.errors.WrongRepositoryStateException; import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.MissingObjectException; -import org.eclipse.jgit.errors.UnmergedPathException; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.PersonIdent; @@ -77,9 +74,8 @@ import org.junit.Test; */ public class CommitAndLogCommandTests extends RepositoryTestCase { @Test - public void testSomeCommits() throws NoHeadException, NoMessageException, - ConcurrentRefUpdateException, JGitInternalException, - WrongRepositoryStateException, IOException { + public void testSomeCommits() throws JGitInternalException, IOException, + GitAPIException { // do 4 commits Git git = new Git(db); @@ -115,9 +111,8 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { } @Test - public void testLogWithFilter() throws IOException, NoFilepatternException, - NoHeadException, NoMessageException, ConcurrentRefUpdateException, - JGitInternalException, WrongRepositoryStateException { + public void testLogWithFilter() throws IOException, JGitInternalException, + GitAPIException { Git git = new Git(db); @@ -170,9 +165,7 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { // try to do a commit without specifying a message. Should fail! @Test - public void testWrongParams() throws UnmergedPathException, - NoHeadException, ConcurrentRefUpdateException, - JGitInternalException, WrongRepositoryStateException { + public void testWrongParams() throws GitAPIException { Git git = new Git(db); try { git.commit().setAuthor(author).call(); @@ -185,10 +178,7 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { // try to work with Commands after command has been invoked. Should throw // exceptions @Test - public void testMultipleInvocations() throws NoHeadException, - ConcurrentRefUpdateException, NoMessageException, - UnmergedPathException, JGitInternalException, - WrongRepositoryStateException { + public void testMultipleInvocations() throws GitAPIException { Git git = new Git(db); CommitCommand commitCmd = git.commit(); commitCmd.setMessage("initial commit").call(); @@ -211,9 +201,8 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { } @Test - public void testMergeEmptyBranches() throws IOException, NoHeadException, - NoMessageException, ConcurrentRefUpdateException, - JGitInternalException, WrongRepositoryStateException { + public void testMergeEmptyBranches() throws IOException, + JGitInternalException, GitAPIException { Git git = new Git(db); git.commit().setMessage("initial commit").call(); RefUpdate r = db.updateRef("refs/heads/side"); @@ -235,10 +224,8 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { } @Test - public void testAddUnstagedChanges() throws IOException, NoHeadException, - NoMessageException, ConcurrentRefUpdateException, - JGitInternalException, WrongRepositoryStateException, - NoFilepatternException { + public void testAddUnstagedChanges() throws IOException, + JGitInternalException, GitAPIException { File file = new File(db.getWorkTree(), "a.txt"); FileUtils.createNewFile(file); PrintWriter writer = new PrintWriter(file); @@ -268,9 +255,7 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { } @Test - public void testModeChange() throws IOException, NoFilepatternException, - NoHeadException, NoMessageException, ConcurrentRefUpdateException, - JGitInternalException, WrongRepositoryStateException { + public void testModeChange() throws IOException, GitAPIException { Git git = new Git(db); // create file @@ -298,10 +283,9 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { } @Test - public void testCommitRange() throws NoHeadException, NoMessageException, - UnmergedPathException, ConcurrentRefUpdateException, - JGitInternalException, WrongRepositoryStateException, - IncorrectObjectTypeException, MissingObjectException { + public void testCommitRange() throws GitAPIException, + JGitInternalException, MissingObjectException, + IncorrectObjectTypeException { // do 4 commits and set the range to the second and fourth one Git git = new Git(db); git.commit().setMessage("first commit").call(); @@ -334,9 +318,8 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { } @Test - public void testCommitAmend() throws NoHeadException, NoMessageException, - ConcurrentRefUpdateException, JGitInternalException, - WrongRepositoryStateException, IOException { + public void testCommitAmend() throws JGitInternalException, IOException, + GitAPIException { Git git = new Git(db); git.commit().setMessage("first comit").call(); // typo git.commit().setAmend(true).setMessage("first commit").call(); @@ -357,10 +340,8 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { } @Test - public void testInsertChangeId() throws NoHeadException, - NoMessageException, - UnmergedPathException, ConcurrentRefUpdateException, - JGitInternalException, WrongRepositoryStateException { + public void testInsertChangeId() throws JGitInternalException, + GitAPIException { Git git = new Git(db); String messageHeader = "Some header line\n\nSome detail explanation\n"; String changeIdTemplate = "\nChange-Id: I" diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java index b9f5882d50..3aec611f44 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java @@ -50,6 +50,7 @@ import java.io.File; import java.util.List; import org.eclipse.jgit.diff.DiffEntry; +import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.lib.ConfigConstants; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.FileMode; @@ -258,4 +259,110 @@ public class CommitCommandTest extends RepositoryTestCase { assertEquals(path, subDiff.getNewPath()); assertEquals(path, subDiff.getOldPath()); } + + @Test + public void commitUpdatesSmudgedEntries() throws Exception { + Git git = new Git(db); + + File file1 = writeTrashFile("file1.txt", "content1"); + assertTrue(file1.setLastModified(file1.lastModified() - 5000)); + File file2 = writeTrashFile("file2.txt", "content2"); + assertTrue(file2.setLastModified(file2.lastModified() - 5000)); + File file3 = writeTrashFile("file3.txt", "content3"); + assertTrue(file3.setLastModified(file3.lastModified() - 5000)); + + assertNotNull(git.add().addFilepattern("file1.txt") + .addFilepattern("file2.txt").addFilepattern("file3.txt").call()); + RevCommit commit = git.commit().setMessage("add files").call(); + assertNotNull(commit); + + DirCache cache = DirCache.read(db.getIndexFile(), db.getFS()); + int file1Size = cache.getEntry("file1.txt").getLength(); + int file2Size = cache.getEntry("file2.txt").getLength(); + int file3Size = cache.getEntry("file3.txt").getLength(); + ObjectId file2Id = cache.getEntry("file2.txt").getObjectId(); + ObjectId file3Id = cache.getEntry("file3.txt").getObjectId(); + assertTrue(file1Size > 0); + assertTrue(file2Size > 0); + assertTrue(file3Size > 0); + + // Smudge entries + cache = DirCache.lock(db.getIndexFile(), db.getFS()); + cache.getEntry("file1.txt").setLength(0); + cache.getEntry("file2.txt").setLength(0); + cache.getEntry("file3.txt").setLength(0); + cache.write(); + assertTrue(cache.commit()); + + // Verify entries smudged + cache = DirCache.read(db.getIndexFile(), db.getFS()); + assertEquals(0, cache.getEntry("file1.txt").getLength()); + assertEquals(0, cache.getEntry("file2.txt").getLength()); + assertEquals(0, cache.getEntry("file3.txt").getLength()); + + long indexTime = db.getIndexFile().lastModified(); + db.getIndexFile().setLastModified(indexTime - 5000); + + write(file1, "content4"); + assertTrue(file1.setLastModified(file1.lastModified() + 1000)); + assertNotNull(git.commit().setMessage("edit file").setOnly("file1.txt") + .call()); + + cache = db.readDirCache(); + assertEquals(file1Size, cache.getEntry("file1.txt").getLength()); + assertEquals(file2Size, cache.getEntry("file2.txt").getLength()); + assertEquals(file3Size, cache.getEntry("file3.txt").getLength()); + assertEquals(file2Id, cache.getEntry("file2.txt").getObjectId()); + assertEquals(file3Id, cache.getEntry("file3.txt").getObjectId()); + } + + @Test + public void commitIgnoresSmudgedEntryWithDifferentId() throws Exception { + Git git = new Git(db); + + File file1 = writeTrashFile("file1.txt", "content1"); + assertTrue(file1.setLastModified(file1.lastModified() - 5000)); + File file2 = writeTrashFile("file2.txt", "content2"); + assertTrue(file2.setLastModified(file2.lastModified() - 5000)); + + assertNotNull(git.add().addFilepattern("file1.txt") + .addFilepattern("file2.txt").call()); + RevCommit commit = git.commit().setMessage("add files").call(); + assertNotNull(commit); + + DirCache cache = DirCache.read(db.getIndexFile(), db.getFS()); + int file1Size = cache.getEntry("file1.txt").getLength(); + int file2Size = cache.getEntry("file2.txt").getLength(); + assertTrue(file1Size > 0); + assertTrue(file2Size > 0); + + writeTrashFile("file2.txt", "content3"); + assertNotNull(git.add().addFilepattern("file2.txt").call()); + writeTrashFile("file2.txt", "content4"); + + // Smudge entries + cache = DirCache.lock(db.getIndexFile(), db.getFS()); + cache.getEntry("file1.txt").setLength(0); + cache.getEntry("file2.txt").setLength(0); + cache.write(); + assertTrue(cache.commit()); + + // Verify entries smudged + cache = db.readDirCache(); + assertEquals(0, cache.getEntry("file1.txt").getLength()); + assertEquals(0, cache.getEntry("file2.txt").getLength()); + + long indexTime = db.getIndexFile().lastModified(); + db.getIndexFile().setLastModified(indexTime - 5000); + + write(file1, "content5"); + assertTrue(file1.setLastModified(file1.lastModified() + 1000)); + + assertNotNull(git.commit().setMessage("edit file").setOnly("file1.txt") + .call()); + + cache = db.readDirCache(); + assertEquals(file1Size, cache.getEntry("file1.txt").getLength()); + assertEquals(0, cache.getEntry("file2.txt").getLength()); + } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java index 8031769204..d8e1a058f7 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java @@ -48,6 +48,8 @@ import static org.junit.Assert.fail; import java.io.IOException; import org.eclipse.jgit.api.ListBranchCommand.ListMode; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.RepositoryTestCase; @@ -84,7 +86,7 @@ public class GitConstructionTest extends RepositoryTestCase { } @Test - public void testWrap() { + public void testWrap() throws JGitInternalException, GitAPIException { Git git = Git.wrap(db); assertEquals(1, git.branchList().call().size()); @@ -101,7 +103,8 @@ public class GitConstructionTest extends RepositoryTestCase { } @Test - public void testOpen() throws IOException { + public void testOpen() throws IOException, JGitInternalException, + GitAPIException { Git git = Git.open(db.getDirectory()); assertEquals(1, git.branchList().call().size()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java index 28236369e4..7db9ce71c1 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java @@ -48,6 +48,8 @@ import static org.junit.Assert.assertTrue; import java.io.File; import java.io.IOException; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.RepositoryTestCase; import org.junit.Before; @@ -62,7 +64,8 @@ public class InitCommandTest extends RepositoryTestCase { } @Test - public void testInitRepository() throws IOException { + public void testInitRepository() throws IOException, JGitInternalException, + GitAPIException { File directory = createTempDirectory("testInitRepository"); InitCommand command = new InitCommand(); command.setDirectory(directory); @@ -72,7 +75,8 @@ public class InitCommandTest extends RepositoryTestCase { } @Test - public void testInitNonEmptyRepository() throws IOException { + public void testInitNonEmptyRepository() throws IOException, + JGitInternalException, GitAPIException { File directory = createTempDirectory("testInitRepository2"); File someFile = new File(directory, "someFile"); someFile.createNewFile(); @@ -86,7 +90,8 @@ public class InitCommandTest extends RepositoryTestCase { } @Test - public void testInitBareRepository() throws IOException { + public void testInitBareRepository() throws IOException, + JGitInternalException, GitAPIException { File directory = createTempDirectory("testInitBareRepository"); InitCommand command = new InitCommand(); command.setDirectory(directory); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java index 648ef6f01b..cf2dead5a4 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java @@ -293,7 +293,8 @@ public class RebaseCommandTest extends RepositoryTestCase { // change third line in topic branch writeTrashFile(FILE1, "1\n2\n3\ntopic\n"); git.add().addFilepattern(FILE1).call(); - git.commit().setMessage("change file1 in topic").call(); + RevCommit origHead = git.commit().setMessage("change file1 in topic") + .call(); RebaseResult res = git.rebase().setUpstream("refs/heads/master").call(); assertEquals(Status.OK, res.getStatus()); @@ -302,6 +303,7 @@ public class RebaseCommandTest extends RepositoryTestCase { assertEquals("refs/heads/topic", db.getFullBranch()); assertEquals(lastMasterChange, new RevWalk(db).parseCommit( db.resolve(Constants.HEAD)).getParent(0)); + assertEquals(origHead, db.readOrigHead()); } @Test diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java index 27c3549be3..0806cf0dd0 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java @@ -54,12 +54,8 @@ import java.io.IOException; import java.io.PrintWriter; import org.eclipse.jgit.api.ResetCommand.ResetType; -import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.JGitInternalException; -import org.eclipse.jgit.api.errors.NoFilepatternException; -import org.eclipse.jgit.api.errors.NoHeadException; -import org.eclipse.jgit.api.errors.NoMessageException; -import org.eclipse.jgit.api.errors.WrongRepositoryStateException; import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCacheEntry; import org.eclipse.jgit.errors.AmbiguousObjectException; @@ -87,9 +83,8 @@ public class ResetCommandTest extends RepositoryTestCase { private DirCacheEntry prestage; - public void setupRepository() throws IOException, NoFilepatternException, - NoHeadException, NoMessageException, ConcurrentRefUpdateException, - JGitInternalException, WrongRepositoryStateException { + public void setupRepository() throws IOException, JGitInternalException, + GitAPIException { // create initial commit git = new Git(db); @@ -138,9 +133,7 @@ public class ResetCommandTest extends RepositoryTestCase { @Test public void testHardReset() throws JGitInternalException, - AmbiguousObjectException, IOException, NoFilepatternException, - NoHeadException, NoMessageException, ConcurrentRefUpdateException, - WrongRepositoryStateException { + AmbiguousObjectException, IOException, GitAPIException { setupRepository(); ObjectId prevHead = db.resolve(Constants.HEAD); git.reset().setMode(ResetType.HARD).setRef(initialCommit.getName()) @@ -156,11 +149,12 @@ public class ResetCommandTest extends RepositoryTestCase { assertFalse(inHead(fileInIndexPath)); assertFalse(inIndex(indexFile.getName())); assertReflog(prevHead, head); + assertEquals(prevHead, db.readOrigHead()); } @Test public void testResetToNonexistingHEAD() throws JGitInternalException, - AmbiguousObjectException, IOException { + AmbiguousObjectException, IOException, GitAPIException { // create a file in the working tree of a fresh repo git = new Git(db); @@ -176,9 +170,7 @@ public class ResetCommandTest extends RepositoryTestCase { @Test public void testSoftReset() throws JGitInternalException, - AmbiguousObjectException, IOException, NoFilepatternException, - NoHeadException, NoMessageException, ConcurrentRefUpdateException, - WrongRepositoryStateException { + AmbiguousObjectException, IOException, GitAPIException { setupRepository(); ObjectId prevHead = db.resolve(Constants.HEAD); git.reset().setMode(ResetType.SOFT).setRef(initialCommit.getName()) @@ -194,13 +186,12 @@ public class ResetCommandTest extends RepositoryTestCase { assertFalse(inHead(fileInIndexPath)); assertTrue(inIndex(indexFile.getName())); assertReflog(prevHead, head); + assertEquals(prevHead, db.readOrigHead()); } @Test public void testMixedReset() throws JGitInternalException, - AmbiguousObjectException, IOException, NoFilepatternException, - NoHeadException, NoMessageException, ConcurrentRefUpdateException, - WrongRepositoryStateException { + AmbiguousObjectException, IOException, GitAPIException { setupRepository(); ObjectId prevHead = db.resolve(Constants.HEAD); git.reset().setMode(ResetType.MIXED).setRef(initialCommit.getName()) @@ -217,6 +208,49 @@ public class ResetCommandTest extends RepositoryTestCase { assertFalse(inIndex(indexFile.getName())); assertReflog(prevHead, head); + assertEquals(prevHead, db.readOrigHead()); + } + + @Test + public void testMixedResetRetainsSizeAndModifiedTime() throws Exception { + git = new Git(db); + + writeTrashFile("a.txt", "a").setLastModified( + System.currentTimeMillis() - 60 * 1000); + assertNotNull(git.add().addFilepattern("a.txt").call()); + assertNotNull(git.commit().setMessage("a commit").call()); + + writeTrashFile("b.txt", "b").setLastModified( + System.currentTimeMillis() - 60 * 1000); + assertNotNull(git.add().addFilepattern("b.txt").call()); + RevCommit commit2 = git.commit().setMessage("b commit").call(); + assertNotNull(commit2); + + DirCache cache = db.readDirCache(); + + DirCacheEntry aEntry = cache.getEntry("a.txt"); + assertNotNull(aEntry); + assertTrue(aEntry.getLength() > 0); + assertTrue(aEntry.getLastModified() > 0); + + DirCacheEntry bEntry = cache.getEntry("b.txt"); + assertNotNull(bEntry); + assertTrue(bEntry.getLength() > 0); + assertTrue(bEntry.getLastModified() > 0); + + git.reset().setMode(ResetType.MIXED).setRef(commit2.getName()).call(); + + cache = db.readDirCache(); + + DirCacheEntry mixedAEntry = cache.getEntry("a.txt"); + assertNotNull(mixedAEntry); + assertEquals(aEntry.getLastModified(), mixedAEntry.getLastModified()); + assertEquals(aEntry.getLastModified(), mixedAEntry.getLastModified()); + + DirCacheEntry mixedBEntry = cache.getEntry("b.txt"); + assertNotNull(mixedBEntry); + assertEquals(bEntry.getLastModified(), mixedBEntry.getLastModified()); + assertEquals(bEntry.getLastModified(), mixedBEntry.getLastModified()); } @Test diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RmCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RmCommandTest.java index d826b4c135..2eb4f22940 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RmCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RmCommandTest.java @@ -46,8 +46,8 @@ import static org.junit.Assert.assertEquals; import java.io.IOException; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.JGitInternalException; -import org.eclipse.jgit.api.errors.NoFilepatternException; import org.eclipse.jgit.lib.RepositoryTestCase; import org.junit.Before; import org.junit.Test; @@ -71,7 +71,7 @@ public class RmCommandTest extends RepositoryTestCase { @Test public void testRemove() throws JGitInternalException, - NoFilepatternException, IllegalStateException, IOException { + IllegalStateException, IOException, GitAPIException { assertEquals("[test.txt, mode:100644, content:Hello world]", indexState(CONTENT)); RmCommand command = git.rm(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java index faca7ea3ab..c9a6048695 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java @@ -52,13 +52,15 @@ import java.util.Set; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.NoFilepatternException; +import org.eclipse.jgit.errors.NoWorkTreeException; import org.eclipse.jgit.lib.RepositoryTestCase; import org.junit.Test; public class StatusCommandTest extends RepositoryTestCase { @Test - public void testEmptyStatus() throws IOException { + public void testEmptyStatus() throws NoWorkTreeException, + GitAPIException { Git git = new Git(db); Status stat = git.status().call(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java index 7f381e3932..b417b44851 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java @@ -48,15 +48,9 @@ import static org.junit.Assert.fail; import java.io.IOException; import java.util.List; -import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.InvalidTagNameException; import org.eclipse.jgit.api.errors.JGitInternalException; -import org.eclipse.jgit.api.errors.NoHeadException; -import org.eclipse.jgit.api.errors.NoMessageException; -import org.eclipse.jgit.api.errors.WrongRepositoryStateException; -import org.eclipse.jgit.errors.IncorrectObjectTypeException; -import org.eclipse.jgit.errors.MissingObjectException; -import org.eclipse.jgit.errors.UnmergedPathException; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.RepositoryTestCase; @@ -67,10 +61,7 @@ import org.junit.Test; public class TagCommandTest extends RepositoryTestCase { @Test - public void testTaggingOnHead() throws NoHeadException, NoMessageException, - ConcurrentRefUpdateException, JGitInternalException, - WrongRepositoryStateException, InvalidTagNameException, - MissingObjectException, IncorrectObjectTypeException, IOException { + public void testTaggingOnHead() throws GitAPIException, IOException { Git git = new Git(db); RevCommit commit = git.commit().setMessage("initial commit").call(); Ref tagRef = git.tag().setName("tag").call(); @@ -80,10 +71,7 @@ public class TagCommandTest extends RepositoryTestCase { } @Test - public void testTagging() throws NoHeadException, NoMessageException, - UnmergedPathException, ConcurrentRefUpdateException, - JGitInternalException, WrongRepositoryStateException, - InvalidTagNameException { + public void testTagging() throws GitAPIException, JGitInternalException { Git git = new Git(db); git.commit().setMessage("initial commit").call(); RevCommit commit = git.commit().setMessage("second commit").call(); @@ -93,9 +81,7 @@ public class TagCommandTest extends RepositoryTestCase { } @Test - public void testEmptyTagName() throws NoHeadException, NoMessageException, - UnmergedPathException, ConcurrentRefUpdateException, - JGitInternalException, WrongRepositoryStateException { + public void testEmptyTagName() throws GitAPIException { Git git = new Git(db); git.commit().setMessage("initial commit").call(); try { @@ -108,10 +94,7 @@ public class TagCommandTest extends RepositoryTestCase { } @Test - public void testInvalidTagName() throws NoHeadException, - NoMessageException, UnmergedPathException, - ConcurrentRefUpdateException, JGitInternalException, - WrongRepositoryStateException { + public void testInvalidTagName() throws GitAPIException { Git git = new Git(db); git.commit().setMessage("initial commit").call(); try { @@ -123,10 +106,7 @@ public class TagCommandTest extends RepositoryTestCase { } @Test - public void testFailureOnSignedTags() throws NoHeadException, - NoMessageException, UnmergedPathException, - ConcurrentRefUpdateException, JGitInternalException, - WrongRepositoryStateException, InvalidTagNameException { + public void testFailureOnSignedTags() throws GitAPIException { Git git = new Git(db); git.commit().setMessage("initial commit").call(); try { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java index 65d0418b33..fb9cc2cbfc 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java @@ -46,14 +46,8 @@ import java.io.IOException; import java.util.Arrays; import org.eclipse.jgit.api.Git; -import org.eclipse.jgit.api.errors.CheckoutConflictException; -import org.eclipse.jgit.api.errors.InvalidRefNameException; -import org.eclipse.jgit.api.errors.JGitInternalException; -import org.eclipse.jgit.api.errors.RefAlreadyExistsException; -import org.eclipse.jgit.api.errors.RefNotFoundException; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.dircache.InvalidPathException; -import org.eclipse.jgit.errors.IncorrectObjectTypeException; -import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.junit.MockSystemReader; import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.util.SystemReader; @@ -338,20 +332,11 @@ public class DirCacheCheckoutMaliciousPathTest extends RepositoryTestCase { * perform the actual test on the second checkout * @param path * to the blob, one or more levels + * @throws GitAPIException * @throws IOException - * @throws RefAlreadyExistsException - * @throws RefNotFoundException - * @throws InvalidRefNameException - * @throws MissingObjectException - * @throws IncorrectObjectTypeException - * @throws CheckoutConflictException - * @throws JGitInternalException */ - private void testMaliciousPath(boolean good, boolean secondCheckout, String... path) - throws IOException, RefAlreadyExistsException, - RefNotFoundException, InvalidRefNameException, - MissingObjectException, IncorrectObjectTypeException, - JGitInternalException, CheckoutConflictException { + private void testMaliciousPath(boolean good, boolean secondCheckout, + String... path) throws GitAPIException, IOException { Git git = new Git(db); ObjectInserter newObjectInserter; newObjectInserter = git.getRepository().newObjectInserter(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java index b7caecc2c2..dde32d7e9f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java @@ -59,7 +59,7 @@ import java.util.TreeSet; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.MergeResult; import org.eclipse.jgit.api.MergeResult.MergeStatus; -import org.eclipse.jgit.api.errors.NoFilepatternException; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCacheEditor; import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit; @@ -139,7 +139,7 @@ public class IndexDiffTest extends RepositoryTestCase { } @Test - public void testModified() throws IOException, NoFilepatternException { + public void testModified() throws IOException, GitAPIException { writeTrashFile("file2", "file2"); writeTrashFile("dir/file3", "dir/file3"); @@ -291,8 +291,7 @@ public class IndexDiffTest extends RepositoryTestCase { } @Test - public void testUnchangedSimple() throws IOException, - NoFilepatternException { + public void testUnchangedSimple() throws IOException, GitAPIException { writeTrashFile("a.b", "a.b"); writeTrashFile("a.c", "a.c"); writeTrashFile("a=c", "a=c"); @@ -328,11 +327,10 @@ public class IndexDiffTest extends RepositoryTestCase { * used by Git. * * @throws IOException - * @throws NoFilepatternException + * @throws GitAPIException */ @Test - public void testUnchangedComplex() throws IOException, - NoFilepatternException { + public void testUnchangedComplex() throws IOException, GitAPIException { Git git = new Git(db); writeTrashFile("a.b", "a.b"); writeTrashFile("a.c", "a.c"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitListTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitListTest.java new file mode 100644 index 0000000000..5cbd8ebe18 --- /dev/null +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitListTest.java @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2012, Matthias Sohn <matthias.sohn@sap.com> + * and other copyright owners as documented in the project's IP log. + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Distribution License v1.0 which + * accompanies this distribution, is reproduced below, and is + * available at http://www.eclipse.org/org/documents/edl-v10.php + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * - Neither the name of the Eclipse Foundation, Inc. nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.eclipse.jgit.revwalk; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.RepositoryTestCase; +import org.junit.Test; + +public class RevCommitListTest extends RepositoryTestCase { + + private RevCommitList<RevCommit> list; + + public void setup(int count) throws Exception { + Git git = new Git(db); + for (int i = 0; i < count; i++) + git.commit().setCommitter(committer).setAuthor(author) + .setMessage("commit " + i).call(); + list = new RevCommitList<RevCommit>(); + RevWalk w = new RevWalk(db); + w.markStart(w.lookupCommit(db.resolve(Constants.HEAD))); + list.source(w); + } + + @Test + public void testFillToHighMark2() throws Exception { + setup(3); + list.fillTo(1); + assertEquals(2, list.size()); + assertEquals("commit 2", list.get(0).getFullMessage()); + assertEquals("commit 1", list.get(1).getFullMessage()); + assertNull("commit 0 shouldn't be loaded", list.get(2)); + } + + @Test + public void testFillToHighMarkAll() throws Exception { + setup(3); + list.fillTo(2); + assertEquals(3, list.size()); + assertEquals("commit 2", list.get(0).getFullMessage()); + assertEquals("commit 0", list.get(2).getFullMessage()); + } + + @Test + public void testFillToHighMark4() throws Exception { + setup(3); + list.fillTo(3); + assertEquals(3, list.size()); + assertEquals("commit 2", list.get(0).getFullMessage()); + assertEquals("commit 0", list.get(2).getFullMessage()); + assertNull("commit 3 can't be loaded", list.get(3)); + } + + @Test + public void testFillToHighMarkMulitpleBlocks() throws Exception { + setup(258); + list.fillTo(257); + assertEquals(258, list.size()); + } + + @Test + public void testFillToCommit() throws Exception { + setup(3); + + RevWalk w = new RevWalk(db); + w.markStart(w.lookupCommit(db.resolve(Constants.HEAD))); + + w.next(); + RevCommit c = w.next(); + assertNotNull("should have found 2. commit", c); + + list.fillTo(c, 5); + assertEquals(2, list.size()); + assertEquals("commit 1", list.get(1).getFullMessage()); + assertNull(list.get(3)); + } + + @Test + public void testFillToUnknownCommit() throws Exception { + setup(258); + RevCommit c = new RevCommit( + ObjectId.fromString("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); + + list.fillTo(c, 300); + assertEquals("loading to unknown commit should load all commits", 258, + list.size()); + } + + @Test + public void testFillToNullCommit() throws Exception { + setup(3); + list.fillTo(null, 1); + assertNull(list.get(0)); + } +} diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java index 568cd9e2bc..940a78ac4f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java @@ -53,6 +53,7 @@ import java.text.MessageFormat; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Status; import org.eclipse.jgit.api.SubmoduleAddCommand; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCacheEditor; @@ -75,7 +76,7 @@ import org.junit.Test; public class SubmoduleAddTest extends RepositoryTestCase { @Test - public void commandWithNullPath() { + public void commandWithNullPath() throws GitAPIException { try { new SubmoduleAddCommand(db).setURI("uri").call(); fail("Exception not thrown"); @@ -85,7 +86,7 @@ public class SubmoduleAddTest extends RepositoryTestCase { } @Test - public void commandWithEmptyPath() { + public void commandWithEmptyPath() throws GitAPIException { try { new SubmoduleAddCommand(db).setPath("").setURI("uri").call(); fail("Exception not thrown"); @@ -95,7 +96,7 @@ public class SubmoduleAddTest extends RepositoryTestCase { } @Test - public void commandWithNullUri() { + public void commandWithNullUri() throws GitAPIException { try { new SubmoduleAddCommand(db).setPath("sub").call(); fail("Exception not thrown"); @@ -105,7 +106,7 @@ public class SubmoduleAddTest extends RepositoryTestCase { } @Test - public void commandWithEmptyUri() { + public void commandWithEmptyUri() throws GitAPIException { try { new SubmoduleAddCommand(db).setPath("sub").setURI("").call(); fail("Exception not thrown"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleInitTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleInitTest.java index f0a0750c5c..424ad01fcb 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleInitTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleInitTest.java @@ -53,6 +53,7 @@ import java.io.IOException; import java.util.Collection; import org.eclipse.jgit.api.SubmoduleInitCommand; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCacheEditor; @@ -73,7 +74,7 @@ import org.junit.Test; public class SubmoduleInitTest extends RepositoryTestCase { @Test - public void repositoryWithNoSubmodules() { + public void repositoryWithNoSubmodules() throws GitAPIException { SubmoduleInitCommand command = new SubmoduleInitCommand(db); Collection<String> modules = command.call(); assertNotNull(modules); @@ -82,7 +83,7 @@ public class SubmoduleInitTest extends RepositoryTestCase { @Test public void repositoryWithUninitializedModule() throws IOException, - ConfigInvalidException { + ConfigInvalidException, GitAPIException { final String path = addSubmoduleToIndex(); SubmoduleWalk generator = SubmoduleWalk.forIndex(db); @@ -156,7 +157,7 @@ public class SubmoduleInitTest extends RepositoryTestCase { @Test public void resolveOneLevelHigherRelativeUrl() throws IOException, - ConfigInvalidException { + ConfigInvalidException, GitAPIException { final String path = addSubmoduleToIndex(); String base = "git://server/repo.git"; @@ -197,7 +198,7 @@ public class SubmoduleInitTest extends RepositoryTestCase { @Test public void resolveTwoLevelHigherRelativeUrl() throws IOException, - ConfigInvalidException { + ConfigInvalidException, GitAPIException { final String path = addSubmoduleToIndex(); String base = "git://server/repo.git"; @@ -238,7 +239,7 @@ public class SubmoduleInitTest extends RepositoryTestCase { @Test public void resolveWorkingDirectoryRelativeUrl() throws IOException, - ConfigInvalidException { + GitAPIException, ConfigInvalidException { final String path = addSubmoduleToIndex(); String base = db.getWorkTree().getAbsolutePath(); @@ -281,7 +282,7 @@ public class SubmoduleInitTest extends RepositoryTestCase { @Test public void resolveInvalidParentUrl() throws IOException, - ConfigInvalidException { + ConfigInvalidException, GitAPIException { final String path = addSubmoduleToIndex(); String base = "no_slash"; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleStatusTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleStatusTest.java index dc79d84259..6feefdb2d1 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleStatusTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleStatusTest.java @@ -53,6 +53,7 @@ import java.util.Map.Entry; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.SubmoduleStatusCommand; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCacheEditor; import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit; @@ -74,7 +75,7 @@ import org.junit.Test; public class SubmoduleStatusTest extends RepositoryTestCase { @Test - public void repositoryWithNoSubmodules() { + public void repositoryWithNoSubmodules() throws GitAPIException { SubmoduleStatusCommand command = new SubmoduleStatusCommand(db); Map<String, SubmoduleStatus> statuses = command.call(); assertNotNull(statuses); @@ -82,7 +83,8 @@ public class SubmoduleStatusTest extends RepositoryTestCase { } @Test - public void repositoryWithMissingSubmodule() throws IOException { + public void repositoryWithMissingSubmodule() throws IOException, + GitAPIException { final ObjectId id = ObjectId .fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); final String path = "sub"; @@ -113,7 +115,8 @@ public class SubmoduleStatusTest extends RepositoryTestCase { } @Test - public void repositoryWithUninitializedSubmodule() throws IOException { + public void repositoryWithUninitializedSubmodule() throws IOException, + GitAPIException { final ObjectId id = ObjectId .fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); final String path = "sub"; @@ -152,7 +155,8 @@ public class SubmoduleStatusTest extends RepositoryTestCase { } @Test - public void repositoryWithNoHeadInSubmodule() throws IOException { + public void repositoryWithNoHeadInSubmodule() throws IOException, + GitAPIException { final ObjectId id = ObjectId .fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); final String path = "sub"; @@ -202,7 +206,8 @@ public class SubmoduleStatusTest extends RepositoryTestCase { } @Test - public void repositoryWithNoSubmoduleRepository() throws IOException { + public void repositoryWithNoSubmoduleRepository() throws IOException, + GitAPIException { final ObjectId id = ObjectId .fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); final String path = "sub"; @@ -247,7 +252,8 @@ public class SubmoduleStatusTest extends RepositoryTestCase { } @Test - public void repositoryWithInitializedSubmodule() throws IOException { + public void repositoryWithInitializedSubmodule() throws IOException, + GitAPIException { final ObjectId id = ObjectId .fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); final String path = "sub"; @@ -302,7 +308,7 @@ public class SubmoduleStatusTest extends RepositoryTestCase { @Test public void repositoryWithDifferentRevCheckedOutSubmodule() - throws IOException { + throws IOException, GitAPIException { final ObjectId id = ObjectId .fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); final String path = "sub"; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleSyncTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleSyncTest.java index 4df9077ba0..3f9ad11f1d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleSyncTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleSyncTest.java @@ -53,6 +53,7 @@ import java.util.Map.Entry; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.SubmoduleSyncCommand; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCacheEditor; import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit; @@ -73,7 +74,7 @@ import org.junit.Test; public class SubmoduleSyncTest extends RepositoryTestCase { @Test - public void repositoryWithNoSubmodules() { + public void repositoryWithNoSubmodules() throws GitAPIException { SubmoduleSyncCommand command = new SubmoduleSyncCommand(db); Map<String, String> modules = command.call(); assertNotNull(modules); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleUpdateTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleUpdateTest.java index 9bb4a63aab..eb0cf2b0b6 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleUpdateTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleUpdateTest.java @@ -52,6 +52,7 @@ import java.util.Collection; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.SubmoduleUpdateCommand; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCacheEditor; import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit; @@ -73,7 +74,7 @@ import org.junit.Test; public class SubmoduleUpdateTest extends RepositoryTestCase { @Test - public void repositoryWithNoSubmodules() { + public void repositoryWithNoSubmodules() throws GitAPIException { SubmoduleUpdateCommand command = new SubmoduleUpdateCommand(db); Collection<String> modules = command.call(); assertNotNull(modules); @@ -125,7 +126,8 @@ public class SubmoduleUpdateTest extends RepositoryTestCase { } @Test - public void repositoryWithUnconfiguredSubmodule() throws IOException { + public void repositoryWithUnconfiguredSubmodule() throws IOException, + GitAPIException { final ObjectId id = ObjectId .fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); final String path = "sub"; @@ -159,7 +161,8 @@ public class SubmoduleUpdateTest extends RepositoryTestCase { } @Test - public void repositoryWithInitializedSubmodule() throws IOException { + public void repositoryWithInitializedSubmodule() throws IOException, + GitAPIException { final ObjectId id = ObjectId .fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); final String path = "sub"; |