Example usage for org.eclipse.jgit.lib Constants R_HEADS

List of usage examples for org.eclipse.jgit.lib Constants R_HEADS

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Constants R_HEADS.

Prototype

String R_HEADS

To view the source code for org.eclipse.jgit.lib Constants R_HEADS.

Click Source Link

Document

Prefix for branch refs

Usage

From source file:org.eclipse.egit.ui.gitflow.InitHandlerTest.java

License:Open Source License

@Test
public void testInitMissingMaster() throws Exception {
    selectProject(PROJ1);//  w w  w  .j  a v a2 s.  co  m
    clickInit();
    fillDialog(MASTER_BRANCH_MISSING);

    bot.waitUntil(shellIsActive(UIText.InitDialog_masterBranchIsMissing));
    bot.button("Yes").click();
    bot.waitUntil(Conditions.waitForJobs(JobFamilies.GITFLOW_FAMILY, "Git flow jobs"));

    GitFlowRepository gitFlowRepository = new GitFlowRepository(repository);
    GitFlowConfig config = gitFlowRepository.getConfig();

    assertEquals(DEVELOP_BRANCH, repository.getBranch());
    assertEquals(MASTER_BRANCH_MISSING, config.getMaster());
    assertEquals(FEATURE_BRANCH_PREFIX, config.getFeaturePrefix());
    assertEquals(RELEASE_BRANCH_PREFIX, config.getReleasePrefix());
    assertEquals(HOTFIX_BRANCH_PREFIX, config.getHotfixPrefix());
    assertEquals(VERSION_TAG_PREFIX, config.getVersionTagPrefix());

    assertNotNull(repository.exactRef(Constants.R_HEADS + DEVELOP_BRANCH));
}

From source file:org.eclipse.egit.ui.gitflow.InitHandlerTest.java

License:Open Source License

@Test
public void testInitEmptyRepoMissingMaster() throws Exception {
    String projectName = "AnyProjectName";
    TestRepository testRepository = createAndShare(projectName);

    selectProject(projectName);//from   w w w.ja  v  a  2  s.co  m
    clickInit();
    bot.button("Yes").click();
    fillDialog(MASTER_BRANCH_MISSING);
    bot.waitUntil(shellIsActive(UIText.InitDialog_masterBranchIsMissing));
    bot.button("Yes").click();
    bot.waitUntil(Conditions.waitForJobs(JobFamilies.GITFLOW_FAMILY, "Git flow jobs"));

    Repository localRepository = testRepository.getRepository();
    GitFlowRepository gitFlowRepository = new GitFlowRepository(localRepository);
    GitFlowConfig config = gitFlowRepository.getConfig();

    assertEquals(DEVELOP_BRANCH, localRepository.getBranch());
    assertEquals(MASTER_BRANCH_MISSING, config.getMaster());
    assertEquals(FEATURE_BRANCH_PREFIX, config.getFeaturePrefix());
    assertEquals(RELEASE_BRANCH_PREFIX, config.getReleasePrefix());
    assertEquals(HOTFIX_BRANCH_PREFIX, config.getHotfixPrefix());
    assertEquals(VERSION_TAG_PREFIX, config.getVersionTagPrefix());

    assertNotNull(localRepository.exactRef(Constants.R_HEADS + DEVELOP_BRANCH));
}

From source file:org.eclipse.egit.ui.httpauth.PushTest.java

License:Open Source License

@Before
public void setup() throws Exception {
    TestUtil.disableProxy();//from w  w  w.  j  av  a2  s .  c om
    remoteRepository = new SampleTestRepository(NUMBER_RANDOM_COMMITS, true);
    localRepoPath = new File(ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile(),
            "test" + System.nanoTime());
    String branch = Constants.R_HEADS + SampleTestRepository.FIX;
    CloneOperation cloneOperation = new CloneOperation(new URIish(remoteRepository.getUri()), true, null,
            localRepoPath, branch, "origin", 30);
    cloneOperation.setCredentialsProvider(new UsernamePasswordCredentialsProvider("agitter", "letmein"));
    cloneOperation.run(null);
    file = new File(localRepoPath, SampleTestRepository.A_txt_name);
    assertTrue(file.exists());
    localRepository = Activator.getDefault().getRepositoryCache()
            .lookupRepository(new File(localRepoPath, ".git"));
    assertNotNull(localRepository);
}

