List of usage examples for org.eclipse.jgit.lib Repository getFullBranch
@Nullable public String getFullBranch() throws IOException
From source file:org.eclipse.egit.gitflow.op.ReleaseStartOperationTest.java
License:Open Source License
@Test public void testReleaseStartFailed() throws Exception { testRepository.createInitialCommit("testReleaseStart\n\nfirst commit\n"); Repository repository = testRepository.getRepository(); new InitOperation(repository).execute(null); GitFlowRepository gfRepo = new GitFlowRepository(repository); createTag(gfRepo.findHead(), MY_RELEASE, "irrelevant", repository); try {/*from w w w . j ava 2s .c o m*/ new ReleaseStartOperation(gfRepo, MY_RELEASE).execute(null); fail(); } catch (CoreException e) { assertEquals(gfRepo.getConfig().getDevelopFull(), repository.getFullBranch()); } }
From source file:org.eclipse.egit.gitflow.ui.internal.dialogs.FeatureBranchSelectionDialog.java
License:Open Source License
private void checkPage() { List<Ref> selection = filteredFeatures.getSelection(); if (selection.isEmpty() || selection.get(0) == null) { getButton(OK).setEnabled(false); return;//from w w w . j a va 2 s. c om } Repository repository = gfRepo.getRepository(); try { Ref currentBranch = repository.exactRef(repository.getFullBranch()); getButton(OK).setEnabled(!selection.get(0).equals(currentBranch)); } catch (IOException e) { Activator.logError("Unable to find current branch", e); //$NON-NLS-1$ } }
From source file:org.eclipse.egit.ui.internal.actions.PullFromUpstreamActionHandler.java
License:Open Source License
@Override public boolean isEnabled() { // we don't do the full canMerge check here, but // ensure that a branch is checked out Repository repo = getRepository(); if (repo == null) return false; try {// www .j a v a2s .com String fullBranch = repo.getFullBranch(); return (fullBranch.startsWith(Constants.R_REFS)); } catch (IOException e) { return false; } }
From source file:org.eclipse.egit.ui.internal.actions.PushBranchActionHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { Repository repository = getRepository(true, event); try {//from w ww. j a v a2 s.c o m PushBranchWizard wizard = null; Ref ref = getBranchRef(repository); if (ref != null) { wizard = new PushBranchWizard(repository, ref); } else { ObjectId id = repository.resolve(repository.getFullBranch()); wizard = new PushBranchWizard(repository, id); } WizardDialog dlg = new WizardDialog(getShell(event), wizard); dlg.open(); } catch (IOException ex) { Activator.handleError(ex.getLocalizedMessage(), ex, false); } return null; }
From source file:org.eclipse.egit.ui.internal.actions.PushBranchActionHandler.java
License:Open Source License
private Ref getBranchRef(Repository repository) { try {/*ww w. ja v a2 s. co m*/ String fullBranch = repository.getFullBranch(); if (fullBranch != null && fullBranch.startsWith(Constants.R_HEADS)) return repository.exactRef(fullBranch); } catch (IOException e) { Activator.handleError(e.getLocalizedMessage(), e, false); } return null; }
From source file:org.eclipse.egit.ui.internal.actions.PushMenu.java
License:Open Source License
@Override protected IContributionItem[] getContributionItems() { List<IContributionItem> res = new ArrayList<>(); if (this.handlerService != null) { Repository repository = SelectionUtils.getRepository(handlerService.getCurrentState()); if (repository != null) { try { String ref = repository.getFullBranch(); String menuLabel = UIText.PushMenu_PushHEAD; if (ref != null && ref.startsWith(Constants.R_HEADS)) { menuLabel = NLS.bind(UIText.PushMenu_PushBranch, Repository.shortenRefName(ref)); }/*from w w w .j a va 2 s. co m*/ CommandContributionItemParameter params = new CommandContributionItemParameter( this.serviceLocator, getClass().getName(), ActionCommands.PUSH_BRANCH_ACTION, CommandContributionItem.STYLE_PUSH); params.label = menuLabel; CommandContributionItem item = new CommandContributionItem(params); res.add(item); } catch (IOException ex) { Activator.handleError(ex.getLocalizedMessage(), ex, false); } } } return res.toArray(new IContributionItem[res.size()]); }
From source file:org.eclipse.egit.ui.internal.actions.SwitchToMenu.java
License:Open Source License
private void createDynamicMenu(Menu menu, final Repository repository) { MenuItem newBranch = new MenuItem(menu, SWT.PUSH); newBranch.setText(UIText.SwitchToMenu_NewBranchMenuLabel); newBranch.setImage(newBranchImage);//from ww w. j a v a2 s .co m newBranch.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { BranchOperationUI.create(repository).start(); } }); new MenuItem(menu, SWT.SEPARATOR); try { String currentBranch = repository.getFullBranch(); Map<String, Ref> localBranches = repository.getRefDatabase().getRefs(Constants.R_HEADS); TreeMap<String, Ref> sortedRefs = new TreeMap<String, Ref>(); // Add the MAX_NUM_MENU_ENTRIES most recently used branches first List<ReflogEntry> reflogEntries = new ReflogReader(repository, Constants.HEAD).getReverseEntries(); for (ReflogEntry entry : reflogEntries) { CheckoutEntry checkout = entry.parseCheckout(); if (checkout != null) { Ref ref = localBranches.get(checkout.getFromBranch()); if (ref != null) if (sortedRefs.size() < MAX_NUM_MENU_ENTRIES) sortedRefs.put(checkout.getFromBranch(), ref); ref = localBranches.get(checkout.getToBranch()); if (ref != null) if (sortedRefs.size() < MAX_NUM_MENU_ENTRIES) sortedRefs.put(checkout.getToBranch(), ref); } } // Add the recently used branches to the menu, in alphabetical order int itemCount = 0; for (final Entry<String, Ref> entry : sortedRefs.entrySet()) { itemCount++; final String shortName = entry.getKey(); final String fullName = entry.getValue().getName(); createMenuItem(menu, repository, currentBranch, fullName, shortName); // Do not duplicate branch names localBranches.remove(shortName); } if (itemCount < MAX_NUM_MENU_ENTRIES) { // A separator between recently used branches and local branches is // nice but only if we have both recently used branches and other // local branches if (itemCount > 0 && localBranches.size() > 0) new MenuItem(menu, SWT.SEPARATOR); // Now add more other branches if we have only a few branch switches // Sort the remaining local branches sortedRefs.clear(); sortedRefs.putAll(localBranches); for (final Entry<String, Ref> entry : sortedRefs.entrySet()) { itemCount++; // protect ourselves against a huge sub-menu if (itemCount > MAX_NUM_MENU_ENTRIES) break; final String fullName = entry.getValue().getName(); final String shortName = entry.getKey(); createMenuItem(menu, repository, currentBranch, fullName, shortName); } } if (itemCount > 0) new MenuItem(menu, SWT.SEPARATOR); MenuItem others = new MenuItem(menu, SWT.PUSH); others.setText(UIText.SwitchToMenu_OtherMenuLabel); others.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { BranchOperationUI.checkout(repository).start(); } }); } catch (IOException e) { Activator.handleError(e.getMessage(), e, true); } }
From source file:org.eclipse.egit.ui.internal.actions.SynchronizeWithMenu.java
License:Open Source License
@Override public void fill(final Menu menu, int index) { if (srv == null) return;//from w w w . java 2s . c o m final IResource selectedResource = getSelection(); if (selectedResource == null || selectedResource.isLinked(IResource.CHECK_ANCESTORS)) return; RepositoryMapping mapping = RepositoryMapping.getMapping(selectedResource.getProject()); if (mapping == null) return; final Repository repo = mapping.getRepository(); if (repo == null) return; List<Ref> refs = new LinkedList<Ref>(); RefDatabase refDatabase = repo.getRefDatabase(); try { refs.addAll(refDatabase.getAdditionalRefs()); } catch (IOException e) { // do nothing } try { refs.addAll(refDatabase.getRefs(RefDatabase.ALL).values()); } catch (IOException e) { // do nothing } Collections.sort(refs, CommonUtils.REF_ASCENDING_COMPARATOR); String currentBranch; try { currentBranch = repo.getFullBranch(); } catch (IOException e) { currentBranch = ""; //$NON-NLS-1$ } int count = 0; String oldName = null; int refsLength = R_REFS.length(); int tagsLength = R_TAGS.substring(refsLength).length(); for (Ref ref : refs) { final String name = ref.getName(); if (name.equals(Constants.HEAD) || name.equals(currentBranch) || excludeTag(ref, repo)) continue; if (name.startsWith(R_REFS) && oldName != null && !oldName.regionMatches(refsLength, name, refsLength, tagsLength)) new MenuItem(menu, SWT.SEPARATOR); MenuItem item = new MenuItem(menu, SWT.PUSH); item.setText(name); if (name.startsWith(Constants.R_TAGS)) item.setImage(tagImage); else if (name.startsWith(Constants.R_HEADS) || name.startsWith(Constants.R_REMOTES)) item.setImage(branchImage); item.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { GitSynchronizeData data; try { data = new GitSynchronizeData(repo, HEAD, name, true); if (!(selectedResource instanceof IProject)) { HashSet<IContainer> containers = new HashSet<IContainer>(); containers.add((IContainer) selectedResource); data.setIncludedPaths(containers); } GitModelSynchronize.launch(data, new IResource[] { selectedResource }); } catch (IOException e) { Activator.logError(e.getMessage(), e); } } }); if (++count == MAX_NUM_MENU_ENTRIES) break; oldName = name; } if (count > 1) new MenuItem(menu, SWT.SEPARATOR); MenuItem custom = new MenuItem(menu, SWT.PUSH); custom.setText(UIText.SynchronizeWithMenu_custom); custom.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { GitSynchronizeWizard gitWizard = new GitSynchronizeWizard(); WizardDialog wizard = new WizardDialog(menu.getShell(), gitWizard); wizard.create(); wizard.open(); } }); }
From source file:org.eclipse.egit.ui.internal.branch.BranchResultDialog.java
License:Open Source License
/** * @param result/* w w w . j a va 2 s. c o m*/ * the result to show * @param repository * @param target * the target (branch name or commit id) */ public static void show(final CheckoutResult result, final Repository repository, final String target) { BranchResultDialog.target = target; if (result.getStatus() == CheckoutResult.Status.CONFLICTS) PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { public void run() { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); new BranchResultDialog(shell, repository, result, target).open(); } }); else if (result.getStatus() == CheckoutResult.Status.NONDELETED) { // double-check if the files are still there boolean show = false; List<String> pathList = result.getUndeletedList(); for (String path : pathList) if (new File(repository.getWorkTree(), path).exists()) { show = true; break; } if (!show) return; PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { public void run() { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); new NonDeletedFilesDialog(shell, repository, result.getUndeletedList()).open(); } }); } else if (result.getStatus() == CheckoutResult.Status.OK) { try { if (ObjectId.isId(repository.getFullBranch())) showDetachedHeadWarning(); } catch (IOException e) { Activator.logError(e.getMessage(), e); } } }
From source file:org.eclipse.egit.ui.internal.commands.shared.RebaseCurrentRefCommand.java
License:Open Source License
public Object execute(ExecutionEvent event) throws ExecutionException { Ref ref;//from www . j av a 2 s.c o m ISelection currentSelection = getCurrentSelectionChecked(event); if (currentSelection instanceof IStructuredSelection) { IStructuredSelection selection = (IStructuredSelection) currentSelection; Object selected = selection.getFirstElement(); ref = getRef(selected); } else ref = null; final Repository repository = getRepository(event); if (repository == null) return null; BasicConfigurationDialog.show(repository); try { if (ref != null && ref.getName().equals(repository.getFullBranch())) ref = null; } catch (IOException ignored) { // Ignored } if (ref == null) { RebaseTargetSelectionDialog rebaseTargetSelectionDialog = new RebaseTargetSelectionDialog( getShell(event), repository); if (rebaseTargetSelectionDialog.open() == IDialogConstants.OK_ID) { String refName = rebaseTargetSelectionDialog.getRefName(); try { ref = repository.getRef(refName); } catch (IOException e) { throw new ExecutionException(e.getMessage(), e); } } else return null; } String jobname = NLS.bind(UIText.RebaseCurrentRefCommand_RebasingCurrentJobName, ref.getName()); RebaseHelper.runRebaseJob(repository, jobname, ref); return null; }