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

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

Introduction

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

Prototype

String R_REMOTES

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

Click Source Link

Document

Prefix for remotes refs

Usage

From source file:org.eclipse.egit.ui.internal.dialogs.RenameBranchDialog.java

License:Open Source License

@Override
protected void okPressed() {
    String refName = refNameFromDialog();
    String refPrefix;/*from   w  w w.j  av  a2 s  .  c  o m*/

    if (refName.startsWith(Constants.R_HEADS))
        refPrefix = Constants.R_HEADS;
    else if (refName.startsWith(Constants.R_REMOTES))
        refPrefix = Constants.R_REMOTES;
    else if (refName.startsWith(Constants.R_TAGS))
        refPrefix = Constants.R_TAGS;
    else {
        // the button should be disabled anyway, but we check again
        return;
    }

    String branchName = refName.substring(refPrefix.length());

    InputDialog labelDialog = getRefNameInputDialog(
            NLS.bind(UIText.RenameBranchDialog_NewNameInputDialogPrompt, branchName, refPrefix), refPrefix,
            branchName);
    if (labelDialog.open() == Window.OK) {
        String newRefName = refPrefix + labelDialog.getValue();
        try {
            new Git(repo).branchRename().setOldName(refName).setNewName(labelDialog.getValue()).call();
            branchTree.refresh();
            markRef(newRefName);
        } catch (Throwable e1) {
            reportError(e1, UIText.RenameBranchDialog_RenameErrorMessage, refName, newRefName, e1.getMessage());
        }
    }
    super.okPressed();
}

From source file:org.eclipse.egit.ui.internal.dialogs.RenameBranchDialog.java

License:Open Source License

@Override
protected void refNameSelected(String refName) {
    boolean tagSelected = refName != null && refName.startsWith(Constants.R_TAGS);

    boolean branchSelected = refName != null
            && (refName.startsWith(Constants.R_HEADS) || refName.startsWith(Constants.R_REMOTES));

    getButton(Window.OK).setEnabled(branchSelected || tagSelected);
}

From source file:org.eclipse.egit.ui.internal.fetch.FetchDestinationPage.java

License:Open Source License

@Override
public void setVisible(boolean visible) {
    super.setVisible(visible);
    if (visible) {
        FetchSourcePage fsp = (FetchSourcePage) getWizard().getPreviousPage(this);
        String sourceString = fsp.getSource();
        sourceText.setText(sourceString);
        if (sourceString.length() > 0) {
            destinationText.setText(//from   www  .j a v  a  2 s  .  c  o m
                    Constants.R_REMOTES + config.getName() + '/' + Repository.shortenRefName(sourceString));
        }
        destinationText.setFocus();
    }
}

From source file:org.eclipse.egit.ui.internal.fetch.FetchDestinationPage.java

License:Open Source License

private List<Ref> getRemoteRefs() {
    if (this.trackingBranches == null) {
        List<Ref> proposals = new ArrayList<Ref>();
        try {//from  ww w. j av a2s . c  om
            for (Ref ref : repository.getRefDatabase().getRefs(Constants.R_REMOTES).values()) {
                proposals.add(ref);
            }
            this.trackingBranches = proposals;
        } catch (IOException e) {
            setErrorMessage(UIText.FetchDestinationPage_CouldNotGetBranchesMessage);
        }
    }
    return this.trackingBranches;
}

From source file:org.eclipse.egit.ui.internal.fetch.SimpleConfigureFetchDialog.java

License:Open Source License

/**
 * @param shell//from www .java 2  s .c  om
 * @param repository
 * @param config
 * @param showBranchInfo
 *            should be true if this is used for upstream configuration; if
 *            false, branch information will be hidden in the dialog
 */
private SimpleConfigureFetchDialog(Shell shell, Repository repository, RemoteConfig config,
        boolean showBranchInfo) {
    super(shell);
    setHelpAvailable(false);
    setShellStyle(getShellStyle() | SWT.SHELL_TRIM);
    this.repository = repository;
    this.config = config;
    this.showBranchInfo = showBranchInfo;

    // Add default fetch ref spec if this is a new remote config
    if (config.getFetchRefSpecs().isEmpty() && !repository.getConfig()
            .getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION).contains(config.getName())) {
        StringBuilder defaultRefSpec = new StringBuilder();
        defaultRefSpec.append('+');
        defaultRefSpec.append(Constants.R_HEADS);
        defaultRefSpec.append('*').append(':');
        defaultRefSpec.append(Constants.R_REMOTES);
        defaultRefSpec.append(config.getName());
        defaultRefSpec.append(RefSpec.WILDCARD_SUFFIX);
        config.addFetchRefSpec(new RefSpec(defaultRefSpec.toString()));
    }
}

From source file:org.eclipse.egit.ui.internal.gerrit.GerritConfigurationPage.java

License:Open Source License

