Author: adietish
Date: 2011-08-24 13:43:31 -0400 (Wed, 24 Aug 2011)
New Revision: 34235
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/src/org/jboss/ide/eclipse/as/egit/internal/test/EGitUtilsTest.java
trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/src/org/jboss/ide/eclipse/as/egit/internal/test/util/TestRepository.java
Log:
[JBIDE-9575] test for "push to remote by name" implemented and successful.
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/src/org/jboss/ide/eclipse/as/egit/internal/test/EGitUtilsTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/src/org/jboss/ide/eclipse/as/egit/internal/test/EGitUtilsTest.java 2011-08-24
17:32:31 UTC (rev 34234)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/src/org/jboss/ide/eclipse/as/egit/internal/test/EGitUtilsTest.java 2011-08-24
17:43:31 UTC (rev 34235)
@@ -8,8 +8,6 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.egit.core.Activator;
-import org.eclipse.jgit.api.Git;
-import org.eclipse.jgit.lib.Repository;
import org.jboss.ide.eclipse.as.egit.core.EGitUtils;
import org.jboss.ide.eclipse.as.egit.internal.test.util.TestProject;
import org.jboss.ide.eclipse.as.egit.internal.test.util.TestRepository;
@@ -26,7 +24,6 @@
protected final TestUtils testUtils = new TestUtils();
- private File gitDir;
private TestRepository testRepository;
private TestProject testProject;
private TestRepository clonedTestRepository;
@@ -37,8 +34,7 @@
this.testProject = new TestProject(true);
- this.gitDir = TestUtils.createGitDir(testProject);
- this.testRepository = new TestRepository(gitDir);
+ this.testRepository = new TestRepository(TestUtils.createGitDir(testProject));
testRepository.createMockSystemReader(ResourcesPlugin.getWorkspace().getRoot().getLocation());
testRepository.setUserAndEmail(GIT_USER, GIT_EMAIL);
testRepository.connect(testProject.getProject());
@@ -46,7 +42,8 @@
this.clonedTestRepository = cloneRepository(testRepository);
}
- private TestRepository cloneRepository(TestRepository repository) throws
URISyntaxException, InvocationTargetException, InterruptedException, IOException {
+ private TestRepository cloneRepository(TestRepository repository) throws
URISyntaxException,
+ InvocationTargetException, InterruptedException, IOException {
File workspaceDir = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile();
File clonedRepositoryFile =
new File(workspaceDir, "clonedRepository-" +
String.valueOf(System.currentTimeMillis()));
@@ -66,10 +63,10 @@
public void canCommitFileInProject() throws Exception {
String fileName = "a.txt";
String fileContent = "adietish(a)redhat.com";
-
+
IFile file = testUtils.addFileToProject(
testProject.getProject(),
- fileName,
+ fileName,
fileContent);
testRepository.track(file);
@@ -84,19 +81,50 @@
public void fileAddedToCloneIsInOriginAfterPush() throws Exception {
String fileName = "b.txt";
String fileContent = "adietish(a)redhat.com";
-
- clonedTestRepository.createFile(fileName, fileContent);
- Repository clonedRepository = clonedTestRepository.getRepository();
- Git git = new Git(clonedRepository);
- git.add().addFilepattern(fileName).call();
- git.commit().setCommitter(GIT_USER, GIT_EMAIL).setMessage("adding a new
file").call();
- EGitUtils.push(clonedRepository, null);
+ File file = clonedTestRepository.createFile(fileName, fileContent);
+ clonedTestRepository.addAndCommit(file, "adding a file");
+ EGitUtils.push(clonedTestRepository.getRepository(), null);
+
// does origin contain file added to clone?
testUtils.assertRepositoryContainsFilesWithContent(
- clonedRepository,
+ clonedTestRepository.getRepository(),
fileName,
fileContent);
}
+
+ @Test
+ public void fileAddedToCloneIsInRemoteAfterPush() throws Exception {
+ TestProject testProject2 = null;
+ TestRepository testRepository2 = null;
+ String fileName = "c.txt";
+ String fileContent = "adietish(a)redhat.com";
+ String remoteRepoName = "openshift";
+
+ try {
+ testProject2 = new TestProject(true);
+ File gitDir = TestUtils.createGitDir(testProject2);
+ testRepository2 = new TestRepository(gitDir);
+ clonedTestRepository.addRemoteTo(remoteRepoName, testRepository2.getRepository());
+
+ File file = clonedTestRepository.createFile(fileName, fileContent);
+ clonedTestRepository.addAndCommit(file, "adding a file");
+
+ EGitUtils.push(remoteRepoName, clonedTestRepository.getRepository(), null);
+
+ // does origin contain file added to clone?
+ testUtils.assertRepositoryContainsFilesWithContent(
+ clonedTestRepository.getRepository(),
+ fileName,
+ fileContent);
+ } finally {
+ if (testProject2 != null) {
+ testProject2.dispose();
+ }
+ if (testRepository2 != null) {
+ testRepository2.dispose();
+ }
+ }
+ }
}
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/src/org/jboss/ide/eclipse/as/egit/internal/test/util/TestRepository.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/src/org/jboss/ide/eclipse/as/egit/internal/test/util/TestRepository.java 2011-08-24
17:32:31 UTC (rev 34234)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/src/org/jboss/ide/eclipse/as/egit/internal/test/util/TestRepository.java 2011-08-24
17:43:31 UTC (rev 34235)
@@ -16,6 +16,7 @@
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.Collections;
@@ -53,6 +54,7 @@
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.storage.file.FileRepository;
+import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.util.FileUtils;
@@ -170,9 +172,10 @@
return file;
}
- public void createFile(String name, String data) throws IOException {
+ public File createFile(String name, String data) throws IOException {
File file = new File(repository.getWorkTree(), name);
write(file, data);
+ return file;
}
private void write(final File file, final String data) throws IOException {
@@ -202,6 +205,14 @@
return commit(commitMessage);
}
+ public RevCommit addAndCommit(File file, String commitMessage)
+ throws Exception {
+ track(file);
+ addToIndex(file);
+
+ return commit(commitMessage);
+ }
+
/**
* Appends file content to given file, then track, add to index and finally
* commit it.
@@ -363,6 +374,15 @@
}
}
+ public void addToIndex(File file) throws CoreException, IOException {
+ String repoPath = getRepoRelativePath(file.getAbsolutePath());
+ try {
+ new Git(repository).add().addFilepattern(repoPath).call();
+ } catch (NoFilepatternException e) {
+ throw new IOException(e.getMessage());
+ }
+ }
+
/**
* Appends content to end of given file.
*
@@ -573,4 +593,16 @@
public File getGitDir() {
return gitDir;
}
+
+ public void addRemoteTo(String remoteName, Repository remoteRepository)
+ throws URISyntaxException, MalformedURLException,
+ IOException {
+ StoredConfig config = repository.getConfig();
+ RemoteConfig remoteConfig = new RemoteConfig(config, remoteName);
+ URIish uri = new URIish(remoteRepository.getDirectory().toURI().toURL());
+ remoteConfig.addURI(uri);
+ remoteConfig.update(config);
+ config.save();
+ }
+
}