Search in sources :

Example 1 with SubmoduleWalk

use of org.eclipse.jgit.submodule.SubmoduleWalk in project gitiles by GerritCodeReview.

the class PathServlet method showGitlink.

private void showGitlink(HttpServletRequest req, HttpServletResponse res, WalkResult wr) throws IOException {
    GitilesView view = ViewFilter.getView(req);
    String modulesUrl;
    String remoteUrl = null;
    try (SubmoduleWalk sw = SubmoduleWalk.forPath(ServletUtils.getRepository(req), wr.root, view.getPathPart())) {
        modulesUrl = sw.getModulesUrl();
        if (modulesUrl != null && (modulesUrl.startsWith("./") || modulesUrl.startsWith("../"))) {
            String moduleRepo = PathUtil.simplifyPathUpToRoot(modulesUrl, view.getRepositoryName());
            if (moduleRepo != null) {
                modulesUrl = urls.getBaseGitUrl(req) + moduleRepo;
            }
        } else {
            remoteUrl = sw.getRemoteUrl();
        }
    } catch (ConfigInvalidException e) {
        throw new IOException(e);
    }
    Map<String, Object> data = Maps.newHashMap();
    data.put("sha", ObjectId.toString(wr.id));
    data.put("remoteUrl", remoteUrl != null ? remoteUrl : modulesUrl);
    // TODO(dborowitz): Guess when we can put commit SHAs in the URL.
    String httpUrl = resolveHttpUrl(remoteUrl);
    if (httpUrl != null) {
        data.put("httpUrl", httpUrl);
    }
    // TODO(sop): Allow caching links by SHA-1 when no S cookie is sent.
    renderHtml(req, res, "gitiles.pathDetail", ImmutableMap.of("title", view.getPathPart(), "type", FileType.GITLINK.toString(), "data", data));
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) RevObject(org.eclipse.jgit.revwalk.RevObject) QuotedString(org.eclipse.jgit.util.QuotedString) IOException(java.io.IOException) SubmoduleWalk(org.eclipse.jgit.submodule.SubmoduleWalk)

Example 2 with SubmoduleWalk

use of org.eclipse.jgit.submodule.SubmoduleWalk in project gradle by gradle.

the class GitVersionControlSystem method updateSubModules.

private static void updateSubModules(Git git) throws IOException, GitAPIException {
    SubmoduleWalk walker = SubmoduleWalk.forIndex(git.getRepository());
    try {
        while (walker.next()) {
            Repository submodule = walker.getRepository();
            try {
                Git submoduleGit = Git.wrap(submodule);
                submoduleGit.fetch().call();
                git.submoduleUpdate().addPath(walker.getPath()).call();
                submoduleGit.reset().setMode(ResetCommand.ResetType.HARD).call();
                updateSubModules(submoduleGit);
            } finally {
                submodule.close();
            }
        }
    } finally {
        walker.close();
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) SubmoduleWalk(org.eclipse.jgit.submodule.SubmoduleWalk)

Example 3 with SubmoduleWalk

use of org.eclipse.jgit.submodule.SubmoduleWalk in project gradle by gradle.

the class GitFileRepository method updateSubmodulesToLatest.

/**
 * Updates any submodules in this repository to the latest in the submodule origin repository
 */
public RevCommit updateSubmodulesToLatest() throws GitAPIException {
    List<String> submodulePaths = Lists.newArrayList();
    try {
        SubmoduleWalk walker = SubmoduleWalk.forIndex(git.getRepository());
        try {
            while (walker.next()) {
                Repository submodule = walker.getRepository();
                try {
                    submodulePaths.add(walker.getPath());
                    Git.wrap(submodule).pull().call();
                } finally {
                    submodule.close();
                }
            }
        } finally {
            walker.close();
        }
        return commit("update submodules", submodulePaths.toArray(new String[submodulePaths.size()]));
    } catch (IOException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) IOException(java.io.IOException) SubmoduleWalk(org.eclipse.jgit.submodule.SubmoduleWalk)

Aggregations

SubmoduleWalk (org.eclipse.jgit.submodule.SubmoduleWalk)3 IOException (java.io.IOException)2 Repository (org.eclipse.jgit.lib.Repository)2 Git (org.eclipse.jgit.api.Git)1 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)1 RevObject (org.eclipse.jgit.revwalk.RevObject)1 QuotedString (org.eclipse.jgit.util.QuotedString)1