use of org.eclipse.egit.core.op.CloneOperation in project egit by eclipse.
the class GitRepositoriesViewBranchHandlingTest method setUp.
@Before
public void setUp() throws Exception {
clearView();
setVerboseBranchMode(false);
repositoryFile = createProjectAndCommitToRepository();
remoteRepositoryFile = createRemoteRepository(repositoryFile);
// now let's clone the remote repository
final URIish uri = new URIish(remoteRepositoryFile.getPath());
final File workdir = new File(getTestDirectory(), "Cloned");
CloneOperation op = new CloneOperation(uri, true, null, workdir, "refs/heads/master", "origin", 0);
op.run(null);
clonedRepositoryFile = new File(workdir, Constants.DOT_GIT);
RepositoryUtil repositoryUtil = Activator.getDefault().getRepositoryUtil();
repositoryUtil.addConfiguredRepository(repositoryFile);
repositoryUtil.addConfiguredRepository(remoteRepositoryFile);
repositoryUtil.addConfiguredRepository(clonedRepositoryFile);
}
use of org.eclipse.egit.core.op.CloneOperation in project egit by eclipse.
the class ListRemoteOperationTest method setUp.
/**
* Set up repository1 with branch "master", create some project and commit
* it; then clone into repository2; finally create a branch "test" on top of
* "master" in repository2
*
* @throws Exception
*/
@Before
public void setUp() throws Exception {
workdir = testUtils.createTempDir("Repository1");
workdir2 = testUtils.createTempDir("Repository2");
repository1 = new TestRepository(new File(workdir, Constants.DOT_GIT));
// now we create a project in repo1
IProject project = testUtils.createProjectInLocalFileSystem(workdir, projectName);
testUtils.addFileToProject(project, "folder1/file1.txt", "Hello world");
repository1.connect(project);
repository1.trackAllFiles(project);
repository1.commit("Initial commit");
// let's get rid of the project
project.delete(false, false, null);
// let's clone repository1 to repository2
URIish uri = new URIish("file:///" + repository1.getRepository().getDirectory().toString());
CloneOperation clop = new CloneOperation(uri, true, null, workdir2, "refs/heads/master", "origin", 0);
clop.run(null);
Repository existingRepo = Activator.getDefault().getRepositoryCache().lookupRepository(new File(workdir2, Constants.DOT_GIT));
repository2 = new TestRepository(existingRepo);
// we push to branch "test" of repository2
RefUpdate createBranch = repository2.getRepository().updateRef("refs/heads/test");
createBranch.setNewObjectId(repository2.getRepository().resolve("refs/heads/master"));
createBranch.update();
}
use of org.eclipse.egit.core.op.CloneOperation in project egit by eclipse.
the class PushOperationTest method setUp.
/**
* Set up repository1 with branch "master", create some project and commit
* it; then clone into repository2; finally create a branch "test" on top of
* "master" in repository2
*
* @throws Exception
*/
@Before
public void setUp() throws Exception {
workdir = testUtils.createTempDir("Repository1");
workdir2 = testUtils.createTempDir("Repository2");
repository1 = new TestRepository(new File(workdir, Constants.DOT_GIT));
// now we create a project in repo1
IProject project = testUtils.createProjectInLocalFileSystem(workdir, projectName);
testUtils.addFileToProject(project, "folder1/file1.txt", "Hello world");
repository1.connect(project);
repository1.trackAllFiles(project);
repository1.commit("Initial commit");
// let's get rid of the project
project.delete(false, false, null);
// let's clone repository1 to repository2
URIish uri = repository1.getUri();
CloneOperation clop = new CloneOperation(uri, true, null, workdir2, "refs/heads/master", "origin", 0);
clop.run(null);
Repository repo2 = Activator.getDefault().getRepositoryCache().lookupRepository(new File(workdir2, Constants.DOT_GIT));
repository2 = new TestRepository(repo2);
// we push to branch "test" of repository2
RefUpdate createBranch = repository2.getRepository().updateRef("refs/heads/test");
createBranch.setNewObjectId(repository2.getRepository().resolve("refs/heads/master"));
createBranch.update();
}
use of org.eclipse.egit.core.op.CloneOperation in project egit by eclipse.
the class CloneOperationTest method testConfigureFetchAfterCloneTask.
@Test
public void testConfigureFetchAfterCloneTask() throws Exception {
createNoteInOrigin();
URIish uri = new URIish("file:///" + repository1.getRepository().getDirectory().toString());
CloneOperation clop = new CloneOperation(uri, true, null, workdir2, "refs/heads/master", "origin", 0);
clop.addPostCloneTask(new ConfigureFetchAfterCloneTask("origin", "refs/notes/review:refs/notes/review"));
clop.run(null);
Repository clonedRepo = FileRepositoryBuilder.create(new File(workdir2, Constants.DOT_GIT));
assertTrue(clonedRepo.getConfig().getStringList(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", "fetch")[1].equals("refs/notes/review:refs/notes/review"));
Git clonedGit = new Git(clonedRepo);
assertEquals(1, clonedGit.notesList().setNotesRef("refs/notes/review").call().size());
clonedGit.close();
}
use of org.eclipse.egit.core.op.CloneOperation in project egit by eclipse.
the class ProjectReferenceImporter method cloneIfNecessary.
private static File cloneIfNecessary(final URIish gitUrl, final String refToCheckout, final IPath workDir, final Set<ProjectReference> projects, IProgressMonitor monitor) throws TeamException, InterruptedException {
final File repositoryPath = workDir.append(Constants.DOT_GIT_EXT).toFile();
if (workDir.toFile().exists()) {
if (repositoryAlreadyExistsForUrl(repositoryPath, gitUrl))
return repositoryPath;
else {
final Collection<String> projectNames = new LinkedList<String>();
for (final ProjectReference projectReference : projects) projectNames.add(projectReference.getProjectDir());
throw new TeamException(NLS.bind(CoreText.GitProjectSetCapability_CloneToExistingDirectory, new Object[] { workDir, projectNames, gitUrl }));
}
} else {
try {
int timeout = 60;
final CloneOperation cloneOperation = new CloneOperation(gitUrl, true, null, workDir.toFile(), refToCheckout, Constants.DEFAULT_REMOTE_NAME, timeout);
cloneOperation.run(monitor);
return repositoryPath;
} catch (final InvocationTargetException e) {
throw getTeamException(e);
}
}
}
Aggregations