Example usage for org.eclipse.jgit.transport TagOpt FETCH_TAGS

List of usage examples for org.eclipse.jgit.transport TagOpt FETCH_TAGS

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport TagOpt FETCH_TAGS.

Prototype

TagOpt FETCH_TAGS

To view the source code for org.eclipse.jgit.transport TagOpt FETCH_TAGS.

Click Source Link

Document

Always fetch tags, even if we do not have the thing it points at.

Usage

From source file:com.meltmedia.cadmium.core.git.GitService.java

License:Apache License

public boolean tag(String tagname, String comment) throws Exception {
    try {// ww  w  .  j  a  v a  2 s. c  o m
        git.fetch().setTagOpt(TagOpt.FETCH_TAGS).call();
    } catch (Exception e) {
        log.debug("Fetch from origin failed.", e);
    }
    List<RevTag> tags = git.tagList().call();
    if (tags != null && tags.size() > 0) {
        for (RevTag tag : tags) {
            if (tag.getTagName().equals(tagname)) {
                throw new Exception("Tag already exists.");
            }
        }
    }
    boolean success = git.tag().setMessage(comment).setName(tagname).call() != null;
    try {
        git.push().setPushTags().call();
    } catch (Exception e) {
        log.debug("Failed to push changes.", e);
    }
    return success;
}

From source file:com.meltmedia.cadmium.core.git.GitService.java

License:Apache License

public void fetchRemotes() throws Exception {
    git.fetch().setTagOpt(TagOpt.FETCH_TAGS).setCheckFetchedObjects(false).setRemoveDeletedRefs(true).call();
}

From source file:org.ajoberstar.gradle.git.tasks.GitFetch.java

License:Apache License

/**
 * Attempts to get a valid {@link TagOpt} out of the user
 * configuration/*from   ww  w . jav  a  2s  .  co  m*/
 * 
 * @return the TagOpt corresponding to the user input 
 */
private TagOpt getTagOpt() {
    String tagConfig = ObjectUtil.unpackString(getFetchTags());
    if (tagConfig == null) {
        return TagOpt.AUTO_FOLLOW;
    } else if (tagConfig.equalsIgnoreCase("auto")) {
        return TagOpt.AUTO_FOLLOW;
    } else if (tagConfig.equalsIgnoreCase("yes")) {
        return TagOpt.FETCH_TAGS;
    } else if (tagConfig.equalsIgnoreCase("no")) {
        return TagOpt.NO_TAGS;
    } else {
        throw new GradleException(
                "No valid tag option could be " + "identified from the specified input: " + tagConfig);
    }
}

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

License:Open Source License

/**
 * @return selected tag fetching strategy. This result is relevant only for
 *         fetch page./* w  w w.  jav  a 2s.c om*/
 */
public TagOpt getTagOpt() {
    if (tagsAutoFollowButton.getSelection())
        return TagOpt.AUTO_FOLLOW;
    if (tagsFetchTagsButton.getSelection())
        return TagOpt.FETCH_TAGS;
    return TagOpt.NO_TAGS;
}

From source file:org.flowerplatform.web.git.GitService.java

License:Open Source License

@RemoteInvocation
public boolean fetch(ServiceInvocationContext context, List<PathFragment> path, RemoteConfig fetchConfig) {
    tlCommand.set((InvokeServiceMethodServerCommand) context.getCommand());

    ProgressMonitor monitor = ProgressMonitor.create(
            GitPlugin.getInstance().getMessage("git.fetch.monitor.title"), context.getCommunicationChannel());

    try {/*from w  ww .jav a  2s. co m*/
        Object node = GenericTreeStatefulService.getNodeByPathFor(path, null);
        GenericTreeStatefulService service = GenericTreeStatefulService.getServiceFromPathWithRoot(path);
        NodeInfo nodeInfo = service.getVisibleNodes().get(node);
        Repository repository = getRepository(nodeInfo);
        if (repository == null) {
            context.getCommunicationChannel().appendOrSendCommand(new DisplaySimpleMessageClientCommand(
                    CommonPlugin.getInstance().getMessage("error"), "Cannot find repository for node " + node,
                    DisplaySimpleMessageClientCommand.ICON_ERROR));
            return false;
        }

        String remote = null;
        if (GitNodeType.NODE_TYPE_REMOTE.equals(nodeInfo.getPathFragment().getType())) {
            remote = ((RemoteNode) node).getRemote();
        }

        GitProgressMonitor gitMonitor = new GitProgressMonitor(monitor);
        FetchCommand command;

        if (remote != null) {
            command = new Git(repository).fetch().setRemote(remote);
        } else {
            List<RefSpec> specs = new ArrayList<RefSpec>();
            for (String refMapping : fetchConfig.getFetchMappings()) {
                specs.add(new RefSpec(refMapping));
            }
            command = new Git(repository).fetch().setRemote(new URIish(fetchConfig.getUri()).toPrivateString())
                    .setRefSpecs(specs);
        }
        command.setProgressMonitor(gitMonitor);
        command.setTagOpt(TagOpt.FETCH_TAGS);

        FetchResult fetchResult = command.call();

        dispatchContentUpdate(node);

        context.getCommunicationChannel()
                .appendOrSendCommand(new DisplaySimpleMessageClientCommand(
                        GitPlugin.getInstance().getMessage("git.fetch.result"),
                        GitPlugin.getInstance().getUtils().handleFetchResult(fetchResult),
                        DisplaySimpleMessageClientCommand.ICON_INFORMATION));

        return true;
    } catch (Exception e) {
        if (GitPlugin.getInstance().getUtils().isAuthentificationException(e)) {
            openLoginWindow();
            return true;
        }
        logger.debug(GitPlugin.getInstance().getMessage("git.fetch.error"), e);
        context.getCommunicationChannel().appendOrSendCommand(
                new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"),
                        e.getMessage(), DisplaySimpleMessageClientCommand.ICON_ERROR));
        return false;
    } finally {
        monitor.done();
    }
}

