Example usage for org.eclipse.jgit.lib Repository isValidRefName

List of usage examples for org.eclipse.jgit.lib Repository isValidRefName

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Repository isValidRefName.

Prototype

public static boolean isValidRefName(String refName) 

Source Link

Document

Check validity of a ref name.

Usage

From source file:org.eclipse.egit.gitflow.BranchNameValidator.java

License:Open Source License

/**
 * @param name/*from  www  .  j a  va  2  s .  co  m*/
 * @return Whether or not name would be a valid name for a branch.
 */
public static boolean isBranchNameValid(String name) {
    return Repository.isValidRefName(Constants.R_HEADS + name);
}

From source file:org.eclipse.egit.ui.internal.components.BranchNameNormalizer.java

License:Open Source License

/**
 * Creates a new {@link BranchNameNormalizer}.
 *
 * @param text/*from w  w  w .j  av a  2s.c o m*/
 *            {@link Text} to operate on
 * @param tooltipText
 *            to show on the bulb decorator
 */
public BranchNameNormalizer(Text text, String tooltipText) {
    KeyStroke stroke = UIUtils
            .getKeystrokeOfBestActiveBindingFor(IWorkbenchCommandConstants.EDIT_CONTENT_ASSIST);
    if (stroke == null) {
        stroke = KeyStroke.getInstance(SWT.MOD1, ' ');
    }
    decorator = UIUtils.addBulbDecorator(text, MessageFormat.format(tooltipText, stroke.format()));
    decorator.hide();
    ContentProposalAdapter proposer = new ContentProposalAdapter(text, new TextContentAdapter(), (c, p) -> {
        if (c.isEmpty() || Repository.isValidRefName(Constants.R_HEADS + c)) {
            return null;
        }
        String normalized = Repository.normalizeBranchName(c);
        if (normalized == null || normalized.isEmpty()) {
            return new ContentProposal[0];
        }
        return new ContentProposal[] { new ContentProposal(normalized) };
    }, stroke, BRANCH_NAME_NORMALIZER_ACTIVATION_CHARS);
    proposer.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    text.addVerifyListener(e -> e.text = e.text.replaceAll(REGEX_BLANK, UNDERSCORE));
    text.addModifyListener(e -> {
        String input = text.getText();
        boolean doProposeCorrection = !input.isEmpty() && !Repository.isValidRefName(Constants.R_HEADS + input);
        setVisible(doProposeCorrection);
    });
}

From source file:org.eclipse.egit.ui.internal.components.RefSpecPanel.java

License:Open Source License

private static boolean isValidRefExpression(final String s) {
    if (RefSpec.isWildcard(s)) {
        // replace wildcard with some legal name just for checking
        return Repository.isValidRefName(s.substring(0, s.length() - 1) + 'X');
    } else//from   w  w  w.j  a  v a 2s.com
        return Repository.isValidRefName(s);
}

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

License:Open Source License

private void validateInput() {
    // don't validate if dialog is disposed
    if (getShell() == null) {
        return;/*from   w w  w .  j a  v a2 s.c  om*/
    }

    // validate tag name
    String tagNameMessage = tagNameValidator.isValid(tagNameText.getText());
    setErrorMessage(tagNameMessage);

    String tagMessageVal = tagMessageText.getText().trim();

    Control button = getButton(IDialogConstants.OK_ID);
    if (button != null) {
        boolean containsTagNameAndMessage = (tagNameMessage == null || tagMessageVal.length() == 0)
                && tagMessageVal.length() != 0;
        boolean shouldOverwriteTag = (overwriteButton.getSelection()
                && Repository.isValidRefName(Constants.R_TAGS + tagNameText.getText()));

        button.setEnabled(containsTagNameAndMessage || shouldOverwriteTag);
    }
}

From source file:org.eclipse.egit.ui.internal.push.AddRemotePage.java

License:Open Source License

