@Override @Before public void beforeTestCase() throws Exception { workdir = testUtils.createTempDir("Repository1"); workdir2 = testUtils.createTempDir("Repository2"); repository1 = new TestRepository(new File(workdir, DOT_GIT)); repository1.createInitialCommit("setUp"); Repository repository = repository1.getRepository(); new InitOperation(repository).execute(null); // 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, R_HEADS + MY_MASTER, DEFAULT_REMOTE_NAME, 0); clop.run(null); Repository repo2 = Activator.getDefault().getRepositoryCache().lookupRepository(new File(workdir2, DOT_GIT)); repository2 = new TestRepository(repo2); }
@Before public void before() throws Exception { repositoryFile = createProjectAndCommitToRepository(); remoteRepositoryFile = createRemoteRepository(repositoryFile); // now let's clone the remote repository URIish uri = new URIish("file:///" + remoteRepositoryFile.getPath()); File workdir = new File(getTestDirectory(), "ClonedRepo"); CloneOperation op = new CloneOperation(uri, true, null, workdir, "refs/heads/master", "origin", 0); op.run(null); clonedRepositoryFile = new File(workdir, Constants.DOT_GIT); // now let's clone the remote repository uri = new URIish(remoteRepositoryFile.getPath()); workdir = new File(getTestDirectory(), "ClonedRepo2"); op = new CloneOperation(uri, true, null, workdir, "refs/heads/master", "origin", 0); op.run(null); clonedRepositoryFile2 = new File(workdir, Constants.DOT_GIT); clearView(); deleteAllProjects(); }
private IStatus executeCloneOperation(final CloneOperation op, final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { final RepositoryUtil util = Activator.getDefault().getRepositoryUtil(); op.run(monitor); util.addConfiguredRepository(op.getGitDir()); return Status.OK_STATUS; }
boolean performClone() { final URIish uri = cloneSource.getSelection().getURI(); setWindowTitle(NLS.bind(UIText.GitCloneWizard_jobName, uri.toString())); final boolean allSelected; final Collection<Ref> selectedBranches; if (validSource.isSourceRepoEmpty()) { // fetch all branches of empty repo allSelected = true; selectedBranches = Collections.emptyList(); } else { allSelected = validSource.isAllSelected(); selectedBranches = validSource.getSelectedBranches(); } final File workdir = cloneDestination.getDestinationFile(); final Ref ref = cloneDestination.getInitialBranch(); final String remoteName = cloneDestination.getRemote(); boolean created = workdir.exists(); if (!created) created = workdir.mkdirs(); if (!created || !workdir.isDirectory()) { final String errorMessage = NLS.bind(UIText.GitCloneWizard_errorCannotCreate, workdir.getPath()); ErrorDialog.openError( getShell(), getWindowTitle(), UIText.GitCloneWizard_failed, new Status(IStatus.ERROR, Activator.getPluginId(), 0, errorMessage, null)); // let's give user a chance to fix this minor problem return false; } int timeout = Activator.getDefault().getPreferenceStore().getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT); final CloneOperation op = new CloneOperation( uri, allSelected, selectedBranches, workdir, ref != null ? ref.getName() : null, remoteName, timeout); if (gerritConfiguration.configureGerrit()) doGerritConfiguration(remoteName, op); UserPasswordCredentials credentials = cloneSource.getCredentials(); if (credentials != null) op.setCredentialsProvider( new UsernamePasswordCredentialsProvider( credentials.getUser(), credentials.getPassword())); alreadyClonedInto = workdir.getPath(); cloneSource.saveUriInPrefs(); if (!callerRunsCloneOperation) runAsJob(uri, op); else cloneOperation = op; return true; }
private void doGerritConfiguration(final String remoteName, final CloneOperation op) { String gerritBranch = gerritConfiguration.getBranch(); URIish pushURI = gerritConfiguration.getURI(); if (gerritBranch != null && gerritBranch.length() > 0) { ConfigurePushAfterCloneTask push = new ConfigurePushAfterCloneTask( remoteName, "HEAD:refs/for/" + gerritBranch, pushURI); // $NON-NLS-1$ op.addPostCloneTask(push); } op.addPostCloneTask(new SetChangeIdTask(true)); }
public static void cloneRepository( String uri, String remoteName, File destination, PostCloneTask postCloneTask, IProgressMonitor monitor) throws URISyntaxException, InvocationTargetException, InterruptedException { URIish gitUri = new URIish(uri); CloneOperation cloneOperation = new CloneOperation( gitUri, true, null, destination, Constants.HEAD, remoteName, CLONE_TIMEOUT); if (postCloneTask != null) { cloneOperation.addPostCloneTask(postCloneTask); } cloneOperation.run(monitor); // RepositoryUtil repositoryUtil = // Activator.getDefault().getRepositoryUtil(); // repositoryUtil.addConfiguredRepository(new File(destination, // Constants.DOT_GIT)); }