Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Muskalla2010-08-25 09:48:14 -0400
committerChris Aniszczyk2010-08-25 19:30:21 -0400
commit70ff817ab96a5da9b814c08d0cccb05750ba6c6c (patch)
tree3c00e19f9a03d9e078673ee1760fc6f3458ebc29 /org.eclipse.egit.core.test
parent0f65928171227869936e05703709ec00e7ef3f89 (diff)
downloadegit-70ff817ab96a5da9b814c08d0cccb05750ba6c6c.tar.gz
egit-70ff817ab96a5da9b814c08d0cccb05750ba6c6c.tar.xz
egit-70ff817ab96a5da9b814c08d0cccb05750ba6c6c.zip
Cleanup of HistoryTest and IndexFileRevision
Fixed several warnings, added testcase for the IndexFileRevision and rewrote test setup to use porcelain API instead of the plumbing stuff. Change-Id: Ia568de2231e12f62f8415ca32c8aba5c89abf7b5 Signed-off-by: Benjamin Muskalla <bmuskalla@eclipsesource.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
Diffstat (limited to 'org.eclipse.egit.core.test')
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/internal/mapping/HistoryTest.java120
1 files changed, 47 insertions, 73 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/internal/mapping/HistoryTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/internal/mapping/HistoryTest.java
index 155d150d1..da573a3b0 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/internal/mapping/HistoryTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/internal/mapping/HistoryTest.java
@@ -14,25 +14,20 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;
import java.util.TimeZone;
+import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.egit.core.GitProvider;
+import org.eclipse.egit.core.internal.storage.GitFileRevision;
import org.eclipse.egit.core.op.ConnectProviderOperation;
import org.eclipse.egit.core.test.GitTestCase;
-import org.eclipse.jgit.lib.CommitBuilder;
-import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.lib.FileTreeEntry;
-import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.ObjectInserter;
+import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.PersonIdent;
-import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.lib.Tree;
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.team.core.RepositoryProvider;
import org.eclipse.team.core.history.IFileHistory;
@@ -48,69 +43,37 @@ public class HistoryTest extends GitTestCase {
protected static final PersonIdent jcommitter;
static {
- jauthor = new PersonIdent("J. Author", "jauthor@example.com");
- jcommitter = new PersonIdent("J. Committer", "jcommitter@example.com");
+ jauthor = new PersonIdent("J. Author", "jauthor@example.com",
+ new Date(0L), TimeZone.getTimeZone("GMT+1"));
+ jcommitter = new PersonIdent("J. Committer", "jcommitter@example.com",
+ new Date(0L), TimeZone.getTimeZone("GMT+1"));
}
private File workDir;
- private File gitDir;
private Repository thisGit;
- private Tree tree;
- private ObjectInserter inserter;
@Before
public void setUp() throws Exception {
super.setUp();
- project.createSourceFolder();
- gitDir = new File(project.getProject().getWorkspace().getRoot()
- .getRawLocation().toFile(), Constants.DOT_GIT);
+ // ensure we are working on an empty repository
+ testUtils.deleteRecursive(gitDir);
thisGit = new FileRepository(gitDir);
workDir = thisGit.getWorkTree();
thisGit.create();
- inserter = thisGit.newObjectInserter();
-
- tree = new Tree(thisGit);
- Tree projectTree = tree.addTree("Project-1");
- File project1_a_txt = createFile("Project-1/A.txt","A.txt - first version\n");
- addFile(projectTree,project1_a_txt);
- projectTree.setId(inserter.insert(Constants.OBJ_TREE, projectTree.format()));
- File project1_b_txt = createFile("Project-1/B.txt","B.txt - first version\n");
- addFile(projectTree,project1_b_txt);
- projectTree.setId(inserter.insert(Constants.OBJ_TREE, projectTree.format()));
- tree.setId(inserter.insert(Constants.OBJ_TREE, tree.format()));
- CommitBuilder commit = new CommitBuilder();
- commit.setAuthor(new PersonIdent(jauthor, new Date(0L), TimeZone
- .getTimeZone("GMT+1")));
- commit.setCommitter(new PersonIdent(jcommitter, new Date(0L), TimeZone
- .getTimeZone("GMT+1")));
- commit.setMessage("Foo\n\nMessage");
- commit.setTreeId(tree.getTreeId());
- ObjectId commitId = inserter.insert(commit);
-
- tree = new Tree(thisGit);
- projectTree = tree.addTree("Project-1");
- addFile(projectTree,project1_a_txt);
-
- File project1_b_v2_txt = createFile("Project-1/B.txt","B.txt - second version\n");
- addFile(projectTree,project1_b_v2_txt);
- projectTree.setId(inserter.insert(Constants.OBJ_TREE, projectTree.format()));
- tree.setId(inserter.insert(Constants.OBJ_TREE, tree.format()));
- commit = new CommitBuilder();
- commit.setAuthor(new PersonIdent(jauthor, new Date(0L), TimeZone
- .getTimeZone("GMT+1")));
- commit.setCommitter(new PersonIdent(jcommitter, new Date(0L), TimeZone
- .getTimeZone("GMT+1")));
- commit.setMessage("Modified");
- commit.setParentId(commitId);
- commit.setTreeId(tree.getTreeId());
- commitId = inserter.insert(commit);
- inserter.flush();
-
- RefUpdate lck = thisGit.updateRef("refs/heads/master");
- assertNotNull("obtained lock", lck);
- lck.setNewObjectId(commitId);
- assertEquals(RefUpdate.Result.NEW, lck.forceUpdate());
+
+ Git git = new Git(thisGit);
+
+ createFile("Project-1/A.txt","A.txt - first version\n");
+ createFile("Project-1/B.txt","B.txt - first version\n");
+ git.add().addFilepattern("Project-1/A.txt").addFilepattern("Project-1/B.txt").call();
+ git.commit().setAuthor(jauthor).setCommitter(jcommitter)
+ .setMessage("Foo\n\nMessage").call();
+
+ createFile("Project-1/B.txt","B.txt - second version\n");
+ git.add().addFilepattern("Project-1/B.txt").call();
+ git.commit().setAuthor(jauthor).setCommitter(jcommitter)
+ .setMessage("Modified").call();
ConnectProviderOperation operation = new ConnectProviderOperation(
project.getProject(), gitDir);
@@ -119,23 +82,9 @@ public class HistoryTest extends GitTestCase {
@Override
public void tearDown() throws Exception {
- if (inserter != null) {
- inserter.release();
- }
super.tearDown();
}
- private void addFile(Tree t,File f) throws IOException {
- ObjectId id;
- FileInputStream in = new FileInputStream(f);
- try {
- id = inserter.insert(Constants.OBJ_BLOB, in.getChannel().size(), in);
- } finally {
- in.close();
- }
- t.addEntry(new FileTreeEntry(t,id,f.getName().getBytes("UTF-8"),false));
- }
-
private File createFile(String name, String content) throws IOException {
File f = new File(workDir, name);
FileWriter fileWriter = new FileWriter(f);
@@ -177,6 +126,31 @@ public class HistoryTest extends GitTestCase {
}
@Test
+ public void testIndexRevision() throws Exception {
+ GitProvider provider = (GitProvider)RepositoryProvider.getProvider(project.project);
+ assertNotNull(provider);
+ IFileHistoryProvider fileHistoryProvider = provider.getFileHistoryProvider();
+ IFileHistory fileHistory = fileHistoryProvider.getFileHistoryFor(project.getProject().getWorkspace().getRoot().findMember("Project-1/A.txt"), IFileHistoryProvider.SINGLE_LINE_OF_DESCENT, new NullProgressMonitor());
+ IFileRevision fileRevision = fileHistory.getFileRevision(GitFileRevision.INDEX);
+ assertEquals(GitFileRevision.INDEX, fileRevision.getContentIdentifier());
+ IStorage storage = fileRevision.getStorage(null);
+ String content = testUtils.slurpAndClose(storage.getContents());
+ assertEquals("A.txt - first version\n", content);
+ }
+
+ @Test
+ public void testIndexRevisionSecondCommit() throws Exception {
+ GitProvider provider = (GitProvider)RepositoryProvider.getProvider(project.project);
+ assertNotNull(provider);
+ IFileHistoryProvider fileHistoryProvider = provider.getFileHistoryProvider();
+ IFileHistory fileHistory = fileHistoryProvider.getFileHistoryFor(project.getProject().getWorkspace().getRoot().findMember("Project-1/B.txt"), IFileHistoryProvider.SINGLE_LINE_OF_DESCENT, new NullProgressMonitor());
+ IFileRevision fileRevision = fileHistory.getFileRevision(GitFileRevision.INDEX);
+ assertEquals(GitFileRevision.INDEX, fileRevision.getContentIdentifier());
+ IStorage storage = fileRevision.getStorage(null);
+ String content = testUtils.slurpAndClose(storage.getContents());
+ assertEquals("B.txt - second version\n", content);
+ }
+ @Test
public void testShallowHistory() {
GitProvider provider = (GitProvider)RepositoryProvider.getProvider(project.project);
assertNotNull(provider);

Back to the top