List of usage examples for org.eclipse.jgit.lib Repository getFullBranch
@Nullable public String getFullBranch() throws IOException
From source file:org.eclipse.egit.ui.internal.dialogs.BranchSelectionAndEditDialog.java
License:Open Source License
/** * @param parentShell//from ww w . j a v a 2 s . com * @param repo * @param refToMark * @param settings */ public BranchSelectionAndEditDialog(Shell parentShell, Repository repo, String refToMark, int settings) { super(parentShell, repo, refToMark, settings); try { currentBranch = repo.getFullBranch(); } catch (IOException e) { currentBranch = null; } }
From source file:org.eclipse.egit.ui.internal.dialogs.CheckoutDialog.java
License:Open Source License
/** * @param parentShell/*from ww w . j a v a 2 s. c o m*/ * @param repo */ public CheckoutDialog(Shell parentShell, Repository repo) { super(parentShell, repo, SHOW_LOCAL_BRANCHES | SHOW_REMOTE_BRANCHES | SHOW_TAGS | SHOW_REFERENCES | EXPAND_LOCAL_BRANCHES_NODE | ALLOW_MULTISELECTION); try { currentBranch = repo.getFullBranch(); } catch (IOException e) { currentBranch = null; } }
From source file:org.eclipse.egit.ui.internal.dialogs.DeleteBranchDialog.java
License:Open Source License
/** * @param parentShell/*from w ww.j a v a 2s. c om*/ * @param repo */ public DeleteBranchDialog(Shell parentShell, Repository repo) { super(parentShell, repo, SHOW_LOCAL_BRANCHES | EXPAND_LOCAL_BRANCHES_NODE | SHOW_REMOTE_BRANCHES | ALLOW_MULTISELECTION); try { currentBranch = repo.getFullBranch(); } catch (IOException e) { // just ignore here } }
From source file:org.eclipse.egit.ui.internal.history.command.DeleteBranchOnCommitHandler.java
License:Open Source License
private List<Ref> getBranchesOfCommit(GitHistoryPage page, final Repository repo, boolean hideCurrentBranch) throws IOException { final List<Ref> branchesOfCommit = new ArrayList<Ref>(); IStructuredSelection selection = getSelection(page); if (selection.isEmpty()) return branchesOfCommit; PlotCommit commit = (PlotCommit) selection.getFirstElement(); String head = repo.getFullBranch(); int refCount = commit.getRefCount(); for (int i = 0; i < refCount; i++) { Ref ref = commit.getRef(i); String refName = ref.getName(); if (hideCurrentBranch && head != null && refName.equals(head)) continue; if (refName.startsWith(Constants.R_HEADS) || refName.startsWith(Constants.R_REMOTES)) branchesOfCommit.add(ref);// w w w .j av a 2 s . c o m } return branchesOfCommit; }
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());//from w ww. j a v a2 s.com 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/*from w w w . j a v a 2 s .com*/ id.setText(UIText.GitProjectPropertyPage_ValueUnbornBranch); } else id.setText(objectId.name()); }
From source file:org.eclipse.egit.ui.internal.pull.PullWizardPage.java
License:Open Source License
/** * Create the page.//from w w w .j a va 2s. co m * * @param repository */ public PullWizardPage(Repository repository) { super(UIText.PullWizardPage_PageName); setTitle(UIText.PullWizardPage_PageTitle); setMessage(UIText.PullWizardPage_PageMessage); setImageDescriptor(UIIcons.WIZBAN_PULL); this.repository = repository; try { this.head = repository.findRef(Constants.HEAD); this.fullBranch = repository.getFullBranch(); } catch (IOException ex) { Activator.logError(ex.getMessage(), ex); } }
From source file:org.eclipse.egit.ui.internal.repository.tree.command.MergeCommand.java
License:Open Source License
public Object execute(final ExecutionEvent event) throws ExecutionException { RepositoryTreeNode node = getSelectedNodes(event).get(0); final Repository repository = node.getRepository(); if (!canMerge(repository)) return null; String targetRef;//from w w w . j av a2s. c o m if (node instanceof RefNode) { String refName = ((RefNode) node).getObject().getName(); try { if (repository.getFullBranch().equals(refName)) targetRef = null; else targetRef = refName; } catch (IOException e) { targetRef = null; } } else if (node instanceof TagNode) targetRef = ((TagNode) node).getObject().getName(); else targetRef = null; final String refName; if (targetRef != null) refName = targetRef; else { MergeTargetSelectionDialog mergeTargetSelectionDialog = new MergeTargetSelectionDialog(getShell(event), repository); if (mergeTargetSelectionDialog.open() == IDialogConstants.OK_ID) { refName = mergeTargetSelectionDialog.getRefName(); } else { return null; } } String jobname = NLS.bind(UIText.MergeAction_JobNameMerge, refName); final MergeOperation op = new MergeOperation(repository, refName); Job job = new Job(jobname) { @Override protected IStatus run(IProgressMonitor monitor) { try { op.execute(monitor); } catch (final CoreException e) { return e.getStatus(); } return Status.OK_STATUS; } }; job.setUser(true); job.setRule(op.getSchedulingRule()); job.addJobChangeListener(new JobChangeAdapter() { @Override public void done(IJobChangeEvent jobEvent) { IStatus result = jobEvent.getJob().getResult(); if (result.getSeverity() == IStatus.CANCEL) { Display.getDefault().asyncExec(new Runnable() { public void run() { // don't use getShell(event) here since // the active shell has changed since the // execution has been triggered. Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); MessageDialog.openInformation(shell, UIText.MergeAction_MergeCanceledTitle, UIText.MergeAction_MergeCanceledMessage); } }); } else if (!result.isOK()) { Activator.handleError(result.getMessage(), result.getException(), true); } else { Display.getDefault().asyncExec(new Runnable() { public void run() { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); new MergeResultDialog(shell, repository, op.getResult()).open(); } }); } } }); job.schedule(); return null; }
From source file:org.eclipse.egit.ui.internal.repository.tree.PropertyTester.java
License:Open Source License
/** * TODO javadoc missing//from w w w.j a va 2 s. c om */ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { if (!(receiver instanceof RepositoryTreeNode)) return false; RepositoryTreeNode node = (RepositoryTreeNode) receiver; if (property.equals("isBare")) { //$NON-NLS-1$ Repository rep = node.getRepository(); return rep.getConfig().getBoolean("core", "bare", false); //$NON-NLS-1$//$NON-NLS-2$ } if (property.equals("isRefCheckedOut")) { //$NON-NLS-1$ if (!(node.getObject() instanceof Ref)) return false; Ref ref = (Ref) node.getObject(); try { return ref.getName().equals(node.getRepository().getFullBranch()); } catch (IOException e) { return false; } } if (property.equals("isLocalBranch")) { //$NON-NLS-1$ if (!(node.getObject() instanceof Ref)) return false; Ref ref = (Ref) node.getObject(); return ref.getName().startsWith(Constants.R_HEADS); } if (property.equals("fetchExists")) { //$NON-NLS-1$ if (node instanceof RemoteNode) { String configName = ((RemoteNode) node).getObject(); RemoteConfig rconfig; try { rconfig = new RemoteConfig(node.getRepository().getConfig(), configName); } catch (URISyntaxException e2) { // TODO Exception handling rconfig = null; } boolean fetchExists = rconfig != null && !rconfig.getURIs().isEmpty(); return fetchExists; } } if (property.equals("pushExists")) { //$NON-NLS-1$ if (node instanceof RemoteNode) { String configName = ((RemoteNode) node).getObject(); RemoteConfig rconfig; try { rconfig = new RemoteConfig(node.getRepository().getConfig(), configName); } catch (URISyntaxException e2) { // TODO Exception handling rconfig = null; } boolean pushExists = rconfig != null && !rconfig.getPushURIs().isEmpty(); return pushExists; } } if (property.equals("canMerge")) { //$NON-NLS-1$ Repository rep = node.getRepository(); try { return rep.getFullBranch().startsWith(Constants.R_HEADS); } catch (IOException e) { return false; } } return false; }
From source file:org.eclipse.egit.ui.internal.repository.tree.RepositoriesViewPropertyTester.java
License:Open Source License
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { if (!(receiver instanceof RepositoryTreeNode)) return false; RepositoryTreeNode node = (RepositoryTreeNode) receiver; if (property.equals("isBare")) //$NON-NLS-1$ return node.getRepository().isBare(); if (property.equals("isSafe")) //$NON-NLS-1$ return node.getRepository().getRepositoryState() == RepositoryState.SAFE; if (property.equals("isRefCheckedOut")) { //$NON-NLS-1$ if (!(node.getObject() instanceof Ref)) return false; Ref ref = (Ref) node.getObject(); try {/*from ww w .j a va 2 s. c om*/ if (ref.getName().startsWith(Constants.R_REFS)) { return ref.getName().equals(node.getRepository().getFullBranch()); } else if (ref.getName().equals(Constants.HEAD)) return true; else { String leafname = ref.getLeaf().getName(); if (leafname.startsWith(Constants.R_REFS) && leafname.equals(node.getRepository().getFullBranch())) return true; else ref.getLeaf().getObjectId().equals(node.getRepository().resolve(Constants.HEAD)); } } catch (IOException e) { return false; } } if (property.equals("isLocalBranch")) { //$NON-NLS-1$ if (!(node.getObject() instanceof Ref)) return false; Ref ref = (Ref) node.getObject(); return ref.getName().startsWith(Constants.R_HEADS); } if (property.equals("fetchExists")) { //$NON-NLS-1$ if (node instanceof RemoteNode) { String configName = ((RemoteNode) node).getObject(); RemoteConfig rconfig; try { rconfig = new RemoteConfig(node.getRepository().getConfig(), configName); } catch (URISyntaxException e2) { return false; } // we need to have a fetch ref spec and a fetch URI return !rconfig.getFetchRefSpecs().isEmpty() && !rconfig.getURIs().isEmpty(); } } if (property.equals("pushExists")) { //$NON-NLS-1$ if (node instanceof RemoteNode) { String configName = ((RemoteNode) node).getObject(); RemoteConfig rconfig; try { rconfig = new RemoteConfig(node.getRepository().getConfig(), configName); } catch (URISyntaxException e2) { return false; } // we need to have at least a push ref spec and any URI return !rconfig.getPushRefSpecs().isEmpty() && (!rconfig.getPushURIs().isEmpty() || !rconfig.getURIs().isEmpty()); } } if (property.equals("canMerge")) { //$NON-NLS-1$ Repository rep = node.getRepository(); if (rep.getRepositoryState() != RepositoryState.SAFE) return false; try { String branch = rep.getFullBranch(); if (branch == null) return false; // fail gracefully... return branch.startsWith(Constants.R_HEADS); } catch (IOException e) { return false; } } if (property.equals("canAbortRebase")) //$NON-NLS-1$ switch (node.getRepository().getRepositoryState()) { case REBASING_INTERACTIVE: return true; default: return false; } return false; }