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));
}
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();
}
}
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);
}
}
Aggregations