List of usage examples for org.eclipse.jgit.lib StoredConfig save
public abstract void save() throws IOException;
From source file:org.archicontribs.modelrepository.grafico.GraficoUtils.java
License:Open Source License
/** * Clone a model/*from w w w .j a va 2s . c om*/ * @param localGitFolder * @param repoURL * @param userName * @param userPassword * @param monitor * @throws GitAPIException * @throws IOException */ public static void cloneModel(File localGitFolder, String repoURL, String userName, String userPassword, ProgressMonitor monitor) throws GitAPIException, IOException { CloneCommand cloneCommand = Git.cloneRepository(); cloneCommand.setDirectory(localGitFolder); cloneCommand.setURI(repoURL); cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userName, userPassword)); cloneCommand.setProgressMonitor(monitor); try (Git git = cloneCommand.call()) { // Use the same line endings StoredConfig config = git.getRepository().getConfig(); config.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, "true"); //$NON-NLS-1$ config.save(); } }
From source file:org.codice.git.GitHandler.java
License:Open Source License
public void setConfigString(String section, String subsection, String key, String value) throws IOException { final StoredConfig config = repo.getConfig(); config.setString(section, subsection, key, value); config.save(); LOGGER.log(Level.FINE, "Value for [{0}, {1}, {2}] set to: {3}\n", new Object[] { section, subsection, key, value }); }
From source file:org.craftercms.studio.impl.v1.deployment.EnvironmentStoreGitBranchDeployer.java
License:Open Source License
private void addWorkAreaRemote(String site, Repository envStoreRepo) { envStoreRepo.getRemoteName("work-area"); Git git = new Git(envStoreRepo); StoredConfig config = git.getRepository().getConfig(); Path siteRepoPath = Paths.get(rootPath, "sites", site, ".git"); config.setString("remote", "work-area", "url", siteRepoPath.normalize().toAbsolutePath().toString()); try {//from w w w . j a va2 s.c o m config.save(); } catch (IOException e) { logger.error("Error adding work area as remote for environment store.", e); } }
From source file:org.craftercms.studio.impl.v1.repository.git.GitContentRepositoryHelper.java
License:Open Source License
public Repository createGitRepository(Path path) { Repository toReturn;/* ww w.j a va 2 s.co m*/ path = Paths.get(path.toAbsolutePath().toString(), GIT_ROOT); try { toReturn = FileRepositoryBuilder.create(path.toFile()); toReturn.create(); // Get git configuration StoredConfig config = toReturn.getConfig(); // Set compression level (core.compression) config.setInt(CONFIG_SECTION_CORE, null, CONFIG_PARAMETER_COMPRESSION, CONFIG_PARAMETER_COMPRESSION_DEFAULT); // Set big file threshold (core.bigFileThreshold) config.setString(CONFIG_SECTION_CORE, null, CONFIG_PARAMETER_BIG_FILE_THRESHOLD, CONFIG_PARAMETER_BIG_FILE_THRESHOLD_DEFAULT); // Save configuration changes config.save(); } catch (IOException e) { logger.error("Error while creating repository for site with path" + path.toString(), e); toReturn = null; } return toReturn; }
From source file:org.eclipse.che.git.impl.jgit.JGitConnection.java
License:Open Source License
public void clone(CloneRequest request) throws GitException, UnauthorizedException { String remoteUri;/*from w w w .j av a 2 s . c o m*/ boolean removeIfFailed = false; try { if (request.getRemoteName() == null) { request.setRemoteName(Constants.DEFAULT_REMOTE_NAME); } if (request.getWorkingDir() == null) { request.setWorkingDir(repository.getWorkTree().getCanonicalPath()); } // If clone fails and the .git folder didn't exist we want to remove it. // We have to do this here because the clone command doesn't revert its own changes in case of failure. removeIfFailed = !repository.getDirectory().exists(); remoteUri = request.getRemoteUri(); CloneCommand cloneCommand = Git.cloneRepository().setDirectory(new File(request.getWorkingDir())) .setRemote(request.getRemoteName()).setURI(remoteUri); if (request.getBranchesToFetch().isEmpty()) { cloneCommand.setCloneAllBranches(true); } else { cloneCommand.setBranchesToClone(request.getBranchesToFetch()); } executeRemoteCommand(remoteUri, cloneCommand); StoredConfig repositoryConfig = getRepository().getConfig(); GitUser gitUser = getUser(); if (gitUser != null) { repositoryConfig.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_NAME, gitUser.getName()); repositoryConfig.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_EMAIL, gitUser.getEmail()); } repositoryConfig.save(); } catch (IOException | GitAPIException exception) { // Delete .git directory in case it was created if (removeIfFailed) { deleteRepositoryFolder(); } throw new GitException(exception.getMessage(), exception); } }
From source file:org.eclipse.che.git.impl.jgit.JGitConnection.java
License:Open Source License
@Override public void remoteAdd(RemoteAddRequest request) throws GitException { String remoteName = request.getName(); if (isNullOrEmpty(remoteName)) { throw new IllegalArgumentException(ERROR_ADD_REMOTE_NAME_MISSING); }//from www . j a va2 s . c o m StoredConfig config = repository.getConfig(); Set<String> remoteNames = config.getSubsections("remote"); if (remoteNames.contains(remoteName)) { throw new IllegalArgumentException(String.format(ERROR_REMOTE_NAME_ALREADY_EXISTS, remoteName)); } String url = request.getUrl(); if (isNullOrEmpty(url)) { throw new IllegalArgumentException(ERROR_REMOTE_URL_MISSING); } RemoteConfig remoteConfig; try { remoteConfig = new RemoteConfig(config, remoteName); } catch (URISyntaxException exception) { // Not happen since it is newly created remote. throw new GitException(exception.getMessage(), exception); } try { remoteConfig.addURI(new URIish(url)); } catch (URISyntaxException exception) { throw new IllegalArgumentException("Remote url " + url + " is invalid. "); } List<String> branches = request.getBranches(); if (branches.isEmpty()) { remoteConfig.addFetchRefSpec( new RefSpec(Constants.R_HEADS + "*" + ":" + Constants.R_REMOTES + remoteName + "/*") .setForceUpdate(true)); } else { for (String branch : branches) { remoteConfig.addFetchRefSpec(new RefSpec( Constants.R_HEADS + branch + ":" + Constants.R_REMOTES + remoteName + "/" + branch) .setForceUpdate(true)); } } remoteConfig.update(config); try { config.save(); } catch (IOException exception) { throw new GitException(exception.getMessage(), exception); } }
From source file:org.eclipse.che.git.impl.jgit.JGitConnection.java
License:Open Source License
@Override public void remoteDelete(String name) throws GitException { StoredConfig config = repository.getConfig(); Set<String> remoteNames = config.getSubsections(ConfigConstants.CONFIG_KEY_REMOTE); if (!remoteNames.contains(name)) { throw new GitException("error: Could not remove config section 'remote." + name + "'"); }/*from w w w. j a va 2 s .c o m*/ config.unsetSection(ConfigConstants.CONFIG_REMOTE_SECTION, name); Set<String> branches = config.getSubsections(ConfigConstants.CONFIG_BRANCH_SECTION); for (String branch : branches) { String r = config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_KEY_REMOTE); if (name.equals(r)) { config.unset(ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_KEY_REMOTE); config.unset(ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_KEY_MERGE); List<Branch> remoteBranches = branchList(newDto(BranchListRequest.class).withListMode("r")); for (Branch remoteBranch : remoteBranches) { if (remoteBranch.getDisplayName().startsWith(name)) { branchDelete( newDto(BranchDeleteRequest.class).withName(remoteBranch.getName()).withForce(true)); } } } } try { config.save(); } catch (IOException exception) { throw new GitException(exception.getMessage(), exception); } }
From source file:org.eclipse.che.git.impl.jgit.JGitConnection.java
License:Open Source License
@Override public void remoteUpdate(RemoteUpdateRequest request) throws GitException { String remoteName = request.getName(); if (isNullOrEmpty(remoteName)) { throw new IllegalArgumentException(ERROR_UPDATE_REMOTE_NAME_MISSING); }/*ww w. j av a 2 s . co m*/ StoredConfig config = repository.getConfig(); Set<String> remoteNames = config.getSubsections(ConfigConstants.CONFIG_KEY_REMOTE); if (!remoteNames.contains(remoteName)) { throw new IllegalArgumentException("Remote " + remoteName + " not found. "); } RemoteConfig remoteConfig; try { remoteConfig = new RemoteConfig(config, remoteName); } catch (URISyntaxException e) { throw new GitException(e.getMessage(), e); } List<String> branches = request.getBranches(); if (!branches.isEmpty()) { if (!request.isAddBranches()) { remoteConfig.setFetchRefSpecs(Collections.emptyList()); remoteConfig.setPushRefSpecs(Collections.emptyList()); } else { // Replace wildcard refSpec if any. remoteConfig.removeFetchRefSpec( new RefSpec(Constants.R_HEADS + "*" + ":" + Constants.R_REMOTES + remoteName + "/*") .setForceUpdate(true)); remoteConfig.removeFetchRefSpec( new RefSpec(Constants.R_HEADS + "*" + ":" + Constants.R_REMOTES + remoteName + "/*")); } // Add new refSpec. for (String branch : branches) { remoteConfig.addFetchRefSpec(new RefSpec( Constants.R_HEADS + branch + ":" + Constants.R_REMOTES + remoteName + "/" + branch) .setForceUpdate(true)); } } // Remove URLs first. for (String url : request.getRemoveUrl()) { try { remoteConfig.removeURI(new URIish(url)); } catch (URISyntaxException e) { LOG.debug(ERROR_REMOVING_INVALID_URL); } } // Add new URLs. for (String url : request.getAddUrl()) { try { remoteConfig.addURI(new URIish(url)); } catch (URISyntaxException e) { throw new IllegalArgumentException("Remote url " + url + " is invalid. "); } } // Remove URLs for pushing. for (String url : request.getRemovePushUrl()) { try { remoteConfig.removePushURI(new URIish(url)); } catch (URISyntaxException e) { LOG.debug(ERROR_REMOVING_INVALID_URL); } } // Add URLs for pushing. for (String url : request.getAddPushUrl()) { try { remoteConfig.addPushURI(new URIish(url)); } catch (URISyntaxException e) { throw new IllegalArgumentException("Remote push url " + url + " is invalid. "); } } remoteConfig.update(config); try { config.save(); } catch (IOException exception) { throw new GitException(exception.getMessage(), exception); } }
From source file:org.eclipse.egit.core.internal.gerrit.GerritUtil.java
License:Open Source License
/** * If the repository is not bare and looks like it might be a Gerrit * repository, try to configure it such that EGit's Gerrit support is * enabled.//w w w .j a v a 2s . c o m * * @param repository * to try to configure */ public static void tryToAutoConfigureForGerrit(@NonNull Repository repository) { if (repository.isBare()) { return; } StoredConfig config = repository.getConfig(); boolean isGerrit = false; boolean changed = false; try { for (RemoteConfig remote : RemoteConfig.getAllRemoteConfigs(config)) { if (isGerritPush(remote)) { isGerrit = true; if (configureFetchNotes(remote)) { changed = true; remote.update(config); } } } } catch (URISyntaxException ignored) { // Ignore it here -- we're just trying to set up Gerrit support. } if (isGerrit) { if (config.getString(ConfigConstants.CONFIG_GERRIT_SECTION, null, ConfigConstants.CONFIG_KEY_CREATECHANGEID) != null) { // Already configured. } else { setCreateChangeId(config); changed = true; } if (changed) { try { config.save(); } catch (IOException e) { Activator.logError( MessageFormat.format(CoreText.GerritUtil_ConfigSaveError, repository.getDirectory()), e); } } } }
From source file:org.eclipse.egit.core.internal.ProjectReferenceImporterTest.java
License:Open Source License
private static void addRemote(Repository repository, String name, URIish url) throws IOException { StoredConfig config = repository.getConfig(); config.setString("remote", name, "url", url.toString()); config.save(); }