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

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

Introduction

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

Prototype

TagOpt NO_TAGS

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

Click Source Link

Document

Never fetch tags, even if we have the thing it points at.

Usage

From source file:net.polydawn.mdm.Plumbing.java

License:Open Source License

public static boolean fetch(Repository repo, MdmModuleDependency module) throws ConfigInvalidException,
        MdmRepositoryIOException, MdmRepositoryStateException, MdmException, IOException {
    switch (module.getStatus().getType()) {
    case MISSING:
        throw new MajorBug();
    case UNINITIALIZED:
        if (module.getRepo() == null)
            try {
                RepositoryBuilder builder = new RepositoryBuilder();
                builder.setWorkTree(new File(repo.getWorkTree() + "/" + module.getPath()));
                builder.setGitDir(new File(repo.getDirectory() + "/modules/" + module.getPath()));
                module.repo = builder.build();

                // we actually *might* not have to make the repo from zero.
                // this getRepo gets its effective data from SubmoduleWalk.getSubmoduleRepository...
                // which does its job by looking in the working tree of the parent repo.
                // meaning if it finds nothing, it certainly won't find any gitdir indirections.
                // so, even if this is null, we might well have a gitdir cached that we still have to go find.
                final FileBasedConfig cfg = (FileBasedConfig) module.repo.getConfig();
                if (!cfg.getFile().exists()) { // though seemly messy, this is the same question the jgit create() function asks, and it's not exposed to us, so.
                    module.repo.create(false);
                } else {
                    // do something crazy, because... i think the user's expectation after blowing away their submodule working tree is likely wanting a clean state of index and such here
                    try {
                        new Git(module.getRepo()).reset().setMode(ResetType.HARD).call();
                    } catch (CheckoutConflictException e) {
                        /* Can a hard reset even have a conflict? */
                        throw new MajorBug("an unrecognized problem occurred.  please file a bug report.", e);
                    } catch (GitAPIException e) {
                        throw new MajorBug("an unrecognized problem occurred.  please file a bug report.", e);
                    }/*from   w w w. j  av  a2s .co m*/
                }

                // set up a working tree which points to the gitdir in the parent repo:

                // handling paths in java, god forbid relative paths, is such an unbelievable backwater.  someday please make a whole library that actually disambiguates pathnames from filedescriptors properly
                int ups = StringUtils.countMatches(module.getPath(), "/");
                // look up the path between the `repo` and its possible git dir location.  if the gitdir is relocated, we have adjust our own relocations to compensate.
                String parentGitPointerStr = ".git/";
                String parentWorktreePointerStr = "../";
                // load it ourselves because we explicitly want the unresolved path, not what jgit would give us back from `repo.getDirectory().toString()`.
                File parentGitPointer = new File(repo.getWorkTree(), ".git");
                if (parentGitPointer.isFile()) {
                    // this shouldn't have to be recursive fortunately (that recursion is done implicitly by the chaining of each guy at each stage).
                    // this does however feel fairly fragile.  it's considerable that perhaps we should try to heuristically determine when paths are just to crazy to deal with.  but, on the off chance that check was overzealous, it would be very irritating, so let's not.
                    // frankly, if you're doing deeply nested submodules, or other advanced gitdir relocations, at some point you're taking it upon yourself to deal with the inevitably complex outcomes and edge case limitations.
                    parentGitPointerStr = IOForge.readFileAsString(parentGitPointer);
                    if (!"gitdir:".equals(parentGitPointerStr.substring(0, 7)))
                        throw new ConfigInvalidException(
                                "cannot understand location of parent project git directory");
                    parentGitPointerStr = parentGitPointerStr.substring(7).trim() + "/";
                    parentWorktreePointerStr = repo.getConfig().getString("core", null, "worktree") + "/";
                }
                // jgit does not appear to create the .git file correctly here :/
                // nor even consider it to be jgit's job to create the worktree yet, apparently, so do that
                module.repo.getWorkTree().mkdirs();
                // need modules/[module]/config to contain 'core.worktree' = appropriate
                String submoduleWorkTreeRelativeToGitDir = StringUtils.repeat("../", ups + 2)
                        + parentWorktreePointerStr + module.getPath();
                StoredConfig cnf = module.repo.getConfig();
                cnf.setString("core", null, "worktree", submoduleWorkTreeRelativeToGitDir);
                cnf.save();
                // need [module]/.git to contain 'gitdir: appropriate' (which appears to not be normal gitconfig)
                String submoduleGitDirRelativeToWorkTree = StringUtils.repeat("../", ups + 1)
                        + parentGitPointerStr + "modules/" + module.getPath();
                IOForge.saveFile("gitdir: " + submoduleGitDirRelativeToWorkTree + "\n",
                        new File(module.repo.getWorkTree(), ".git"));
            } catch (IOException e) {
                throw new MdmRepositoryIOException("create a new submodule", true, module.getHandle(), e);
            }

        try {
            if (initLocalConfig(repo, module))
                repo.getConfig().save();
        } catch (IOException e) {
            throw new MdmRepositoryIOException("save changes", true, "the local git configuration file", e);
        }
        try {
            setMdmRemote(module);
            module.getRepo().getConfig().save();
        } catch (IOException e) {
            throw new MdmRepositoryIOException("save changes", true,
                    "the git configuration file for submodule " + module.getHandle(), e);
        }
    case INITIALIZED:
        if (module.getVersionName() == null || module.getVersionName().equals(module.getVersionActual()))
            return false;
    case REV_CHECKED_OUT:
        try {
            if (initModuleConfig(repo, module))
                module.getRepo().getConfig().save();
        } catch (IOException e) {
            throw new MdmRepositoryIOException("save changes", true,
                    "the git configuration file for submodule " + module.getHandle(), e);
        }

        final String versionBranchName = "refs/heads/mdm/release/" + module.getVersionName();
        final String versionTagName = "refs/tags/release/" + module.getVersionName();

        /* Fetch only the branch labelled with the version requested. */
        if (module.getRepo().getRef(versionBranchName) == null)
            try {
                RefSpec releaseBranchRef = new RefSpec().setForceUpdate(true).setSource(versionBranchName)
                        .setDestination(versionBranchName);
                RefSpec releaseTagRef = new RefSpec().setForceUpdate(true).setSource(versionTagName)
                        .setDestination(versionTagName);
                new Git(module.getRepo()).fetch().setRemote("origin")
                        .setRefSpecs(releaseBranchRef, releaseTagRef).setTagOpt(TagOpt.NO_TAGS).call();
            } catch (InvalidRemoteException e) {
                throw new MdmRepositoryStateException(
                        "find a valid remote origin in the config for the submodule", module.getHandle(), e);
            } catch (TransportException e) {
                URIish remote = null;
                try { //XXX: if we went through all the work to resolve the remote like the fetch command does, we could just as well do it and hand the resolved uri to fetch for better consistency.
                    remote = new RemoteConfig(module.getRepo().getConfig(), "origin").getURIs().get(0);
                } catch (URISyntaxException e1) {
                }
                throw new MdmRepositoryIOException("fetch from a remote", false, remote.toASCIIString(), e)
                        .setAdditionalMessage("check your connectivity and try again?");
            } catch (GitAPIException e) {
                throw new MajorBug("an unrecognized problem occurred.  please file a bug report.", e);
            }

        /* Drop the files into the working tree. */
        try {
            new Git(module.getRepo()).checkout().setName(versionBranchName).setForce(true).call();
        } catch (RefAlreadyExistsException e) {
            /* I'm not creating a new branch, so this exception wouldn't even make sense. */
            throw new MajorBug(e);
        } catch (RefNotFoundException e) {
            /* I just got this branch, so we shouldn't have a problem here. */
            throw new MajorBug("an unrecognized problem occurred.  please file a bug report.", e);
        } catch (InvalidRefNameException e) {
            /* I just got this branch, so we shouldn't have a problem here. */
            throw new MajorBug("an unrecognized problem occurred.  please file a bug report.", e);
        } catch (CheckoutConflictException e) {
            // this one is just a perfectly reasonable message with a list of files in conflict; we'll take it.
            throw new MdmRepositoryStateException(module.getHandle(), e); // this currently gets translated to a :'( exception and it's probably more like a :(
        } catch (GitAPIException e) {
            throw new MajorBug("an unrecognized problem occurred.  please file a bug report.", e);
        }
        return true;
    default:
        throw new MajorBug();
    }
}

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  . j  a v a  2 s  .  c o  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 ww  .  java  2 s  . c om*/
 */
public TagOpt getTagOpt() {
    if (tagsAutoFollowButton.getSelection())
        return TagOpt.AUTO_FOLLOW;
    if (tagsFetchTagsButton.getSelection())
        return TagOpt.FETCH_TAGS;
    return TagOpt.NO_TAGS;
}