List of usage examples for org.eclipse.jgit.lib Repository getDirectory
public File getDirectory()
From source file:org.eclipse.egit.ui.internal.jobs.RepositoryJobResultAction.java
License:Open Source License
/** * Creates a new {@link RepositoryJobResultAction}. * * @param repository/*from w w w . j a v a2 s.c o m*/ * the result belongs to * @param title * of the action */ public RepositoryJobResultAction(@NonNull Repository repository, String title) { super(title); this.repositoryDir = repository.getDirectory(); }
From source file:org.eclipse.egit.ui.internal.merge.GitMergeEditorInput.java
License:Open Source License
@Override protected Object prepareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { final Set<IFile> files = new HashSet<IFile>(); List<IContainer> folders = new ArrayList<IContainer>(); Set<IProject> projects = new HashSet<IProject>(); // collect all projects and sort the selected // resources into files and folders; skip // ignored resources for (IResource res : resources) { projects.add(res.getProject());// w w w .java2 s . co m if (Team.isIgnoredHint(res)) continue; if (res.getType() == IResource.FILE) files.add((IFile) res); else folders.add((IContainer) res); } if (monitor.isCanceled()) throw new InterruptedException(); // make sure all resources belong to the same repository Repository repo = null; for (IProject project : projects) { RepositoryMapping map = RepositoryMapping.getMapping(project); if (repo != null && repo != map.getRepository()) throw new InvocationTargetException( new IllegalStateException(UIText.AbstractHistoryCommanndHandler_NoUniqueRepository)); repo = map.getRepository(); } if (repo == null) throw new InvocationTargetException( new IllegalStateException(UIText.AbstractHistoryCommanndHandler_NoUniqueRepository)); if (monitor.isCanceled()) throw new InterruptedException(); // collect all file children of the selected folders IResourceVisitor fileCollector = new IResourceVisitor() { public boolean visit(IResource resource) throws CoreException { if (Team.isIgnoredHint(resource)) return false; if (resource.getType() == IResource.FILE) { files.add((IFile) resource); } return true; } }; for (IContainer cont : folders) { try { cont.accept(fileCollector); } catch (CoreException e) { // ignore here } } if (monitor.isCanceled()) throw new InterruptedException(); // our root node this.compareResult = new DiffNode(Differencer.CONFLICTING); final RevWalk rw = new RevWalk(repo); // get the "right" side (MERGE_HEAD for merge, ORIG_HEAD for rebase) final RevCommit rightCommit; try { String target; if (repo.getRepositoryState().equals(RepositoryState.MERGING)) target = Constants.MERGE_HEAD; else if (repo.getRepositoryState().equals(RepositoryState.REBASING_INTERACTIVE)) target = readFile(repo.getDirectory(), RebaseCommand.REBASE_MERGE + File.separatorChar + RebaseCommand.STOPPED_SHA); else target = Constants.ORIG_HEAD; ObjectId mergeHead = repo.resolve(target); if (mergeHead == null) throw new IOException(NLS.bind(UIText.ValidationUtils_CanNotResolveRefMessage, target)); rightCommit = rw.parseCommit(mergeHead); } catch (IOException e) { throw new InvocationTargetException(e); } // we need the HEAD, also to determine the common // ancestor final RevCommit headCommit; try { ObjectId head = repo.resolve(Constants.HEAD); if (head == null) throw new IOException(NLS.bind(UIText.ValidationUtils_CanNotResolveRefMessage, Constants.HEAD)); headCommit = rw.parseCommit(head); } catch (IOException e) { throw new InvocationTargetException(e); } final String fullBranch; try { fullBranch = repo.getFullBranch(); } catch (IOException e) { throw new InvocationTargetException(e); } // try to obtain the common ancestor List<RevCommit> startPoints = new ArrayList<RevCommit>(); rw.setRevFilter(RevFilter.MERGE_BASE); startPoints.add(rightCommit); startPoints.add(headCommit); RevCommit ancestorCommit; try { rw.markStart(startPoints); ancestorCommit = rw.next(); } catch (Exception e) { ancestorCommit = null; } if (monitor.isCanceled()) throw new InterruptedException(); // set the labels CompareConfiguration config = getCompareConfiguration(); config.setRightLabel(NLS.bind(LABELPATTERN, rightCommit.getShortMessage(), rightCommit.name())); if (!useWorkspace) config.setLeftLabel(NLS.bind(LABELPATTERN, headCommit.getShortMessage(), headCommit.name())); else config.setLeftLabel(UIText.GitMergeEditorInput_WorkspaceHeader); if (ancestorCommit != null) config.setAncestorLabel( NLS.bind(LABELPATTERN, ancestorCommit.getShortMessage(), ancestorCommit.name())); // set title and icon setTitle(NLS.bind(UIText.GitMergeEditorInput_MergeEditorTitle, new Object[] { Activator.getDefault().getRepositoryUtil().getRepositoryName(repo), rightCommit.getShortMessage(), fullBranch })); // now we calculate the nodes containing the compare information try { for (IFile file : files) { if (monitor.isCanceled()) throw new InterruptedException(); monitor.setTaskName(file.getFullPath().toString()); RepositoryMapping map = RepositoryMapping.getMapping(file); String gitPath = map.getRepoRelativePath(file); if (gitPath == null) continue; // ignore everything in .git if (gitPath.startsWith(Constants.DOT_GIT)) continue; fileToDiffNode(file, gitPath, map, this.compareResult, rightCommit, headCommit, ancestorCommit, rw, monitor); } } catch (IOException e) { throw new InvocationTargetException(e); } return compareResult; }
From source file:org.eclipse.egit.ui.internal.preferences.GitProjectPropertyPage.java
License:Open Source License
private void fillValues(Repository repository) throws IOException { gitDir.setText(repository.getDirectory().getAbsolutePath()); branch.setText(repository.getBranch()); workDir.setText(repository.getWorkTree().getAbsolutePath()); state.setText(repository.getRepositoryState().getDescription()); final ObjectId objectId = repository.resolve(repository.getFullBranch()); if (objectId == null) { if (repository.getAllRefs().size() == 0) id.setText(UIText.GitProjectPropertyPage_ValueEmptyRepository); else/*w ww. ja va2 s . c o m*/ id.setText(UIText.GitProjectPropertyPage_ValueUnbornBranch); } else id.setText(objectId.name()); }
From source file:org.eclipse.egit.ui.internal.push.PushBranchWizardTest.java
License:Open Source License
private URIish getUri(Repository repo) throws MalformedURLException { return new URIish(repo.getDirectory().toURI().toURL()); }
From source file:org.eclipse.egit.ui.internal.push.PushOperationUI.java
License:Open Source License
/** * @param repository//from w w w .j a va 2s . c om * @param remoteName * @param timeout * @param dryRun * */ public PushOperationUI(Repository repository, String remoteName, int timeout, boolean dryRun) { this.repository = repository; this.spec = null; this.config = null; this.remoteName = remoteName; this.timeout = timeout; this.dryRun = dryRun; destinationString = NLS.bind("{0} - {1}", repository.getDirectory() //$NON-NLS-1$ .getParentFile().getName(), remoteName); }
From source file:org.eclipse.egit.ui.internal.push.PushOperationUI.java
License:Open Source License
/** * @param repository//from ww w.j a va2 s . c o m * @param config * @param timeout * @param dryRun * */ public PushOperationUI(Repository repository, RemoteConfig config, int timeout, boolean dryRun) { this.repository = repository; this.spec = null; this.config = config; this.remoteName = null; this.timeout = timeout; this.dryRun = dryRun; destinationString = NLS.bind("{0} - {1}", repository.getDirectory() //$NON-NLS-1$ .getParentFile().getName(), config.getName()); }
From source file:org.eclipse.egit.ui.internal.reflog.ReflogView.java
License:Open Source License
private void reactOnSelection(ISelection selection) { if (!(selection instanceof IStructuredSelection)) return;/*from www . jav a 2 s . c o m*/ IStructuredSelection ssel = (IStructuredSelection) selection; if (ssel.size() != 1) return; Repository selectedRepo = null; Object first = ssel.getFirstElement(); if (first instanceof IResource) { IResource resource = (IResource) ssel.getFirstElement(); RepositoryMapping mapping = RepositoryMapping.getMapping(resource.getProject()); if (mapping != null) selectedRepo = mapping.getRepository(); } if (selectedRepo == null && first instanceof IAdaptable) { IResource adapted = (IResource) ((IAdaptable) ssel.getFirstElement()).getAdapter(IResource.class); if (adapted != null) { RepositoryMapping mapping = RepositoryMapping.getMapping(adapted); if (mapping != null) selectedRepo = mapping.getRepository(); } } if (selectedRepo == null && first instanceof RepositoryTreeNode) { RepositoryTreeNode repoNode = (RepositoryTreeNode) ssel.getFirstElement(); selectedRepo = repoNode.getRepository(); } if (selectedRepo == null) return; // Only update when different repository is selected Repository currentRepo = getRepository(); if (currentRepo == null || !selectedRepo.getDirectory().equals(currentRepo.getDirectory())) showReflogFor(selectedRepo); }
From source file:org.eclipse.egit.ui.internal.repository.RepositoriesViewLabelProvider.java
License:Open Source License
public StyledString getStyledText(Object element) { if (!(element instanceof RepositoryTreeNode)) return null; RepositoryTreeNode node = (RepositoryTreeNode) element; try {/*from w ww . j a v a 2 s . c o m*/ switch (node.getType()) { case REPO: Repository repository = (Repository) node.getObject(); File directory = repository.getDirectory(); StyledString string = new StyledString(directory.getParentFile().getName()); string.append(" - " + directory.getAbsolutePath(), StyledString.QUALIFIER_STYLER); //$NON-NLS-1$ String branch = repository.getBranch(); if (repository.getRepositoryState() != RepositoryState.SAFE) branch += " - " + repository.getRepositoryState().getDescription(); //$NON-NLS-1$ string.append(" [" + branch + "]", StyledString.DECORATIONS_STYLER); //$NON-NLS-1$//$NON-NLS-2$ return string; case ADDITIONALREF: Ref ref = (Ref) node.getObject(); // shorten the name StyledString refName = new StyledString(Repository.shortenRefName(ref.getName())); if (ref.isSymbolic()) { refName.append(" - ", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$ refName.append(ref.getLeaf().getName(), StyledString.QUALIFIER_STYLER); refName.append(" - ", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$ refName.append(ObjectId.toString(ref.getLeaf().getObjectId()), StyledString.QUALIFIER_STYLER); } else { refName.append(" - ", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$ refName.append(ObjectId.toString(ref.getObjectId()), StyledString.QUALIFIER_STYLER); } return refName; case WORKINGDIR: StyledString dirString = new StyledString(UIText.RepositoriesView_WorkingDir_treenode); dirString.append(" - ", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$ if (node.getRepository().isBare()) { dirString.append(UIText.RepositoriesViewLabelProvider_BareRepositoryMessage, StyledString.QUALIFIER_STYLER); } else { dirString.append(node.getRepository().getWorkTree().getAbsolutePath(), StyledString.QUALIFIER_STYLER); } return dirString; case PUSH: // fall through case FETCH: // fall through case FILE: // fall through case FOLDER: // fall through case BRANCHES: // fall through case LOCAL: // fall through case REMOTETRACKING: // fall through case BRANCHHIERARCHY: // fall through case TAGS: // fall through; case ADDITIONALREFS: // fall through case REMOTES: // fall through case REMOTE: // fall through case ERROR: // fall through case REF: // fall through case TAG: { String label = getSimpleText(node); if (label != null) return new StyledString(label); } } } catch (IOException e) { Activator.logError(e.getMessage(), e); } return null; }
From source file:org.eclipse.egit.ui.internal.repository.tree.command.GarbageCollectCommand.java
License:Open Source License
private String getRepositoryName(Repository repository) { File directory;// w w w . ja v a2 s . com if (!repository.isBare()) directory = repository.getDirectory().getParentFile(); else directory = repository.getDirectory(); StringBuilder sb = new StringBuilder(); sb.append(directory.getName()); sb.append(" - "); //$NON-NLS-1$ sb.append(directory.getAbsolutePath()); return sb.toString(); }
From source file:org.eclipse.egit.ui.internal.repository.tree.command.RemoveCommand.java
License:Open Source License
/** * Remove or delete the repository//from ww w . j a v a 2s. c o m * * @param event * @param delete * if <code>true</code>, the repository will be deleted from disk */ protected void removeRepository(final ExecutionEvent event, final boolean delete) { IWorkbenchSite activeSite = HandlerUtil.getActiveSite(event); IWorkbenchSiteProgressService service = (IWorkbenchSiteProgressService) activeSite .getService(IWorkbenchSiteProgressService.class); // get selected nodes final List<RepositoryNode> selectedNodes; try { selectedNodes = getSelectedNodes(event); } catch (ExecutionException e) { Activator.handleError(e.getMessage(), e, true); return; } if (delete) { String title = UIText.RemoveCommand_DeleteConfirmTitle; if (selectedNodes.size() > 1) { String message = NLS.bind(UIText.RemoveCommand_DeleteConfirmSingleMessage, Integer.valueOf(selectedNodes.size())); if (!MessageDialog.openConfirm(getShell(event), title, message)) return; } else if (selectedNodes.size() == 1) { String name = org.eclipse.egit.core.Activator.getDefault().getRepositoryUtil() .getRepositoryName(selectedNodes.get(0).getObject()); String message = NLS.bind(UIText.RemoveCommand_DeleteConfirmMultiMessage, name); if (!MessageDialog.openConfirm(getShell(event), title, message)) return; } } Job job = new Job("Remove Repositories Job") { //$NON-NLS-1$ @Override protected IStatus run(IProgressMonitor monitor) { final List<IProject> projectsToDelete = new ArrayList<IProject>(); monitor.setTaskName(UIText.RepositoriesView_DeleteRepoDeterminProjectsMessage); for (RepositoryNode node : selectedNodes) { if (node.getRepository().isBare()) continue; File workDir = node.getRepository().getWorkTree(); final IPath wdPath = new Path(workDir.getAbsolutePath()); for (IProject prj : ResourcesPlugin.getWorkspace().getRoot().getProjects()) { if (monitor.isCanceled()) return Status.OK_STATUS; if (wdPath.isPrefixOf(prj.getLocation())) { projectsToDelete.add(prj); } } } final boolean[] confirmedCanceled = new boolean[] { false, false }; if (!projectsToDelete.isEmpty()) { Display.getDefault().syncExec(new Runnable() { public void run() { try { confirmedCanceled[0] = confirmProjectDeletion(projectsToDelete, event); } catch (OperationCanceledException e) { confirmedCanceled[1] = true; } } }); } if (confirmedCanceled[1]) { // canceled: return return Status.OK_STATUS; } if (confirmedCanceled[0]) { // confirmed deletion IWorkspaceRunnable wsr = new IWorkspaceRunnable() { public void run(IProgressMonitor actMonitor) throws CoreException { for (IProject prj : projectsToDelete) prj.delete(false, false, actMonitor); } }; try { ResourcesPlugin.getWorkspace().run(wsr, ResourcesPlugin.getWorkspace().getRoot(), IWorkspace.AVOID_UPDATE, monitor); } catch (CoreException e1) { Activator.logError(e1.getMessage(), e1); } } for (RepositoryNode node : selectedNodes) { util.removeDir(node.getRepository().getDirectory()); } if (delete) { try { for (RepositoryNode node : selectedNodes) { Repository repo = node.getRepository(); if (!repo.isBare()) FileUtils.delete(repo.getWorkTree(), FileUtils.RECURSIVE | FileUtils.RETRY); FileUtils.delete(repo.getDirectory(), FileUtils.RECURSIVE | FileUtils.RETRY | FileUtils.SKIP_MISSING); } } catch (IOException e) { return Activator.createErrorStatus(e.getMessage(), e); } } return Status.OK_STATUS; } }; service.schedule(job); }