Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathias Kinzler2010-12-01 09:29:28 -0500
committerMathias Kinzler2010-12-01 09:29:39 -0500
commit2923472cbb95257f7e973e01915956b2ecb20462 (patch)
tree8c183567ebb308de45db4fd7cab7919a10065c1a /org.eclipse.egit.core.test/src
parent82e78f3461917c8a88070eae4a09614e97bb1c88 (diff)
downloadegit-2923472cbb95257f7e973e01915956b2ecb20462.tar.gz
egit-2923472cbb95257f7e973e01915956b2ecb20462.tar.xz
egit-2923472cbb95257f7e973e01915956b2ecb20462.zip
Remove deprecated JGit code from EGit Core Tests
Change-Id: Ia168e795a93261d3d2da161f76200ba7a0ab7924 Signed-off-by: Mathias Kinzler <mathias.kinzler@sap.com>
Diffstat (limited to 'org.eclipse.egit.core.test/src')
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestRepository.java56
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ConnectProviderOperationTest.java58
2 files changed, 46 insertions, 68 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestRepository.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestRepository.java
index a420986e1..cf5e202be 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestRepository.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestRepository.java
@@ -1,4 +1,5 @@
/*******************************************************************************
+ * Copyright (C) 2011, Mathias Kinzler <mathias.kinzler@sap.com>
* Copyright (C) 2010, Jens Baumgart <jens.baumgart@sap.com>
*
* All rights reserved. This program and the accompanying materials
@@ -8,8 +9,6 @@
*******************************************************************************/
package org.eclipse.egit.core.test;
-import static org.junit.Assert.assertNotNull;
-
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
@@ -20,6 +19,7 @@ import java.util.regex.Pattern;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Path;
import org.eclipse.egit.core.op.BranchOperation;
import org.eclipse.egit.core.op.ConnectProviderOperation;
import org.eclipse.egit.core.op.DisconnectProviderOperation;
@@ -27,21 +27,21 @@ import org.eclipse.jgit.api.CommitCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException;
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.errors.UnmergedPathException;
import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.lib.GitIndex;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.lib.Tree;
-import org.eclipse.jgit.lib.GitIndex.Entry;
import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.storage.file.FileRepository;
+import org.eclipse.jgit.treewalk.TreeWalk;
/**
* Helper class for creating and filling a test repository
@@ -228,10 +228,13 @@ public class TestRepository {
* @throws IOException
*/
public void track(File file) throws IOException {
- GitIndex index = repository.getIndex();
- Entry entry = index.add(repository.getWorkTree(), file);
- entry.setAssumeValid(false);
- index.write();
+ String repoPath = getRepoRelativePath(new Path(file.getPath())
+ .toString());
+ try {
+ new Git(repository).add().addFilepattern(repoPath).call();
+ } catch (NoFilepatternException e) {
+ throw new IOException(e.getMessage());
+ }
}
/**
@@ -301,16 +304,16 @@ public class TestRepository {
* Adds the given file to the index
*
* @param file
+ * @throws CoreException
* @throws IOException
*/
- public void addToIndex(IFile file) throws IOException {
- GitIndex index = repository.getIndex();
- Entry entry = index.getEntry(getRepoRelativePath(file.getLocation()
- .toOSString()));
- assertNotNull(entry);
- if (entry.isModified(repository.getWorkTree()))
- entry.update(new File(repository.getWorkTree(), entry.getName()));
- index.write();
+ public void addToIndex(IFile file) throws CoreException, IOException {
+ String repoPath = getRepoRelativePath(file.getLocation().toOSString());
+ try {
+ new Git(repository).add().addFilepattern(repoPath).call();
+ } catch (NoFilepatternException e) {
+ throw new IOException(e.getMessage());
+ }
}
/**
@@ -375,16 +378,21 @@ public class TestRepository {
* @throws IOException
*/
public boolean inHead(String path) throws IOException {
- Tree headTree = repository.mapTree(Constants.HEAD);
- String repoPath = getRepoRelativePath(path);
- boolean headExists = headTree.existsBlob(repoPath);
- return headExists;
+ ObjectId headId = repository.resolve(Constants.HEAD);
+ RevWalk rw = new RevWalk(repository);
+ TreeWalk tw = null;
+ try {
+ tw = TreeWalk.forPath(repository, path, rw.parseTree(headId));
+ return tw != null;
+ } finally {
+ rw.release();
+ rw.dispose();
+ if (tw != null)
+ tw.release();
+ }
}
public boolean inIndex(String path) throws IOException {
-// String repoPath = getRepoRelativePath(path);
-// GitIndex index = repository.getIndex();
-// return index.getEntry(repoPath) != null;
String repoPath = getRepoRelativePath(path);
DirCache dc = DirCache.read(repository.getIndexFile(), repository.getFS());
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ConnectProviderOperationTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ConnectProviderOperationTest.java
index f0cddc272..319fa7d94 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ConnectProviderOperationTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ConnectProviderOperationTest.java
@@ -9,30 +9,22 @@
*******************************************************************************/
package org.eclipse.egit.core.test.op;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
-import java.util.Date;
-import java.util.TimeZone;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.egit.core.op.ConnectProviderOperation;
import org.eclipse.egit.core.test.GitTestCase;
-import org.eclipse.jgit.lib.CommitBuilder;
+import org.eclipse.egit.core.test.TestRepository;
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.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.junit.Test;
@@ -66,49 +58,27 @@ public class ConnectProviderOperationTest extends GitTestCase {
}
@Test
- public void testNewUnsharedFile() throws CoreException, IOException {
+ public void testNewUnsharedFile() throws CoreException, Exception {
project.createSourceFolder();
IFile fileA = project.getProject().getFolder("src").getFile("A.java");
String srcA = "class A {\n" + "}\n";
- fileA.create(new ByteArrayInputStream(srcA.getBytes("UTF-8")), false, null);
-
- Repository thisGit = new FileRepository(gitDir);
- thisGit.create();
- Tree rootTree = new Tree(thisGit);
- Tree prjTree = rootTree.addTree(project.getProject().getName());
- Tree srcTree = prjTree.addTree("src");
- FileTreeEntry entryA = srcTree.addFile("A.java");
-
- ObjectId id;
- ObjectInserter inserter = thisGit.newObjectInserter();
- try {
- entryA.setId(inserter.insert(Constants.OBJ_BLOB, srcA.getBytes("UTF-8")));
- srcTree.setId(inserter.insert(Constants.OBJ_TREE, srcTree.format()));
- prjTree.setId(inserter.insert(Constants.OBJ_TREE, prjTree.format()));
- rootTree.setId(inserter.insert(Constants.OBJ_TREE, rootTree.format()));
- CommitBuilder commit = new CommitBuilder();
- commit.setTreeId(rootTree.getTreeId());
- commit.setAuthor(new PersonIdent("J. Git", "j.git@egit.org",
- new Date(60876075600000L), TimeZone.getTimeZone("GMT+1")));
- commit.setCommitter(commit.getAuthor());
- commit.setMessage("testNewUnsharedFile\n\nJunit tests\n");
- id = inserter.insert(commit);
- inserter.flush();
- } finally {
- inserter.release();
- }
-
- RefUpdate lck = thisGit.updateRef("refs/heads/master");
- assertNotNull("obtained lock", lck);
- lck.setNewObjectId(id);
- assertEquals(RefUpdate.Result.NEW, lck.forceUpdate());
+ fileA.create(new ByteArrayInputStream(srcA.getBytes("UTF-8")), false,
+ null);
+
+ TestRepository thisGit = new TestRepository(gitDir);
+
+ File committable = new File(fileA.getLocationURI());
+
+ thisGit.addAndCommit(project.project, committable,
+ "testNewUnsharedFile\n\nJunit tests\n");
+
+ assertNull(RepositoryProvider.getProvider(project.getProject()));
ConnectProviderOperation operation = new ConnectProviderOperation(
project.getProject(), gitDir);
operation.execute(null);
assertNotNull(RepositoryProvider.getProvider(project.getProject()));
-
}
}

Back to the top