From source file:org.eclipse.egit.ui.internal.actions.PushBranchActionHandler.java

License:Open Source License

private Ref getBranchRef(Repository repository) {
    try {//from  ww w  .  j a v  a  2 s  .  c om
        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  . jav  a  2 s.com
                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   www.j  av a2 s  . c  om*/
    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  www.jav a  2 s. 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.clone.CloneDestinationPage.java

License:Open Source License

/**
 * @return initial branch selected (includes refs/heads prefix).
 *//*  w  w  w .  j a va  2s  .  co m*/
public String getInitialBranch() {
    final int ix = initialBranch.getSelectionIndex();
    if (ix < 0)
        return Constants.R_HEADS + Constants.MASTER;
    return Constants.R_HEADS + initialBranch.getItem(ix);
}

From source file:org.eclipse.egit.ui.internal.clone.CloneDestinationPage.java

License:Open Source License

private void revalidate(RepositorySelection repoSelection, List<Ref> branches, Ref head) {
    if (repoSelection.equals(validatedRepoSelection) && branches.equals(validatedSelectedBranches)
            && head.equals(validatedHEAD)) {
        checkPage();/*  w  ww .j  a  va  2  s .co m*/
        return;
    }

    if (!repoSelection.equals(validatedRepoSelection)) {
        validatedRepoSelection = repoSelection;
        // update repo-related selection only if it changed
        final String n = validatedRepoSelection.getURI().getHumanishName();
        setDescription(NLS.bind(UIText.CloneDestinationPage_description, n));
        String destinationDir = Activator.getDefault().getPreferenceStore()
                .getString(UIPreferences.DEFAULT_REPO_DIR);
        File parentDir = new File(destinationDir);
        if (!parentDir.exists() || !parentDir.isDirectory()) {
            parentDir = ResourcesPlugin.getWorkspace().getRoot().getRawLocation().toFile();
        }
        directoryText.setText(new File(parentDir, n).getAbsolutePath());
    }

    validatedSelectedBranches = branches;
    validatedHEAD = head;

    initialBranch.removeAll();
    final Ref actHead = head;
    int newix = 0;
    for (final Ref r : branches) {
        String name = r.getName();
        if (name.startsWith(Constants.R_HEADS))
            name = name.substring((Constants.R_HEADS).length());
        if (actHead != null && actHead.getName().equals(r.getName()))
            newix = initialBranch.getItemCount();
        initialBranch.add(name);
    }
    initialBranch.select(newix);
    checkPage();
}

From source file:org.eclipse.egit.ui.internal.clone.SourceBranchPage.java

License:Open Source License

public void createControl(final Composite parent) {
    final Composite panel = new Composite(parent, SWT.NULL);
    final GridLayout layout = new GridLayout();
    layout.numColumns = 1;/*from  ww w  .j a  v a  2 s .  com*/
    panel.setLayout(layout);

    label = new Label(panel, SWT.NONE);
    label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

    Table refsTable = new Table(panel, SWT.CHECK | SWT.V_SCROLL | SWT.BORDER);
    refsTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    refsViewer = new CheckboxTableViewer(refsTable);
    refsViewer.setContentProvider(ArrayContentProvider.getInstance());
    refsViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((Ref) element).getName().substring(Constants.R_HEADS.length());
        }

        @Override
        public Image getImage(Object element) {
            return RepositoryTreeNodeType.REF.getIcon();
        }
    });

    refsViewer.addCheckStateListener(new ICheckStateListener() {
        public void checkStateChanged(CheckStateChangedEvent event) {
            checkPage();
        }
    });
    final Composite bPanel = new Composite(panel, SWT.NONE);
    bPanel.setLayout(new RowLayout());
    selectB = new Button(bPanel, SWT.PUSH);
    selectB.setText(UIText.SourceBranchPage_selectAll);
    selectB.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            refsViewer.setAllChecked(true);
            checkPage();
        }
    });
    unselectB = new Button(bPanel, SWT.PUSH);
    unselectB.setText(UIText.SourceBranchPage_selectNone);
    unselectB.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            refsViewer.setAllChecked(false);
            checkPage();
        }
    });
    bPanel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

    Dialog.applyDialogFont(panel);
    setControl(panel);
    checkPage();
}