private static boolean isValidRemoteName(String remoteName) {
    String testRef = Constants.R_REMOTES + remoteName + "/test"; //$NON-NLS-1$
    return Repository.isValidRefName(testRef);
}

From source file:org.eclipse.egit.ui.internal.push.PushBranchPage.java

License:Open Source License

private void checkPage() {
    try {//from   w  w  w.j av  a 2  s  .  c  o m
        if (remoteConfig == null) {
            setErrorMessage(UIText.PushBranchPage_ChooseRemoteError);
            return;
        }
        String branchName = remoteBranchNameText.getText();
        if (branchName.length() == 0) {
            setErrorMessage(
                    MessageFormat.format(UIText.PushBranchPage_ChooseBranchNameError, remoteConfig.getName()));
            return;
        }
        if (!Repository.isValidRefName(Constants.R_HEADS + branchName)) {
            setErrorMessage(UIText.PushBranchPage_InvalidBranchNameError);
            return;
        }
        if (getUpstreamConfig() != null && hasDifferentUpstreamConfiguration()) {
            setMessage(UIText.PushBranchPage_UpstreamConfigOverwriteWarning, IMessageProvider.WARNING);
        } else {
            setMessage(UIText.PushBranchPage_PageMessage);
        }
        setErrorMessage(null);
    } finally {
        setPageComplete(getErrorMessage() == null);
    }
}

From source file:org.eclipse.egit.ui.internal.ValidationUtils.java

License:Open Source License

/**
 * Creates and returns input validator for refNames
 *
 * @param repo//from  w  w w .ja  v a 2  s . c  o m
 * @param refPrefix
 * @param errorOnEmptyName
 * @return input validator for refNames
 */
public static IInputValidator getRefNameInputValidator(final Repository repo, final String refPrefix,
        final boolean errorOnEmptyName) {
    return new IInputValidator() {
        public String isValid(String newText) {
            if (newText.length() == 0) {
                if (errorOnEmptyName)
                    return UIText.ValidationUtils_PleaseEnterNameMessage;
                else
                    // ignore this
                    return null;
            }
            String testFor = refPrefix + newText;
            try {
                if (repo.resolve(testFor) != null)
                    return NLS.bind(UIText.ValidationUtils_RefAlreadyExistsMessage, testFor);
            } catch (IOException e1) {
                Activator.logError(NLS.bind(UIText.ValidationUtils_CanNotResolveRefMessage, testFor), e1);
                return e1.getMessage();
            }
            if (!Repository.isValidRefName(testFor))
                return NLS.bind(UIText.ValidationUtils_InvalidRefNameMessage, testFor);
            return null;
        }
    };
}

From source file:org.jfrog.bamboo.release.scm.git.DeleteTagCommand.java

License:Eclipse Distribution License

/**
 * Sets default values for not explicitly specified options. Then validates that all required data has been
 * provided.//  www  . ja va  2 s .c  o m
 *
 * @param state the state of the repository we are working on
 * @throws InvalidTagNameException       if the tag name is null or invalid
 * @throws UnsupportedOperationException if the tag is signed (not supported yet)
 */
private void processOptions(RepositoryState state) throws InvalidTagNameException {
    if (tagger == null) {
        tagger = new PersonIdent(repo);
    }
    if (name == null || !Repository.isValidRefName(Constants.R_TAGS + name)) {
        throw new InvalidTagNameException(
                MessageFormat.format(JGitText.get().tagNameInvalid, name == null ? "<null>" : name));
    }
    if (signed) {
        throw new UnsupportedOperationException(JGitText.get().signingNotSupportedOnTag);
    }
}

From source file:util.ChkoutCmd.java

License:Eclipse Distribution License

private void processOptions() throws InvalidRefNameException {
    if ((!checkoutAllPaths && paths.isEmpty())
            && (name == null || !Repository.isValidRefName(Constants.R_HEADS + name)))
        throw new InvalidRefNameException(
                MessageFormat.format(JGitText.get().branchNameInvalid, name == null ? "<null>" : name)); //$NON-NLS-1$
}