From source file:org.jboss.forge.git.Clone.java

License:Eclipse Distribution License

private FetchResult runFetch() throws NotSupportedException, URISyntaxException, TransportException {
    final Transport tn = Transport.open(db, remoteName);
    final FetchResult r;
    try {/*from   w w  w.  ja  v a2s  .  c  om*/
        tn.setTagOpt(TagOpt.FETCH_TAGS);
        r = tn.fetch(new TextProgressMonitor(), null);
    } finally {
        tn.close();
    }
    return r;
}

From source file:org.ocpsoft.redoculous.model.impl.GitRepository.java

License:Open Source License

private void cloneRepository() {
    File refsDir = getRefsDir();/* w w  w .  j ava 2s  .  co  m*/
    File cacheDir = getCacheDir();

    if (!getRepoDir().exists()) {
        RedoculousProgressMonitor monitor = new RedoculousProgressMonitor();
        try {
            getRepoDir().mkdirs();
            refsDir.mkdirs();
            cacheDir.mkdirs();

            Git git = Git.cloneRepository().setURI(getUrl()).setRemote("origin").setCloneAllBranches(true)
                    .setDirectory(getRepoDir()).setProgressMonitor(monitor).call();

            try {
                git.fetch().setRemote("origin").setTagOpt(TagOpt.FETCH_TAGS).setThin(false).setTimeout(10)
                        .setProgressMonitor(monitor).call();
            } finally {
                git.getRepository().close();
            }

        } catch (Exception e) {
            throw new RuntimeException("Could not clone repository [" + getUrl() + "] [" + getKey() + "]", e);
        }
    }
}

From source file:org.ocpsoft.redoculous.model.impl.GitRepository.java

License:Open Source License

@Override
public void update() {
    File repoDir = getRepoDir();//from   www .j  a va  2 s  . co  m

    Git git = null;
    RedoculousProgressMonitor monitor = new RedoculousProgressMonitor();
    try {
        log.info("Handling update request for [" + getUrl() + "] [" + getKey() + "]");
        git = Git.open(repoDir);

        git.fetch().setTagOpt(TagOpt.FETCH_TAGS).setRemote("origin")
                .setRefSpecs(new RefSpec("+refs/heads/*:refs/remotes/origin/*")).setProgressMonitor(monitor)
                .call();

        git.fetch().setTagOpt(TagOpt.FETCH_TAGS).setRemote("origin")
                .setRefSpecs(new RefSpec("+refs/tags/*:refs/tags/*")).setProgressMonitor(monitor).call();

        git.reset().setMode(ResetType.HARD).setRef("refs/remotes/origin/" + git.getRepository().getBranch())
                .call();

        git.clean().setCleanDirectories(true).call();

        Files.delete(getRefsDir(), true);
        Files.delete(getCacheDir(), true);
    } catch (Exception e) {
        throw new RuntimeException("Could not update repository [" + getUrl() + "] [" + getKey() + "]", e);
    } finally {
        if (git != null)
            git.getRepository().close();
    }
}

From source file:org.springframework.cloud.config.server.environment.JGitEnvironmentRepository.java

License:Apache License

private FetchResult fetch(Git git, String label) {
    FetchCommand fetch = git.fetch();/*from   w  w w . j  a  va  2  s .com*/
    fetch.setRemote("origin");
    fetch.setTagOpt(TagOpt.FETCH_TAGS);

    setTimeout(fetch);
    try {
        setCredentialsProvider(fetch);
        FetchResult result = fetch.call();
        if (result.getTrackingRefUpdates() != null && result.getTrackingRefUpdates().size() > 0) {
            logger.info("Fetched for remote " + label + " and found " + result.getTrackingRefUpdates().size()
                    + " updates");
        }
        return result;
    } catch (Exception ex) {
        String message = "Could not fetch remote for " + label + " remote: "
                + git.getRepository().getConfig().getString("remote", "origin", "url");
        warn(message, ex);
        return null;
    }
}

From source file:sh.isaac.provider.sync.git.SyncServiceGIT.java

License:Apache License

/**
 * Read tags./*from   w w w  .jav  a  2  s .c  o m*/
 *
 * @param username the username
 * @param password the password
 * @return the array list
 * @throws IllegalArgumentException the illegal argument exception
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws AuthenticationException the authentication exception
 */
public ArrayList<String> readTags(String username, char[] password)
        throws IllegalArgumentException, IOException, AuthenticationException {
    try (Git git = getGit()) {
        final ArrayList<String> results = new ArrayList<>();
        final CredentialsProvider cp = new UsernamePasswordCredentialsProvider(username,
                ((password == null) ? new char[] {} : password));

        git.fetch().setTagOpt(TagOpt.FETCH_TAGS).setCredentialsProvider(cp).call();

        for (final Ref x : git.tagList().call()) {
            results.add(x.getName());
        }

        git.close();
        return results;
    } catch (final GitAPIException e) {
        if (e.getMessage().contains("Auth fail") || e.getMessage().contains("not authorized")) {
            LOG.info("Auth fail", e);
            throw new AuthenticationException("Auth fail");
        } else {
            LOG.error("Unexpected", e);
            throw new IOException("Internal error", e);
        }
    }
}