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

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

Introduction

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

Prototype

@Override
public String toString() 

Source Link

Usage

From source file:com.hazelcast.simulator.utils.jars.GitSupport.java

License:Open Source License

private void addRepository(StoredConfig config, GitRepository repository) {
    String url = repository.getUrl();
    String name = repository.getName();
    LOGGER.info("Adding a new custom repository " + url);
    config.setString(CONFIG_REMOTE, name, CONFIG_URL, url);
    RefSpec refSpec = new RefSpec().setForceUpdate(true).setSourceDestination(Constants.R_HEADS + '*',
            Constants.R_REMOTES + name + "/*");
    config.setString(CONFIG_REMOTE, name, "fetch", refSpec.toString());
}

From source file:jenkins.plugins.git.AbstractGitSCMSource.java

License:Open Source License

protected List<UserRemoteConfig> getRemoteConfigs() {
    List<RefSpec> refSpecs = getRefSpecs();
    List<UserRemoteConfig> result = new ArrayList<UserRemoteConfig>(refSpecs.size());
    String remote = getRemote();//from  www  .j  a v a  2s . c om
    for (RefSpec refSpec : refSpecs) {
        result.add(new UserRemoteConfig(remote, getRemoteName(), refSpec.toString(), getCredentialsId()));
    }
    return result;
}

From source file:jenkins.plugins.git.GitSCMBuilder.java

License:Open Source License

private String joinRefSpecs(List<RefSpec> refSpecs) {
    if (refSpecs.isEmpty()) {
        return "";
    }//www  . j  ava 2s. c o m
    if (refSpecs.size() == 1) {
        return refSpecs.get(0).toString();
    }
    StringBuilder result = new StringBuilder(refSpecs.size() * 50 /*most ref specs are ~50 chars*/);
    boolean first = true;
    for (RefSpec r : refSpecs) {
        if (first) {
            first = false;
        } else {
            result.append(' ');
        }
        result.append(r.toString());
    }
    return result.toString();
}

From source file:jenkins.plugins.versionedbuildstep.Git.java

License:Open Source License

/**
 * Code copied from the Git Plugin//w ww .  j av  a 2 s. c o  m
 * ({@link hudson.plugins.git.GitSCM#newRemoteConfig(String, String, org.eclipse.jgit.transport.RefSpec)}).
 * @param name the name of the remote
 * @param refUrl the url
 * @param refSpec the ref spec.
 * @return a RemoteConfig saleable for clone and fetch.
 */
private RemoteConfig newRemoteConfig(String name, String refUrl, RefSpec refSpec) {

    try {
        Config repoConfig = new Config();
        // Make up a repo config from the request parameters

        repoConfig.setString("remote", name, "url", refUrl);
        repoConfig.setString("remote", name, "fetch", refSpec.toString());

        return RemoteConfig.getAllRemoteConfigs(repoConfig).get(0);
    } catch (Exception ex) {
        throw new GitException("Error trying to create JGit configuration", ex);
    }
}

From source file:jetbrains.buildServer.buildTriggers.vcs.git.OperationContext.java

License:Apache License

@NotNull
private String makeKey(@NotNull URIish uri, @NotNull Collection<RefSpec> refSpecs) {
    StringBuilder key = new StringBuilder();
    key.append(uri.toASCIIString());/* w  w  w.  j a  va 2s. com*/
    for (RefSpec refSpec : refSpecs) {
        key.append(refSpec.toString());
    }
    return key.toString();
}

From source file:org.apache.maven.scm.provider.git.jgit.command.checkin.JGitCheckInCommand.java

License:Apache License

/**
 * {@inheritDoc}// w  w  w .j a v a 2  s.c om
 */
protected CheckInScmResult executeCheckInCommand(ScmProviderRepository repo, ScmFileSet fileSet, String message,
        ScmVersion version) throws ScmException {

    Git git = null;
    try {
        File basedir = fileSet.getBasedir();
        git = Git.open(basedir);

        boolean doCommit = false;

        if (!fileSet.getFileList().isEmpty()) {
            doCommit = JGitUtils.addAllFiles(git, fileSet).size() > 0;
        } else {
            // add all tracked files which are modified manually
            Set<String> changeds = git.status().call().getModified();
            if (changeds.isEmpty()) {
                // warn there is nothing to add
                getLogger().warn("there are no files to be added");
                doCommit = false;
            } else {
                AddCommand add = git.add();
                for (String changed : changeds) {
                    getLogger().debug("add manualy: " + changed);
                    add.addFilepattern(changed);
                    doCommit = true;
                }
                add.call();
            }
        }

        List<ScmFile> checkedInFiles = Collections.emptyList();
        if (doCommit) {
            UserInfo author = getAuthor(repo, git);
            UserInfo committer = getCommitter(repo, git);

            CommitCommand command = git.commit().setMessage(message).setAuthor(author.name, author.email);
            command.setCommitter(committer.name, committer.email);
            RevCommit commitRev = command.call();

            getLogger().info("commit done: " + commitRev.getShortMessage());
            checkedInFiles = JGitUtils.getFilesInCommit(git.getRepository(), commitRev);
            if (getLogger().isDebugEnabled()) {
                for (ScmFile scmFile : checkedInFiles) {
                    getLogger().debug("in commit: " + scmFile);
                }
            }
        }

        if (repo.isPushChanges()) {
            String branch = version != null ? version.getName() : null;
            if (StringUtils.isBlank(branch)) {
                branch = git.getRepository().getBranch();
            }
            RefSpec refSpec = new RefSpec(Constants.R_HEADS + branch + ":" + Constants.R_HEADS + branch);
            getLogger().info("push changes to remote... " + refSpec.toString());
            JGitUtils.push(getLogger(), git, (GitScmProviderRepository) repo, refSpec);
        }

        return new CheckInScmResult("JGit checkin", checkedInFiles);
    } catch (Exception e) {
        throw new ScmException("JGit checkin failure!", e);
    } finally {
        JGitUtils.closeRepo(git);
    }
}

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

