List of usage examples for org.eclipse.jgit.lib Constants CONFIG
String CONFIG
To view the source code for org.eclipse.jgit.lib Constants CONFIG.
Click Source Link
From source file:jetbrains.buildServer.buildTriggers.vcs.git.agent.UpdaterImpl.java
License:Apache License
private void addSubmoduleUsernames(@NotNull File repositoryDir, @NotNull Config gitModules) throws IOException, ConfigInvalidException, VcsException { if (!myPluginConfig.isUseMainRepoUserForSubmodules()) return;// w ww . j a v a 2 s. c om Loggers.VCS.info("Update submodules credentials"); AuthSettings auth = myRoot.getAuthSettings(); final String userName = auth.getUserName(); if (userName == null) { Loggers.VCS.info("Username is not specified in the main VCS root settings, skip updating credentials"); return; } Repository r = new RepositoryBuilder().setBare().setGitDir(getGitDir(repositoryDir)).build(); StoredConfig gitConfig = r.getConfig(); Set<String> submodules = gitModules.getSubsections("submodule"); if (submodules.isEmpty()) { Loggers.VCS.info("No submodule sections found in " + new File(repositoryDir, ".gitmodules").getCanonicalPath() + ", skip updating credentials"); return; } File modulesDir = new File(r.getDirectory(), Constants.MODULES); for (String submoduleName : submodules) { String url = gitModules.getString("submodule", submoduleName, "url"); Loggers.VCS.info("Update credentials for submodule with url " + url); if (url == null || !isRequireAuth(url)) { Loggers.VCS.info("Url " + url + " does not require authentication, skip updating credentials"); continue; } try { URIish uri = new URIish(url); String updatedUrl = uri.setUser(userName).toASCIIString(); gitConfig.setString("submodule", submoduleName, "url", updatedUrl); String submodulePath = gitModules.getString("submodule", submoduleName, "path"); if (submodulePath != null && myPluginConfig.isUpdateSubmoduleOriginUrl()) { File submoduleDir = new File(modulesDir, submodulePath); if (submoduleDir.isDirectory() && new File(submoduleDir, Constants.CONFIG).isFile()) updateOriginUrl(submoduleDir, updatedUrl); } Loggers.VCS.debug("Submodule url " + url + " changed to " + updatedUrl); } catch (URISyntaxException e) { Loggers.VCS.warn("Error while parsing an url " + url + ", skip updating submodule credentials", e); } catch (Exception e) { Loggers.VCS.warn("Error while updating the '" + submoduleName + "' submodule url", e); } } gitConfig.save(); }