private void addRefContentProposalToText(final Text textField) {
    KeyStroke stroke;/*from   w w  w  .  ja v  a 2  s  .c o m*/
    try {
        stroke = KeyStroke.getInstance("CTRL+SPACE"); //$NON-NLS-1$
        UIUtils.addBulbDecorator(textField,
                NLS.bind(UIText.GerritConfigurationPage_BranchTooltipHover, stroke.format()));
    } catch (ParseException e1) {
        Activator.handleError(e1.getMessage(), e1, false);
        stroke = null;
    }

    IContentProposalProvider cp = new IContentProposalProvider() {
        public IContentProposal[] getProposals(String contents, int position) {
            List<IContentProposal> resultList = new ArrayList<IContentProposal>();

            // make the simplest possible pattern check: allow "*"
            // for multiple characters
            String patternString = contents;
            // ignore spaces in the beginning
            while (patternString.length() > 0 && patternString.charAt(0) == ' ') {
                patternString = patternString.substring(1);
            }

            // we quote the string as it may contain spaces
            // and other stuff colliding with the Pattern
            patternString = Pattern.quote(patternString);

            patternString = patternString.replaceAll("\\x2A", ".*"); //$NON-NLS-1$ //$NON-NLS-2$

            // make sure we add a (logical) * at the end
            if (!patternString.endsWith(".*")) //$NON-NLS-1$
                patternString = patternString + ".*"; //$NON-NLS-1$

            // let's compile a case-insensitive pattern (assumes ASCII only)
            Pattern pattern;
            try {
                pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);
            } catch (PatternSyntaxException e) {
                pattern = null;
            }

            Set<String> proposals = new TreeSet<String>();

            try {
                // propose the names of the remote tracking
                // branches for the given remote
                Set<String> remotes = repository.getRefDatabase()
                        .getRefs(Constants.R_REMOTES + remoteName + "/").keySet(); //$NON-NLS-1$
                proposals.addAll(remotes);
            } catch (IOException e) {
                // simply ignore, no proposals then
            }

            for (final String proposal : proposals) {
                if (pattern != null && !pattern.matcher(proposal).matches())
                    continue;
                IContentProposal propsal = new BranchContentProposal(proposal);
                resultList.add(propsal);
            }

            return resultList.toArray(new IContentProposal[resultList.size()]);
        }
    };

    ContentProposalAdapter adapter = new ContentProposalAdapter(textField, new TextContentAdapter(), cp, stroke,
            null);
    // set the acceptance style to always replace the complete content
    adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
}

From source file:org.eclipse.egit.ui.internal.history.command.AbstractRebaseHistoryCommandHandler.java

License:Open Source License

/**
 * @param commit/*from  ww w  .j a v a 2s  .c o  m*/
 * @param repository
 * @param currentBranch
 * @return ref pointing to the given commit, prefers tracking branch if
 *         multiple refs are available
 */
protected Ref getRef(PlotCommit commit, Repository repository, String currentBranch) {
    int count = commit.getRefCount();
    if (count == 0)
        return new ObjectIdRef.Unpeeled(Storage.LOOSE, commit.getName(), commit);
    else if (count == 1)
        return commit.getRef(0);
    else {
        BranchConfig branchConfig = new BranchConfig(repository.getConfig(), currentBranch);
        String trackingBranch = branchConfig.getTrackingBranch();
        Ref remoteRef = null;

        for (int i = 0; i < count; i++) {
            Ref ref = commit.getRef(i);
            if (trackingBranch != null && trackingBranch.equals(ref.getName()))
                return ref;
            if (ref.getName().startsWith(Constants.R_REMOTES))
                remoteRef = ref;
        }

        if (remoteRef != null)
            return remoteRef;
        else
            // We tried to pick a nice ref, just pick the first then
            return commit.getRef(0);
    }
}

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);//from   w w  w  .  j a va2s .c  o m
    }
    return branchesOfCommit;
}

From source file:org.eclipse.egit.ui.internal.history.command.RebaseCurrentHandler.java

License:Open Source License

private Ref getRef(PlotCommit commit, Repository repository, String currentBranch) {
    int count = commit.getRefCount();
    if (count == 0)
        return new ObjectIdRef.Unpeeled(Storage.LOOSE, commit.getName(), commit);
    else if (count == 1)
        return commit.getRef(0);
    else {//from w ww . j  av a  2s . c  o  m
        BranchConfig branchConfig = new BranchConfig(repository.getConfig(), currentBranch);
        String trackingBranch = branchConfig.getTrackingBranch();
        Ref remoteRef = null;

        for (int i = 0; i < count; i++) {
            Ref ref = commit.getRef(i);
            if (trackingBranch != null && trackingBranch.equals(ref.getName()))
                return ref;
            if (ref.getName().startsWith(Constants.R_REMOTES))
                remoteRef = ref;
        }

        if (remoteRef != null)
            return remoteRef;
        else
            // We tried to pick a nice ref, just pick the first then
            return commit.getRef(0);
    }
}

From source file:org.eclipse.egit.ui.internal.history.command.RenameBranchOnCommitHandler.java

License:Open Source License

private List<Ref> getBranchesOfCommit(GitHistoryPage page) {
    final List<Ref> branchesOfCommit = new ArrayList<Ref>();
    IStructuredSelection selection = getSelection(page);
    if (selection.isEmpty())
        return branchesOfCommit;
    PlotCommit commit = (PlotCommit) selection.getFirstElement();

    int refCount = commit.getRefCount();
    for (int i = 0; i < refCount; i++) {
        Ref ref = commit.getRef(i);
        String refName = ref.getName();
        if (refName.startsWith(Constants.R_HEADS) || refName.startsWith(Constants.R_REMOTES))
            branchesOfCommit.add(ref);//from   ww  w . j  a  v a2s.c  o  m
    }
    return branchesOfCommit;
}