Example usage for org.eclipse.jgit.transport RefSpec expandFromSource

List of usage examples for org.eclipse.jgit.transport RefSpec expandFromSource

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport RefSpec expandFromSource.

Prototype

public RefSpec expandFromSource(Ref r) 

Source Link

Document

Expand this specification to exactly match a ref.

Usage

From source file:com.google.gerrit.server.git.PushOp.java

License:Apache License

private RefSpec matchSrc(final String ref) {
    for (final RefSpec s : config.getPushRefSpecs()) {
        if (s.matchSource(ref)) {
            return s.expandFromSource(ref);
        }/*w ww  .j  a  va  2 s .c o  m*/
    }
    return null;
}

From source file:com.googlesource.gerrit.plugins.replication.PushOne.java

License:Apache License

private RefSpec matchSrc(String ref) {
    for (RefSpec s : config.getPushRefSpecs()) {
        if (s.matchSource(ref)) {
            return s.expandFromSource(ref);
        }/*from w w w.java  2 s . co m*/
    }
    return null;
}

From source file:org.eclipse.egit.core.op.CloneOperation.java

License:Open Source License

private void doInit(final IProgressMonitor monitor) throws URISyntaxException, IOException {
    monitor.setTaskName(CoreText.CloneOperation_initializingRepository);

    local = new FileRepository(gitdir);
    local.create();//ww  w.  j  av a 2 s.  c om

    final RefUpdate head = local.updateRef(Constants.HEAD);
    head.disableRefLog();
    head.link(branch);

    remoteConfig = new RemoteConfig(local.getConfig(), remoteName);
    remoteConfig.addURI(uri);

    final String dst = Constants.R_REMOTES + remoteConfig.getName();
    RefSpec wcrs = new RefSpec();
    wcrs = wcrs.setForceUpdate(true);
    wcrs = wcrs.setSourceDestination(Constants.R_HEADS + "*", dst + "/*"); //$NON-NLS-1$ //$NON-NLS-2$

    if (allSelected) {
        remoteConfig.addFetchRefSpec(wcrs);
    } else {
        for (final Ref ref : selectedBranches)
            if (wcrs.matchSource(ref))
                remoteConfig.addFetchRefSpec(wcrs.expandFromSource(ref));
    }

    // we're setting up for a clone with a checkout
    local.getConfig().setBoolean("core", null, "bare", false); //$NON-NLS-1$ //$NON-NLS-2$

    remoteConfig.update(local.getConfig());

    // branch is like 'Constants.R_HEADS + branchName', we need only
    // the 'branchName' part
    String branchName = branch.substring(Constants.R_HEADS.length());

    // setup the default remote branch for branchName
    local.getConfig().setString("branch", branchName, "remote", remoteName); //$NON-NLS-1$ //$NON-NLS-2$
    local.getConfig().setString("branch", branchName, "merge", branch); //$NON-NLS-1$ //$NON-NLS-2$

    local.getConfig().save();
}

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

License:Open Source License

private void tryAutoCompleteSrcToDst() {
    final String src = creationSrcCombo.getText();
    final String dst = creationDstCombo.getText();

    if (src == null || src.length() == 0)
        return;/*from  w ww.  ja v a 2  s. c o  m*/

    if (dst != null && dst.length() > 0) {
        // dst is already there, just fix wildcards if needed
        final String newDst;
        if (RefSpec.isWildcard(src))
            newDst = wildcardSpecComponent(dst);
        else
            newDst = unwildcardSpecComponent(dst, src);
        creationDstCombo.setText(newDst);
        return;
    }

    if (!isValidRefExpression(src)) {
        // no way to be smarter than user here
        return;
    }

    // dst is empty, src is ref or wildcard, so we can rewrite it as user
    // would perhaps
    if (pushSpecs)
        creationDstCombo.setText(src);
    else {
        for (final RefSpec spec : predefinedConfigured) {
            if (spec.matchSource(src)) {
                final String newDst = spec.expandFromSource(src).getDestination();
                creationDstCombo.setText(newDst);
                return;
            }
        }
        if (remoteName != null && src.startsWith(Constants.R_HEADS)) {
            final String newDst = Constants.R_REMOTES + remoteName + '/'
                    + src.substring(Constants.R_HEADS.length());
            creationDstCombo.setText(newDst);
        }
    }
}

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

License:Open Source License

private void validateSpecsCrossDst() {
    final Map<String, RefSpec> dstsSpecsMap = new HashMap<String, RefSpec>();
    try {/*from  www .  j  a va  2s.  c  o m*/
        for (final RefSpec spec : specs) {
            if (!spec.isWildcard()) {
                if (!tryAddDestination(dstsSpecsMap, spec.getDestination(), spec))
                    return;
            } else {
                final Collection<String> srcNames;
                if (pushSpecs)
                    srcNames = localRefNames;
                else
                    srcNames = remoteRefNames;

                for (final String src : srcNames) {
                    if (spec.matchSource(src)) {
                        final String dst = spec.expandFromSource(src).getDestination();
                        if (!tryAddDestination(dstsSpecsMap, dst, spec))
                            return;
                    }
                }
            }
        }
    } finally {
        matchingAnyRefs = !dstsSpecsMap.isEmpty();
    }
}