List of usage examples for org.eclipse.jgit.lib Repository getConfig
@NonNull public abstract StoredConfig getConfig();
From source file:org.eclipse.orion.server.tests.servlets.git.GitSubmoduleTest.java
License:Open Source License
@Test public void testSyncSubmodule() throws IOException, SAXException, JSONException, CoreException, ConfigInvalidException { createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); String workspaceId = getWorkspaceId(workspaceLocation); JSONObject project = createProjectOrLink(workspaceLocation, getMethodName().concat("Project1"), null); JSONObject clone = clone(workspaceId, project); String contentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION); String submoduleLocation = clone.getString(GitConstants.KEY_SUBMODULE); String location = clone.getString(ProtocolConstants.KEY_LOCATION); Repository repository = getRepositoryForContentLocation(contentLocation); File file = new File(repository.getWorkTree(), DOT_GIT_MODULES); assertFalse(file.exists());/* ww w . ja va2 s . c o m*/ URIish uri = new URIish(gitDir.toURI().toURL()); WebRequest request = postSubmoduleRequest(submoduleLocation, "test", uri.toString(), location); WebResponse response = webConversation.getResponse(request); file = new File(repository.getWorkTree(), DOT_GIT_MODULES); assertTrue(file.exists()); assertNotNull(repository); StoredConfig repoConfig = repository.getConfig(); String originalUrl = repoConfig.getString("submodule", "test", "url"); repoConfig.setString("submodule", "test", "url", "value"); repoConfig.save(); assertEquals(repoConfig.getString("submodule", "test", "url"), "value"); WebRequest reqSync = putSubmoduleRequest(submoduleLocation, "sync"); WebResponse resSync = webConversation.getResponse(reqSync); repoConfig = repository.getConfig(); assertEquals(repoConfig.getString("submodule", "test", "url"), originalUrl); }
From source file:org.eclipse.winery.repository.backend.filebased.GitBasedRepository.java
License:Open Source License
/** * @param gitBasedRepositoryConfiguration the configuration of the repository * @throws IOException thrown if repository does not exist * @throws GitAPIException thrown if there was an error while checking the status of the repository * @throws NoWorkTreeException thrown if the directory is not a git work tree *//*from w w w. j a v a 2 s . c om*/ public GitBasedRepository(GitBasedRepositoryConfiguration gitBasedRepositoryConfiguration) throws IOException, NoWorkTreeException, GitAPIException { super(Objects.requireNonNull(gitBasedRepositoryConfiguration)); this.gitBasedRepositoryConfiguration = gitBasedRepositoryConfiguration; FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository gitRepo = builder.setWorkTree(this.repositoryRoot.toFile()).setMustExist(false).build(); String repoUrl = gitBasedRepositoryConfiguration.getRepositoryUrl(); String branch = gitBasedRepositoryConfiguration.getBranch(); if (!Files.exists(this.repositoryRoot.resolve(".git"))) { if (repoUrl != null && !repoUrl.isEmpty()) { this.git = cloneRepository(repoUrl, branch); } else { gitRepo.create(); this.git = new Git(gitRepo); } } else { this.git = new Git(gitRepo); } if (this.repositoryRoot.resolve(Constants.DEFAULT_LOCAL_REPO_NAME).toFile().exists()) { if (!(this instanceof MultiRepository)) { this.workingRepositoryRoot = this.repositoryRoot.resolve(Constants.DEFAULT_LOCAL_REPO_NAME); } else { this.workingRepositoryRoot = repositoryDep; } } else { this.workingRepositoryRoot = repositoryDep; } this.eventBus = new EventBus(); // explicitly enable longpaths to ensure proper handling of long pathss gitRepo.getConfig().setBoolean("core", null, "longpaths", true); gitRepo.getConfig().save(); if (gitBasedRepositoryConfiguration.isAutoCommit() && !this.git.status().call().isClean()) { this.addCommit("Files changed externally."); } }
From source file:org.eluder.coveralls.maven.plugin.domain.GitRepository.java
License:Open Source License
private List<Git.Remote> getRemotes(final Repository repository) { Config config = repository.getConfig(); List<Git.Remote> remotes = new ArrayList<Git.Remote>(); for (String remote : config.getSubsections("remote")) { String url = config.getString("remote", remote, "url"); remotes.add(new Git.Remote(remote, url)); }//from w ww . j av a 2 s . c o m return remotes; }
From source file:org.flowerplatform.web.git.explorer.Remote_VirtualItemChildrenProvider.java
License:Open Source License
@Override public Collection<Pair<Object, String>> getChildrenForNode(Object node, TreeNode treeNode, GenericTreeContext context) {/*from w w w . j a va 2 s. co m*/ @SuppressWarnings("unchecked") Repository repository = ((Pair<Repository, String>) node).a; Collection<Pair<Object, String>> result = new ArrayList<Pair<Object, String>>(); Set<String> configNames = repository.getConfig().getSubsections(ConfigConstants.CONFIG_KEY_REMOTE); Pair<Object, String> child; RemoteNode realChild; for (String configName : configNames) { realChild = new RemoteNode(repository, configName); child = new Pair<Object, String>(realChild, GitNodeType.NODE_TYPE_REMOTE); result.add(child); } return result; }
From source file:org.flowerplatform.web.git.explorer.Remote_VirtualItemChildrenProvider.java
License:Open Source License
@Override public Boolean nodeHasChildren(Object node, TreeNode treeNode, GenericTreeContext context) { @SuppressWarnings("unchecked") Repository repository = ((Pair<Repository, String>) node).a; return repository.getConfig().getSubsections(ConfigConstants.CONFIG_KEY_REMOTE).size() > 0; }
From source file:org.flowerplatform.web.git.GitService.java
License:Open Source License
@RemoteInvocation public boolean configRemote(ServiceInvocationContext context, List<PathFragment> path, RemoteConfig remoteConfig) {/*from w ww .j a va 2 s. c o m*/ try { Object node = GenericTreeStatefulService.getNodeByPathFor(path, null); GenericTreeStatefulService service = GenericTreeStatefulService.getServiceFromPathWithRoot(path); NodeInfo nodeInfo = service.getVisibleNodes().get(node); Repository repository = getRepository(nodeInfo); org.eclipse.jgit.transport.RemoteConfig repoConfig = new org.eclipse.jgit.transport.RemoteConfig( repository.getConfig(), remoteConfig.getName()); while (repoConfig.getURIs().size() > 0) { URIish uri = repoConfig.getURIs().get(0); repoConfig.removeURI(uri); } repoConfig.addURI(new URIish(remoteConfig.getUri().trim())); repoConfig.update(repository.getConfig()); repository.getConfig().save(); // notify clients about changes dispatchContentUpdate(node); return true; } catch (URISyntaxException e) { logger.debug(CommonPlugin.getInstance().getMessage("error"), path, e); context.getCommunicationChannel().appendOrSendCommand( new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"), e.getReason(), DisplaySimpleMessageClientCommand.ICON_ERROR)); return false; } 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; } }
From source file:org.flowerplatform.web.git.GitService.java
License:Open Source License
@RemoteInvocation public RemoteConfig getRemoteConfigData(ServiceInvocationContext context, List<PathFragment> path) { try {//from ww w .j a v a 2s . c om RemoteNode remoteNode = (RemoteNode) GenericTreeStatefulService.getNodeByPathFor(path, null); Repository repository = remoteNode.getRepository(); if (repository == null) { context.getCommunicationChannel() .appendOrSendCommand(new DisplaySimpleMessageClientCommand( CommonPlugin.getInstance().getMessage("error"), "Cannot find repository for node " + remoteNode, DisplaySimpleMessageClientCommand.ICON_ERROR)); return null; } org.eclipse.jgit.transport.RemoteConfig repoConfig = new org.eclipse.jgit.transport.RemoteConfig( repository.getConfig(), remoteNode.getRemote()); RemoteConfig result = new RemoteConfig(); result.setName(remoteNode.getRemote()); result.setUri(repoConfig.getURIs().get(0).toString()); List<String> fetchSpecs = new ArrayList<String>(); for (RefSpec refspec : repoConfig.getFetchRefSpecs()) { fetchSpecs.add(refspec.toString()); } result.setFetchMappings(fetchSpecs); List<String> pushSpecs = new ArrayList<String>(); for (RefSpec refspec : repoConfig.getPushRefSpecs()) { pushSpecs.add(refspec.toString()); } result.setPushMappings(pushSpecs); return result; } 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 null; } }
From source file:org.flowerplatform.web.git.GitService.java
License:Open Source License
@RemoteInvocation public boolean deleteRemote(ServiceInvocationContext context, List<PathFragment> path) { try {//from w w w.j a v a 2s . co m RemoteNode remoteNode = (RemoteNode) GenericTreeStatefulService.getNodeByPathFor(path, null); Repository repository = remoteNode.getRepository(); GenericTreeStatefulService service = GenericTreeStatefulService.getServiceFromPathWithRoot(path); NodeInfo remoteNodeInfo = service.getVisibleNodes().get(remoteNode); if (repository == null) { context.getCommunicationChannel() .appendOrSendCommand(new DisplaySimpleMessageClientCommand( CommonPlugin.getInstance().getMessage("error"), "Cannot find repository for node " + remoteNode, DisplaySimpleMessageClientCommand.ICON_ERROR)); return false; } StoredConfig config = repository.getConfig(); config.unsetSection("remote", remoteNode.getRemote()); config.save(); dispatchContentUpdate(remoteNodeInfo.getParent().getNode()); return true; } catch (Exception e) { logger.debug(GitPlugin.getInstance().getMessage("git.deleteRemote.error"), e); context.getCommunicationChannel().appendOrSendCommand( new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"), GitPlugin.getInstance().getMessage("git.deleteRemote.error"), e.getMessage(), DisplaySimpleMessageClientCommand.ICON_ERROR)); return false; } }
From source file:org.flowerplatform.web.git.GitService.java
License:Open Source License
@RemoteInvocation public ConfigFetchPushPageDto getFetchPushConfigData(ServiceInvocationContext context, List<PathFragment> path, boolean getFetchData) { try {/*w w w . j a va2 s.c o m*/ Repository repository = (Repository) GenericTreeStatefulService.getNodeByPathFor(path, null); ConfigFetchPushPageDto result = new ConfigFetchPushPageDto(); List<RemoteConfig> list = new ArrayList<RemoteConfig>(); List<org.eclipse.jgit.transport.RemoteConfig> remotes = org.eclipse.jgit.transport.RemoteConfig .getAllRemoteConfigs(repository.getConfig()); for (org.eclipse.jgit.transport.RemoteConfig remote : remotes) { RemoteConfig remoteConfig = new RemoteConfig(); remoteConfig.setName(remote.getName()); remoteConfig.setUri(remote.getURIs().get(0).toString()); if (getFetchData) { List<String> fetchSpecs = new ArrayList<String>(); for (RefSpec refspec : remote.getFetchRefSpecs()) { fetchSpecs.add(refspec.toString()); } remoteConfig.setFetchMappings(fetchSpecs); } else { List<String> pushSpecs = new ArrayList<String>(); for (RefSpec refspec : remote.getPushRefSpecs()) { pushSpecs.add(refspec.toString()); } remoteConfig.setPushMappings(pushSpecs); } list.add(remoteConfig); } result.setRemoteConfigs(list); return result; } 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 null; } }
From source file:org.flowerplatform.web.git.GitService.java
License:Open Source License
@RemoteInvocation public List<RemoteConfig> getAllRemotes(ServiceInvocationContext context, List<PathFragment> path) { try {/*from w w w.j ava2s .com*/ Object node = GenericTreeStatefulService.getNodeByPathFor(path, null); GenericTreeStatefulService service = GenericTreeStatefulService.getServiceFromPathWithRoot(path); NodeInfo nodeInfo = service.getVisibleNodes().get(node); Repository repository = getRepository(nodeInfo); List<RemoteConfig> list = new ArrayList<RemoteConfig>(); List<org.eclipse.jgit.transport.RemoteConfig> remotes = org.eclipse.jgit.transport.RemoteConfig .getAllRemoteConfigs(repository.getConfig()); for (org.eclipse.jgit.transport.RemoteConfig remote : remotes) { RemoteConfig remoteConfig = new RemoteConfig(); remoteConfig.setName(remote.getName()); remoteConfig.setUri(remote.getURIs().get(0).toString()); list.add(remoteConfig); } return list; } 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 null; } }