List of usage examples for org.eclipse.jgit.lib Repository getDirectory
public File getDirectory()
From source file:org.jboss.as.server.controller.git.GitRepository.java
License:Apache License
public GitRepository(Repository repository) { this.repository = repository; this.ignored = Collections.emptySet(); this.defaultRemoteRepository = DEFAULT_REMOTE_NAME; this.branch = MASTER; if (repository.isBare()) { this.basePath = repository.getDirectory().toPath(); } else {/*from w w w .j av a 2s . co m*/ this.basePath = repository.getDirectory().toPath().getParent(); } ServerLogger.ROOT_LOGGER.usingGit(); }
From source file:org.jboss.tools.feedhenry.ui.internal.util.GitUtil.java
License:Open Source License
public static Repository share(IProject project, IProgressMonitor monitor) throws CoreException { Repository repository = createRepository(project, monitor); connect(project, repository.getDirectory(), monitor); addToRepository(project, repository, monitor); commit(project, "Initial commit from JBoss Tools", repository, monitor); return repository; }
From source file:org.jboss.tools.maven.git.internal.wizard.ImportMavenProjectsWizard.java
License:Open Source License
@Override public boolean performFinish() { if (!mavenProjectsWizardPage.isPageComplete()) { return false; }/*from ww w . ja va 2 s . c o m*/ final Collection<MavenProjectInfo> projects = mavenProjectsWizardPage.getProjects(); final Repository repository = selectRepoPage.getRepository(); Job job = new WorkspaceJob("Importing Maven projects") { public IStatus runInWorkspace(IProgressMonitor monitor) { setProperty(IProgressConstants.ACTION_PROPERTY, new OpenMavenConsoleAction()); List<IMavenProjectImportResult> results = null; try { results = MavenPlugin.getDefault().getProjectConfigurationManager().importProjects(projects, importConfiguration, monitor); if (repository != null) { String repoDir = repository.getDirectory().getParent(); for (IMavenProjectImportResult result : results) { IProject project = result.getProject(); if (project != null && project.isOpen() && project.getLocation() != null) { if (project.getLocation().toOSString().startsWith(repoDir)) { ConnectProviderOperation connectProviderOperation = new ConnectProviderOperation( project, repository.getDirectory()); connectProviderOperation.execute(monitor); } } } } } catch (CoreException ex) { MavenPlugin.getDefault().getConsole().logError("Projects imported with errors"); return ex.getStatus(); } return Status.OK_STATUS; } }; job.setRule(MavenPlugin.getDefault().getProjectConfigurationManager().getRule()); job.schedule(); return true; }
From source file:org.jboss.tools.maven.git.internal.wizard.ImportMavenProjectsWizard.java
License:Open Source License
@Override public IWizardPage getNextPage(IWizardPage page) { if (page == selectRepoPage) { Repository repository = selectRepoPage.getRepository(); File directory = repository.getDirectory(); if (directory != null) { List<String> locations = new ArrayList<String>(); locations.add(directory.getParent()); mavenProjectsWizardPage.setLocations(locations); }//from w w w . j av a2s .co m } return super.getNextPage(page); }
From source file:org.jboss.tools.openshift.egit.core.EGitUtils.java
License:Open Source License
/** * Connects the given project to the given repository. * //from w w w . j ava 2s.c o m * @param project * the project to connect * @param repository * the repository to connect the project to * @param monitor * the monitor to report progress to * @throws CoreException */ private static void connect(IProject project, Repository repository, IProgressMonitor monitor) throws CoreException { connect(project, repository.getDirectory(), monitor); }
From source file:org.jboss.tools.openshift.egit.core.EGitUtils.java
License:Open Source License
/** * Returns the changes in the index of the HEAD branch in the given * repository. Returns the index diff if there are changes, * <code>null</code> otherwise. * /*from w w w . j av a2s. co m*/ * @param repo * the repository to get index changes for * @param monitor * the monitor to report progress to * @return the changes in the index or null; * @throws IOException */ public static IndexDiff getIndexChanges(Repository repo, IProgressMonitor monitor) throws IOException { EclipseGitProgressTransformer jgitMonitor = new EclipseGitProgressTransformer(monitor); IndexDiff indexDiff = new IndexDiff(repo, Constants.HEAD, IteratorService.createInitialIterator(repo)); if (!indexDiff.diff(jgitMonitor, 0, 0, NLS.bind("Repository: {0}", repo.getDirectory().getPath()))) { return null; } return indexDiff; }
From source file:org.jboss.tools.openshift.egit.internal.test.util.TestRepository.java
License:Open Source License
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);/* w w w . j a v a 2 s . c o m*/ remoteConfig.update(config); config.save(); }
From source file:org.jboss.tools.openshift.internal.ui.wizard.importapp.ImportProjectOperation.java
License:Open Source License
/** * Fetches and creates the branch with the given name from the given remote. * @param gitRef/*w w w .ja va 2 s. c o m*/ * @param project * @param repository * @param monitor * @throws CoreException * @throws InvocationTargetException * @throws IOException */ private void fetchBranch(String gitRef, RemoteConfig remote, Repository repository, IProgressMonitor monitor) throws CoreException, InvocationTargetException, IOException { if (remote == null) { throw new CoreException(StatusFactory.errorStatus(OpenShiftUIActivator.PLUGIN_ID, NLS.bind( "Could not fetch determine the remote for the repo at {0} that we should fetch branch {1} from.", repository.getDirectory(), gitRef))); } EGitUtils.fetch(remote, Arrays.asList(new RefSpec( Constants.R_HEADS + gitRef + ":" + Constants.R_REMOTES + remote.getName() + "/" + gitRef)), repository, monitor); RevCommit commit = EGitUtils.getLatestCommit(gitRef, remote.getName(), repository); EGitUtils.createBranch(gitRef, commit, repository, monitor); }
From source file:org.jenkinsci.git.CloneOperationTest.java
License:Open Source License
/** * Test cloning a local repository//from www . j a va 2 s. c o m * * @throws Exception */ @Test public void cloneRepository() throws Exception { Repository existing = git.repo(); RevCommit commit = git.add("file.txt", "abcd"); BuildRepository repo = new BuildRepository(existing.getDirectory().toURI().toString(), "master", null); File dir = git.tempDirectory(); CloneOperation op = new CloneOperation(repo); Repository cloned = op.invoke(dir, null); assertNotNull(cloned); assertFalse(existing.getDirectory().equals(cloned.getDirectory())); assertTrue(new File(dir, Constants.DOT_GIT).exists()); assertNotNull(CommitUtils.getCommit(cloned, commit)); }
From source file:org.jenkinsci.git.CloneOperationTest.java
License:Open Source License
/** * Test cloning into a subdirectory//from w ww . j av a 2 s . com * * @throws Exception */ @Test public void cloneIntoSubDirectory() throws Exception { Repository existing = git.repo(); RevCommit commit = git.add("file.txt", "abcd"); BuildRepository repo = new BuildRepository(existing.getDirectory().toURI().toString(), "master", "sub1"); CloneOperation op = new CloneOperation(repo); File dir = git.tempDirectory(); Repository cloned = op.invoke(dir, null); assertNotNull(cloned); assertFalse(existing.getDirectory().equals(cloned.getDirectory())); assertFalse(new File(dir, Constants.DOT_GIT).exists()); assertTrue(new File(dir, repo.getDirectory()).exists()); assertTrue(new File(dir, repo.getDirectory() + File.separatorChar + Constants.DOT_GIT).exists()); assertNotNull(CommitUtils.getCommit(cloned, commit)); }