List of usage examples for org.eclipse.jgit.lib StoredConfig unsetSection
public void unsetSection(String section, String subsection)
From source file:com.hazelcast.simulator.utils.jars.GitSupport.java
License:Open Source License
private void removeRepository(StoredConfig config, String remoteName) { config.unsetSection(CONFIG_REMOTE, remoteName); }
From source file:com.microsoft.gittf.core.config.ChangesetCommitMap.java
License:Open Source License
private static void copyConfigurationEntries(StoredConfig source, FileBasedConfig target) { Set<String> downloadedChangesetEntries = source.getNames(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.COMMIT_SUBSECTION); for (String changesetEntry : downloadedChangesetEntries) { String commitHash = source.getString(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.COMMIT_SUBSECTION, changesetEntry); target.setString(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.COMMIT_SUBSECTION, changesetEntry, commitHash); }/* www. jav a 2s. c o m*/ Set<String> createdCommitEntries = source.getNames(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.CHANGESET_SUBSECTION); for (String commitEntry : createdCommitEntries) { int changesetId = source.getInt(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.CHANGESET_SUBSECTION, commitEntry, -1); target.setInt(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.CHANGESET_SUBSECTION, commitEntry, changesetId); } source.unsetSection(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.CHANGESET_SUBSECTION); source.unsetSection(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.COMMIT_SUBSECTION); try { target.save(); source.save(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:de.blizzy.documentr.repository.ProjectRepositoryManager.java
License:Open Source License
public void importSampleContents() throws IOException, GitAPIException { // TODO: synchronization is not quite correct here, but should be okay in this edge case if (listBranches().isEmpty()) { ILock lock = lockManager.lockAll(); List<String> branches; try {/* w ww . j a v a 2 s. co m*/ File gitDir = new File(centralRepoDir, ".git"); //$NON-NLS-1$ FileUtils.forceDelete(gitDir); Git.cloneRepository().setURI(DocumentrConstants.SAMPLE_REPO_URL).setDirectory(gitDir).setBare(true) .call(); Repository centralRepo = null; File centralRepoGitDir; try { centralRepo = getCentralRepositoryInternal(true); centralRepoGitDir = centralRepo.getDirectory(); StoredConfig config = centralRepo.getConfig(); config.unsetSection("remote", "origin"); //$NON-NLS-1$ //$NON-NLS-2$ config.unsetSection("branch", "master"); //$NON-NLS-1$ //$NON-NLS-2$ config.save(); } finally { RepositoryUtil.closeQuietly(centralRepo); } branches = listBranches(); for (String branchName : branches) { File repoDir = new File(reposDir, branchName); Repository repo = null; try { repo = Git.cloneRepository().setURI(centralRepoGitDir.toURI().toString()) .setDirectory(repoDir).call().getRepository(); Git git = Git.wrap(repo); RefSpec refSpec = new RefSpec( "refs/heads/" + branchName + ":refs/remotes/origin/" + branchName); //$NON-NLS-1$ //$NON-NLS-2$ git.fetch().setRemote("origin").setRefSpecs(refSpec).call(); //$NON-NLS-1$ git.branchCreate().setName(branchName).setStartPoint("origin/" + branchName).call(); //$NON-NLS-1$ git.checkout().setName(branchName).call(); } finally { RepositoryUtil.closeQuietly(repo); } } } finally { lockManager.unlock(lock); } for (String branch : branches) { eventBus.post(new BranchCreatedEvent(projectName, branch)); } } }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.agent.UpdaterImpl.java
License:Apache License
protected void removeUrlSections() throws VcsException { Repository r = null;/*from w w w. j a v a2s . c o m*/ try { r = new RepositoryBuilder().setWorkTree(myTargetDirectory).build(); StoredConfig config = r.getConfig(); Set<String> urlSubsections = config.getSubsections("url"); for (String subsection : urlSubsections) { config.unsetSection("url", subsection); } config.save(); } catch (IOException e) { String msg = "Error while remove url.* sections"; LOG.error(msg, e); throw new VcsException(msg, e); } finally { if (r != null) r.close(); } }
From source file:net.polydawn.mdm.commands.MdmRemoveCommand.java
License:Open Source License
public MdmExitMessage call() throws IOException, MdmException { try {/*from w ww . j a va2 s. com*/ assertInRepoRoot(); } catch (MdmExitMessage e) { return e; } // touch up args a tad. tab completion in the terminal tends to suggest *almost* what you want, but with a trailing slash because it's a directory, and git doesn't like that slash. so, we'll sand down that sharp corner a bit. String name = args.getString("name"); if (name.endsWith("/")) name = name.substring(0, name.length() - 1); // load up config StoredConfig gitmodulesCfg = new FileBasedConfig(new File(repo.getWorkTree(), Constants.DOT_GIT_MODULES), repo.getFS()); try { gitmodulesCfg.load(); } catch (ConfigInvalidException e) { throw new MdmExitInvalidConfig(Constants.DOT_GIT_MODULES); } // if there's no module there, we haven't got much to do try { MdmModuleDependency.load(repo, name, gitmodulesCfg); } catch (MdmModuleTypeException _) { return new MdmExitMessage(":I", "there is no mdm dependency by that name."); } // stage the remove and blow away the repo dirs try { new Git(repo).rm().setCached(true).addFilepattern(name).call(); } catch (NoFilepatternException e) { throw new MajorBug(e); // why would an api throw exceptions like this *checked*? } catch (GitAPIException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } IOForge.delete(new File(repo.getWorkTree(), name)); IOForge.delete(new File(repo.getDirectory(), "modules/" + name)); // if this is one of the newer version of git (specifically, 1.7.8 or newer) that stores the submodule's data in the parent projects .git dir, clear that out forcefully as well. // blow away gitmodule config section gitmodulesCfg.unsetSection(ConfigConstants.CONFIG_SUBMODULE_SECTION, name); gitmodulesCfg.save(); // commit the changes try { new Git(repo).add().addFilepattern(name).addFilepattern(Constants.DOT_GIT_MODULES).call(); } catch (NoFilepatternException e) { throw new MajorBug(e); // why would an api throw exceptions like this *checked*? } catch (GitAPIException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } try { new Git(repo).commit().setOnly(name).setOnly(Constants.DOT_GIT_MODULES) .setMessage("removing dependency on " + name + ".").call(); } catch (NoHeadException e) { throw new MdmException("your repository is in an invalid state!", e); } catch (NoMessageException e) { throw new MajorBug(e); // why would an api throw exceptions like this *checked*? } catch (UnmergedPathsException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } catch (ConcurrentRefUpdateException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } catch (WrongRepositoryStateException e) { 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); } // clear out local git config StoredConfig localConfig = repo.getConfig(); localConfig.unsetSection(ConfigConstants.CONFIG_SUBMODULE_SECTION, name); localConfig.save(); return new MdmExitMessage(":D", "removed dependency on " + name + "!"); }
From source file:org.apache.maven.scm.provider.git.jgit.command.checkin.JGitCheckInCommandCommitterAuthorTckTest.java
License:Apache License
/** * make sure the local .gitconfig is in a clean state *///from ww w . ja va2s .com private void unsetConfig(StoredConfig config) { config.unsetSection("user", null); config.unset("user", null, "name"); // somehow unset does not always work on "user" config.setString("user", null, "name", null); config.setString("user", null, "email", null); config.unsetSection(JGitCheckInCommand.GIT_MAVEN_SECTION, null); }
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 + "'"); }/* w ww. j a v a 2s . co 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.egit.ui.internal.push.PushBranchWizardTest.java
License:Open Source License
private void removeExistingRemotes() throws IOException { StoredConfig config = repository.getConfig(); Set<String> remotes = config.getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION); for (String remoteName : remotes) config.unsetSection(ConfigConstants.CONFIG_REMOTE_SECTION, remoteName); config.save();/*from w w w . ja va 2 s . c o m*/ }
From source file:org.eclipse.egit.ui.internal.repository.tree.command.RemoveRemoteCommand.java
License:Open Source License
public Object execute(ExecutionEvent event) throws ExecutionException { final RemoteNode node = getSelectedNodes(event).get(0); final String configName = node.getObject(); boolean ok = MessageDialog.openConfirm(getShell(event), UIText.RepositoriesView_ConfirmDeleteRemoteHeader, NLS.bind(UIText.RepositoriesView_ConfirmDeleteRemoteMessage, configName)); if (ok) {/*from ww w . ja v a 2 s .com*/ StoredConfig config = node.getRepository().getConfig(); config.unsetSection(RepositoriesView.REMOTE, configName); try { config.save(); } catch (IOException e1) { Activator.handleError(UIText.RepositoriesView_ErrorHeader, e1, true); } } return null; }
From source file:org.eclipse.egit.ui.view.repositories.GitRepositoriesViewRemoteHandlingTest.java
License:Open Source License
private void removeRemotesConfig(File file) throws Exception { Repository repo = lookupRepository(file); StoredConfig config = repo.getConfig(); for (String remote : config.getSubsections("remote")) config.unsetSection("remote", remote); config.save();//from w w w . j a v a 2s . c o m waitInUI(); }