List of usage examples for org.eclipse.jgit.lib StoredConfig unset
public void unset(final String section, final String subsection, final String name)
From source file:com.gitblit.GitBlit.java
License:Apache License
private void updateList(StoredConfig config, String field, List<String> list) { // a null list is skipped, not cleared // this is for RPC administration where an older manager might be used if (list == null) { return;//from www . j av a 2s. co m } if (ArrayUtils.isEmpty(list)) { config.unset(Constants.CONFIG_GITBLIT, null, field); } else { config.setStringList(Constants.CONFIG_GITBLIT, null, field, list); } }
From source file:com.gitblit.manager.RepositoryManager.java
License:Apache License
/** * Updates the Gitblit configuration for the specified repository. * * @param r//from w w w . j a v a2 s . co m * the Git repository * @param repository * the Gitblit repository model */ @Override public void updateConfiguration(Repository r, RepositoryModel repository) { StoredConfig config = r.getConfig(); config.setString(Constants.CONFIG_GITBLIT, null, "description", repository.description); config.setString(Constants.CONFIG_GITBLIT, null, "originRepository", repository.originRepository); config.setString(Constants.CONFIG_GITBLIT, null, "owner", ArrayUtils.toString(repository.owners)); config.setBoolean(Constants.CONFIG_GITBLIT, null, "acceptNewPatchsets", repository.acceptNewPatchsets); config.setBoolean(Constants.CONFIG_GITBLIT, null, "acceptNewTickets", repository.acceptNewTickets); if (settings.getBoolean(Keys.tickets.requireApproval, false) == repository.requireApproval) { // use default config.unset(Constants.CONFIG_GITBLIT, null, "requireApproval"); } else { // override default config.setBoolean(Constants.CONFIG_GITBLIT, null, "requireApproval", repository.requireApproval); } if (!StringUtils.isEmpty(repository.mergeTo)) { config.setString(Constants.CONFIG_GITBLIT, null, "mergeTo", repository.mergeTo); } if (repository.mergeType == null || repository.mergeType == MergeType.fromName(settings.getString(Keys.tickets.mergeType, null))) { // use default config.unset(Constants.CONFIG_GITBLIT, null, "mergeType"); } else { // override default config.setString(Constants.CONFIG_GITBLIT, null, "mergeType", repository.mergeType.name()); } config.setBoolean(Constants.CONFIG_GITBLIT, null, "useIncrementalPushTags", repository.useIncrementalPushTags); if (StringUtils.isEmpty(repository.incrementalPushTagPrefix) || repository.incrementalPushTagPrefix .equals(settings.getString(Keys.git.defaultIncrementalPushTagPrefix, "r"))) { config.unset(Constants.CONFIG_GITBLIT, null, "incrementalPushTagPrefix"); } else { config.setString(Constants.CONFIG_GITBLIT, null, "incrementalPushTagPrefix", repository.incrementalPushTagPrefix); } config.setBoolean(Constants.CONFIG_GITBLIT, null, "allowForks", repository.allowForks); config.setString(Constants.CONFIG_GITBLIT, null, "accessRestriction", repository.accessRestriction.name()); config.setString(Constants.CONFIG_GITBLIT, null, "authorizationControl", repository.authorizationControl.name()); config.setBoolean(Constants.CONFIG_GITBLIT, null, "verifyCommitter", repository.verifyCommitter); config.setBoolean(Constants.CONFIG_GITBLIT, null, "showRemoteBranches", repository.showRemoteBranches); config.setBoolean(Constants.CONFIG_GITBLIT, null, "isFrozen", repository.isFrozen); config.setBoolean(Constants.CONFIG_GITBLIT, null, "skipSizeCalculation", repository.skipSizeCalculation); config.setBoolean(Constants.CONFIG_GITBLIT, null, "skipSummaryMetrics", repository.skipSummaryMetrics); config.setString(Constants.CONFIG_GITBLIT, null, "federationStrategy", repository.federationStrategy.name()); config.setBoolean(Constants.CONFIG_GITBLIT, null, "isFederated", repository.isFederated); config.setString(Constants.CONFIG_GITBLIT, null, "gcThreshold", repository.gcThreshold); if (repository.gcPeriod == settings.getInteger(Keys.git.defaultGarbageCollectionPeriod, 7)) { // use default from config config.unset(Constants.CONFIG_GITBLIT, null, "gcPeriod"); } else { config.setInt(Constants.CONFIG_GITBLIT, null, "gcPeriod", repository.gcPeriod); } if (repository.lastGC != null) { config.setString(Constants.CONFIG_GITBLIT, null, "lastGC", new SimpleDateFormat(Constants.ISO8601).format(repository.lastGC)); } if (repository.maxActivityCommits == settings.getInteger(Keys.web.maxActivityCommits, 0)) { // use default from config config.unset(Constants.CONFIG_GITBLIT, null, "maxActivityCommits"); } else { config.setInt(Constants.CONFIG_GITBLIT, null, "maxActivityCommits", repository.maxActivityCommits); } CommitMessageRenderer defaultRenderer = CommitMessageRenderer .fromName(settings.getString(Keys.web.commitMessageRenderer, null)); if (repository.commitMessageRenderer == null || repository.commitMessageRenderer == defaultRenderer) { // use default from config config.unset(Constants.CONFIG_GITBLIT, null, "commitMessageRenderer"); } else { // repository overrides default config.setString(Constants.CONFIG_GITBLIT, null, "commitMessageRenderer", repository.commitMessageRenderer.name()); } updateList(config, "federationSets", repository.federationSets); updateList(config, "preReceiveScript", repository.preReceiveScripts); updateList(config, "postReceiveScript", repository.postReceiveScripts); updateList(config, "mailingList", repository.mailingLists); updateList(config, "indexBranch", repository.indexedBranches); updateList(config, "metricAuthorExclusions", repository.metricAuthorExclusions); // User Defined Properties if (repository.customFields != null) { if (repository.customFields.size() == 0) { // clear section config.unsetSection(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS); } else { for (Entry<String, String> property : repository.customFields.entrySet()) { // set field String key = property.getKey(); String value = property.getValue(); config.setString(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS, key, value); } } } try { config.save(); } catch (IOException e) { logger.error("Failed to save repository config!", e); } }
From source file:eu.cloud4soa.cli.roo.addon.commands.GitManager.java
License:Apache License
public void setConfig() throws URISyntaxException, IOException, GitAPIException { StoredConfig config = gitRepository.getConfig(); if (config.getString("remote", repoName, "url") == null || config.getString("remote", repoName, "url") != gitProxyUrl) { config.unset("remote", repoName, "url"); RemoteConfig remoteConfig = new RemoteConfig(config, repoName); //cloud@94.75.243.141/proxyname.git //proxy<userid><applicationid>.git? // String gitUrl = gitUser+"@"+gitProxyUrl+"/proxy"+this.userId+this.applicationId+".git"; URIish uri = new URIish(gitProxyUrl); remoteConfig.addURI(uri);//ww w. j a v a 2 s .com config.unset("remote", repoName, "fetch"); RefSpec spec = new RefSpec("+refs/heads/*:refs/remotes/" + repoName + "/*"); remoteConfig.addFetchRefSpec(spec); remoteConfig.update(config); } if (config.getString("branch", "master", "remote") == null || config.getString("branch", "master", "remote") != repoName) { config.unset("branch", "master", "remote"); config.setString("branch", "master", "remote", repoName); } if (config.getString("branch", "master", "merge") == null || config.getString("branch", "master", "merge") != "refs/heads/master") { config.unset("branch", "master", "merge"); config.setString("branch", "master", "merge", "refs/heads/master"); } config.save(); }
From source file:net.morimekta.gittool.cmd.Branch.java
License:Apache License
@Override public void execute(GitTool gt) throws IOException { this.gt = gt; ArrayList<InputSelection.Command<BranchInfo>> actions = new ArrayList<>(5); actions.add(new InputSelection.Command<>(Char.CR, "select", this::onSelect, true)); actions.add(new InputSelection.Command<>('D', "delete", this::onDelete)); actions.add(new InputSelection.Command<>('q', "quit", this::onExit)); actions.add(new InputSelection.Command<>('d', "set diffbase", this::onSetDiffbase)); actions.add(new InputSelection.Command<>('m', "move", this::onRename)); STTY tty = new STTY(); try (Terminal terminal = new Terminal(tty)) { try (Repository repositoryResource = gt.getRepository()) { this.repository = repositoryResource; this.git = new Git(repositoryResource); BranchInfo tmp = refreshBranchList(null); prompt = "Manage branches from '" + currentInfo.name + "':"; while (true) { action = null;/*from w ww . j a v a 2 s . co m*/ try { InputSelection<BranchInfo> selection = new InputSelection<>(terminal, prompt, branches, actions, BranchInfo::branchLine); tmp = selection.select(tmp); } catch (UncheckedIOException e) { // Most likely: User interrupted: // <ESC>, <CTRL-C> etc. System.out.println(e.getMessage()); return; } if (tmp == null) { // command action EXIT. return; } if (action == null) { continue; } final BranchInfo selected = tmp; switch (action) { case CHECKOUT: { Ref ref = git.checkout().setName(selected.name).call(); if (ref == null) { terminal.error("No ref from checkout op..."); break; } return; } case DELETE: { if (selected.commits == 0 || terminal .confirm("Do you really want to delete branch " + YELLOW + selected.name + CLEAR + " with " + GREEN + "+" + selected.commits + CLEAR + " commits?")) { git.branchDelete().setBranchNames(selected.name).call(); terminal.info("Deleted branch " + RED + selected.name + CLEAR + "!"); tmp = currentInfo; } else { terminal.info("Delete canceled."); return; } tmp = refreshBranchList(tmp.name); terminal.println(); break; } case RENAME: { String name; try { InputLine input = new InputLine(terminal, "New name for " + YELLOW + selected.name + CLEAR); name = input.readLine(selected.name); } catch (UncheckedIOException e) { // Most likely user interruption. terminal.info(e.getMessage()); terminal.println(); break; } if (selected.name.equals(name)) { terminal.info("Same same same..."); terminal.println(); break; } Ref ref = git.branchRename().setOldName(selected.name).setNewName(name).call(); if (ref == null) { terminal.error("No ref from branch rename operation..."); return; } terminal.println(); tmp = refreshBranchList(selected.name); break; } case SET_DIFFBASE: { if (selected.name.equals(gt.getDefaultBranch())) { // TODO: Replace list with remotes only... terminal.warn(format("Setting diffbase on %s%s%s branch!", Color.BOLD, selected.name, Color.CLEAR)); terminal.println(); break; } List<BranchInfo> options = new LinkedList<>(branches).stream().filter(b -> { // cannot have self as diffbase if (b == selected) return false; // avoid circular diffs. return !selected.name.equals(b.diffbase); }).collect(Collectors.toList()); if (options.size() == 0) { terminal.info("No possible diffbase branches for " + selected.name); break; } terminal.println(); ArrayList<InputSelection.Command<BranchInfo>> diffbaseActions = new ArrayList<>(5); diffbaseActions.add(new InputSelection.Command<>(Char.CR, "select", (br, lp) -> InputSelection.Reaction.SELECT, true)); diffbaseActions.add(new InputSelection.Command<>('c', "clear", (br, lp) -> { try { StoredConfig config = git.getRepository().getConfig(); config.unset("branch", selected.name, "diffbase"); config.save(); return InputSelection.Reaction.EXIT; } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } })); diffbaseActions.add(new InputSelection.Command<>('q', "quit", (br, lp) -> InputSelection.Reaction.EXIT)); InputSelection<BranchInfo> selection = new InputSelection<>(terminal, "Select diffbase for '" + selected.name + "':", options, diffbaseActions, BranchInfo::selectionLine); BranchInfo oldDiffbase = branches.stream().filter(b -> b.name.equals(selected.diffbase)) .findFirst().orElse(null); BranchInfo newDiffbase = selection.select(oldDiffbase); if (newDiffbase != null) { StoredConfig config = git.getRepository().getConfig(); config.setString("branch", selected.name, "diffbase", newDiffbase.name); config.save(); tmp = refreshBranchList(selected.name); } terminal.println(); break; } default: { terminal.warn("Not implemented: " + action.name()); terminal.println(); break; } } } } catch (GitAPIException e) { terminal.fatal("GIT: " + e.getMessage()); throw new IllegalStateException(e.getMessage(), e); } } }
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 *//*w w w.j ava2 s .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 + "'"); }//from w w w . j a v a 2s. 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.egit.ui.internal.repository.tree.command.DeleteFetchCommand.java
License:Open Source License
public Object execute(ExecutionEvent event) throws ExecutionException { FetchNode node = getSelectedNodes(event).get(0); RemoteNode remote = (RemoteNode) node.getParent(); StoredConfig config = node.getRepository().getConfig(); String fetchUrl = config.getString(REMOTE, remote.getObject(), URL); config.unset(REMOTE, remote.getObject(), FETCH); config.unset(REMOTE, remote.getObject(), URL); // the push URL may still be needed for fetch if (fetchUrl != null) { boolean hasPush = config.getStringList(REMOTE, remote.getObject(), PUSH).length > 0; if (hasPush) { String[] pushurls = config.getStringList(REMOTE, remote.getObject(), PUSHURL); // if there are not specific push urls, // copy the former fetch url into push url if (pushurls.length == 0) config.setString(REMOTE, remote.getObject(), PUSHURL, fetchUrl); }// ww w.j a va2 s.co m } try { config.save(); } catch (IOException e1) { Activator.handleError(e1.getMessage(), e1, true); } return null; }
From source file:org.eclipse.egit.ui.internal.repository.tree.command.DeletePushCommand.java
License:Open Source License
public Object execute(ExecutionEvent event) throws ExecutionException { PushNode node = getSelectedNodes(event).get(0); RemoteNode remote = (RemoteNode) node.getParent(); StoredConfig config = node.getRepository().getConfig(); config.unset("remote", remote.getObject(), "pushurl"); //$NON-NLS-1$ //$NON-NLS-2$ config.unset("remote", remote.getObject(), "push"); //$NON-NLS-1$ //$NON-NLS-2$ try {/* w w w. j a v a 2 s .co m*/ config.save(); } catch (IOException e1) { Activator.handleError(e1.getMessage(), e1, true); } return null; }
From source file:org.eclipse.oomph.setup.git.impl.GitCloneTaskImpl.java
License:Open Source License
private static void configureRepository(SetupTaskContext context, Repository repository, String checkoutBranch, String remoteName, String remoteURI, String pushURI, List<? extends ConfigSection> configSections) throws Exception, IOException { StoredConfig config = repository.getConfig(); Map<String, Map<String, Map<String, List<String>>>> properties = new LinkedHashMap<String, Map<String, Map<String, List<String>>>>(); for (ConfigSection section : configSections) { String sectionName = section.getName(); if (!StringUtil.isEmpty(sectionName)) { for (ConfigProperty property : section.getProperties()) { handleProperty(properties, sectionName, null, property); }// ww w. j a v a 2 s. com for (ConfigSubsection subsection : section.getSubsections()) { String subsectionName = subsection.getName(); if (subsectionName != null) { for (ConfigProperty property : subsection.getProperties()) { handleProperty(properties, sectionName, subsectionName, property); } } } } } boolean changed = false; boolean hasAutoCRLFProperty = false; for (Map.Entry<String, Map<String, Map<String, List<String>>>> sectionEntry : properties.entrySet()) { String sectionName = sectionEntry.getKey(); for (Map.Entry<String, Map<String, List<String>>> subsectionEntry : sectionEntry.getValue() .entrySet()) { String subsectionName = subsectionEntry.getKey(); for (Map.Entry<String, List<String>> propertyEntry : subsectionEntry.getValue().entrySet()) { String key = propertyEntry.getKey(); if ("core".equals(sectionName) && subsectionName == null && "autocrlf".equals(key)) { hasAutoCRLFProperty = true; } List<String> value = propertyEntry.getValue(); String[] oldValue = config.getStringList(sectionName, subsectionName, key); if (value.isEmpty()) { config.unset(sectionName, subsectionName, key); changed |= oldValue.length != 0; } else { config.setStringList(sectionName, subsectionName, key, value); changed |= !Arrays.asList(oldValue).equals(value); } } } } if (!hasAutoCRLFProperty) { changed |= configureLineEndingConversion(context, config); } Set<String> gerritPatterns = new HashSet<String>(); for (Object key : context.keySet()) { if (key instanceof String) { if (key.toString().endsWith(".gerrit.uri.pattern")) { Object value = context.get(key); if (value instanceof String) { gerritPatterns.add(value.toString()); } } } } if (!gerritPatterns.isEmpty()) { URI uri = URI.createURI(remoteURI); String uriString = uri.toString(); for (String gerritPattern : gerritPatterns) { if (uriString.matches(gerritPattern)) { changed |= addGerritPullRefSpec(context, config, remoteName); changed |= addGerritPushRefSpec(context, config, checkoutBranch, remoteName); break; } } } changed |= addPushURI(context, config, remoteName, pushURI); if (changed) { config.save(); } }
From source file:org.flowerplatform.web.git.GitService.java
License:Open Source License
@RemoteInvocation public boolean configBranch(ServiceInvocationContext context, List<PathFragment> path, GitRef upstreamBranch, RemoteConfig remote, boolean rebase) { try {//ww w . j a va 2 s .c o m RefNode node = (RefNode) GenericTreeStatefulService.getNodeByPathFor(path, null); Repository repository = node.getRepository(); StoredConfig config = repository.getConfig(); Ref ref; if (node instanceof Ref) { ref = node.getRef(); } else { // get remote branch String dst = Constants.R_REMOTES + remote.getName(); String remoteRefName = dst + "/" + upstreamBranch.getShortName(); ref = repository.getRef(remoteRefName); if (ref == null) { // doesn't exist, fetch it RefSpec refSpec = new RefSpec(); refSpec = refSpec.setForceUpdate(true); refSpec = refSpec.setSourceDestination(upstreamBranch.getName(), remoteRefName); new Git(repository).fetch().setRemote(new URIish(remote.getUri()).toPrivateString()) .setRefSpecs(refSpec).call(); ref = repository.getRef(remoteRefName); } } String branchName = node.getRef().getName().substring(Constants.R_HEADS.length()); if (upstreamBranch.getName().length() > 0) { config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_MERGE, upstreamBranch.getName()); } else { config.unset(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_MERGE); } if (remote.getName().length() > 0) { config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REMOTE, remote.getName()); } else { config.unset(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REMOTE); } if (rebase) { config.setBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REBASE, true); } else { config.unset(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REBASE); } config.save(); return true; } catch (Exception e) { logger.debug(CommonPlugin.getInstance().getMessage("error"), path, e); context.getCommunicationChannel().appendOrSendCommand( new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"), e.getMessage(), DisplaySimpleMessageClientCommand.ICON_ERROR)); return false; } }