License:Open Source License

private void doPaste() {
    Clipboard clipboard = new Clipboard(getShell().getDisplay());
    try {//from  w  w  w  .j  av a 2s  .  com
        String content = (String) clipboard.getContents(TextTransfer.getInstance());
        if (content == null) {
            MessageDialog.openConfirm(getShell(),
                    UIText.AbstractConfigureRemoteDialog_EmptyClipboardDialogTitle,
                    UIText.AbstractConfigureRemoteDialog_EmptyClipboardDialogMessage);
        }
        try {
            RefSpec spec = new RefSpec(content);
            Ref source;
            try {
                // TODO better checks for wild-cards and such
                source = getRepository().findRef(isPush ? spec.getSource() : spec.getDestination());
            } catch (IOException e) {
                source = null;
            }
            if (source != null || MessageDialog.openQuestion(getShell(),
                    UIText.AbstractConfigureRemoteDialog_InvalidRefDialogTitle,
                    NLS.bind(UIText.AbstractConfigureRemoteDialog_InvalidRefDialogMessage, spec.toString()))) {
                addRefSpec(spec);
            }
            updateControls();
        } catch (IllegalArgumentException e) {
            MessageDialog.openError(getShell(), UIText.AbstractConfigureRemoteDialog_NoRefSpecDialogTitle,
                    UIText.AbstractConfigureRemoteDialog_NoRefSpecDialogMessage);
        }
    } finally {
        clipboard.dispose();
    }
}

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

License:Open Source License

private void doPaste() {
    Clipboard clipboard = new Clipboard(getShell().getDisplay());
    try {/*  w  w  w  .j a  va  2s . co  m*/
        String content = (String) clipboard.getContents(TextTransfer.getInstance());
        if (content == null)
            MessageDialog.openConfirm(getShell(), UIText.SimpleConfigureFetchDialog_NothingToPasteMessage,
                    UIText.SimpleConfigureFetchDialog_EmptyClipboardMessage);
        try {
            RefSpec spec = new RefSpec(content);
            Ref source;
            try {
                // TODO better checks for wild-cards and such
                source = repository.getRef(spec.getDestination());
            } catch (IOException e1) {
                source = null;
            }
            if (source != null || MessageDialog.openQuestion(getShell(),
                    UIText.SimpleConfigureFetchDialog_InvalidRefDialogTitle,
                    NLS.bind(UIText.SimpleConfigureFetchDialog_InvalidRefDialogMessage, spec.toString())))
                config.addFetchRefSpec(spec);

            updateControls();
        } catch (IllegalArgumentException ex) {
            MessageDialog.openError(getShell(), UIText.SimpleConfigureFetchDialog_NotRefSpecDialogTitle,
                    UIText.SimpleConfigureFetchDialog_NotRefSpecDialogMessage);
        }
    } finally {
        clipboard.dispose();
    }
}

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

License:Open Source License

private void setSpec(RefSpec spec) {
    setErrorMessage(null);//  w w  w  . j  a va2  s.  co  m
    this.spec = spec;
    String newSourceText = spec.getSource() != null ? spec.getSource() : ""; //$NON-NLS-1$
    String newDestinationText = spec.getDestination() != null ? spec.getDestination() : ""; //$NON-NLS-1$
    String newStringText = spec.toString();
    if (!sourceText.getText().equals(newSourceText))
        sourceText.setText(newSourceText);
    if (!destinationText.getText().equals(newDestinationText))
        destinationText.setText(newDestinationText);
    if (!specString.getText().equals(newStringText))
        specString.setText(newStringText);
    forceButton.setSelection(spec.isForceUpdate());
    if (sourceText.getText().length() == 0 || destinationText.getText().length() == 0)
        setErrorMessage(UIText.RefSpecDialog_MissingDataMessage);
    getButton(OK).setEnabled(sourceText.getText().length() > 0 && destinationText.getText().length() > 0);
}

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

License:Open Source License

private void doPaste() {
    Clipboard clipboard = new Clipboard(getShell().getDisplay());
    try {/*  w w  w .  j  ava  2 s .  c  om*/
        String content = (String) clipboard.getContents(TextTransfer.getInstance());
        if (content == null)
            MessageDialog.openConfirm(getShell(), UIText.SimpleConfigurePushDialog_EmptyClipboardDialogTitle,
                    UIText.SimpleConfigurePushDialog_EmptyClipboardDialogMessage);
        try {
            RefSpec spec = new RefSpec(content);
            Ref source;
            try {
                // TODO better checks for wild-cards and such
                source = repository.getRef(spec.getSource());
            } catch (IOException e1) {
                source = null;
            }
            if (source != null || MessageDialog.openQuestion(getShell(),
                    UIText.SimpleConfigurePushDialog_InvalidRefDialogTitle,
                    NLS.bind(UIText.SimpleConfigurePushDialog_InvalidRefDialogMessage, spec.toString())))
                config.addPushRefSpec(spec);

            updateControls();
        } catch (IllegalArgumentException ex) {
            MessageDialog.openError(getShell(), UIText.SimpleConfigurePushDialog_NoRefSpecDialogTitle,
                    UIText.SimpleConfigurePushDialog_NoRefSpecDialogMessage);
        }
    } finally {
        clipboard.dispose();
    }
}