List of usage examples for org.eclipse.jgit.lib StoredConfig getString
public String getString(final String section, String subsection, final String name)
From source file:org.jboss.forge.rest.main.GitCommandCompletePostProcessor.java
License:Apache License
protected void configureBranch(Git git, String branch, String remote) { // lets update the merge config if (!Strings.isNullOrEmpty(branch)) { StoredConfig config = git.getRepository().getConfig(); if (io.hawt.util.Strings.isBlank(config.getString("branch", branch, "remote")) || io.hawt.util.Strings.isBlank(config.getString("branch", branch, "merge"))) { config.setString("branch", branch, "remote", remote); config.setString("branch", branch, "merge", "refs/heads/" + branch); try { config.save();/*from w w w . j av a2 s. c om*/ } catch (IOException e) { LOG.error("Failed to save the git configuration to " + git.getRepository().getDirectory() + " with branch " + branch + " on remote repo: " + remote + " due: " + e.getMessage() + ". This exception is ignored.", e); } } } }
From source file:org.jboss.tools.openshift.egit.internal.test.EGitUtilsTest.java
License:Open Source License
@Test public void shouldUserFetchSpecInConfig() throws Exception { testRepository.addRemoteTo(REPO2_REMOTE_NAME, testRepository2.getRepository()); // add custom fetch-spec in config (fetch = refs/heads/master:refs/remotes/bingo/master) StoredConfig config = testRepository.getRepository().getConfig(); config.getString(ConfigConstants.CONFIG_KEY_REMOTE, REPO2_REMOTE_NAME, "fetch"); String remoteTrackingBranchRef = "refs/remotes/bingo/master"; String fetchSpec = "refs/heads/master:" + remoteTrackingBranchRef; config.setString(ConfigConstants.CONFIG_KEY_REMOTE, REPO2_REMOTE_NAME, "fetch", fetchSpec); config.save();//from w ww.j a v a 2 s . c o m EGitUtils.isAhead(testRepository.getRepository(), REPO2_REMOTE_NAME, null); // was remote tracking branch created? assertTrue(testRepository.getRepository().getAllRefs().containsKey(remoteTrackingBranchRef)); }
From source file:org.jboss.tools.openshift.egit.internal.test.EGitUtilsTest.java
License:Open Source License
@Test public void canAddRemoteRepo() throws Exception { Repository repository = testRepository.getRepository(); String remoteName = "redhat"; String gitUri = "www.redhat.com"; EGitUtils.addRemoteTo(remoteName, gitUri, repository); StoredConfig config = repository.getConfig(); Set<String> subsections = config.getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION); assertEquals(1, subsections.size()); assertTrue(subsections.contains(remoteName)); assertEquals(gitUri, config.getString(ConfigConstants.CONFIG_REMOTE_SECTION, remoteName, ConfigConstants.CONFIG_KEY_URL)); }
From source file:org.kie.eclipse.navigator.view.server.KieRepositoryHandler.java
License:Open Source License
public Object load() { if (repository == null) { final File repoRoot = new File(PreferencesUtils.getRepoRoot(this)); final Set<File> gitDirs = new HashSet<File>(); final IRunnableWithProgress runnable = new IRunnableWithProgress() { @Override/*ww w.jav a 2s . co m*/ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Searching for Repositories", IProgressMonitor.UNKNOWN); try { findGitDirsRecursive(repoRoot, gitDirs, monitor, false); } catch (Exception ex) { ex.printStackTrace(); } if (monitor.isCanceled()) { throw new InterruptedException(); } } }; IProgressService ps = PlatformUI.getWorkbench().getProgressService(); try { ps.busyCursorWhile(runnable); } catch (InvocationTargetException | InterruptedException e) { e.printStackTrace(); } for (File dir : gitDirs) { if (getName().equals(dir.getParentFile().getName())) { try { Repository repository = repositoryCache.lookupRepository(dir); StoredConfig storedConfig = repository.getConfig(); Set<String> remotes = storedConfig.getSubsections("remote"); for (String remoteName : remotes) { String url = storedConfig.getString("remote", remoteName, "url"); System.out.println(repository.getDirectory()); System.out.println(url); try { URI u = new URI(url); int port = u.getPort(); String host = u.getHost(); String scheme = u.getScheme(); String path[] = u.getPath().split("/"); String repoName = path[path.length - 1]; if (name.equals(repoName) && host.equals(getServer().getHost()) && port == getDelegate().getGitPort() && "ssh".equals(scheme)) { this.repository = repository; break; } } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } if (repository != null) // TODO: why doesn't this work? repository.getListenerList().addListener(ConfigChangedListener.class, this); } return repository; }
From source file:org.kie.eclipse.server.KieRepositoryHandler.java
License:Open Source License
@Override public Object load() { if (repository == null) { try {/* w w w . j a v a 2s . c o m*/ final File repoRoot = new File(PreferencesUtils.getRepoRoot(this)); final Set<File> gitDirs = new HashSet<File>(); GitUtils.findGitDirsRecursive(repoRoot, gitDirs, false); for (File dir : gitDirs) { if (getName().equals(dir.getParentFile().getName())) { Git git = Git.open(dir); Repository repository = git.getRepository(); StoredConfig storedConfig = repository.getConfig(); Set<String> remotes = storedConfig.getSubsections("remote"); for (String remoteName : remotes) { try { String url = storedConfig.getString("remote", remoteName, "url"); URI uri = new URI(url); int port = uri.getPort(); String host = uri.getHost(); String scheme = uri.getScheme(); String path[] = uri.getPath().split("/"); String repoName = path[path.length - 1]; if (name.equals(repoName) && host.equals(getServer().getHost()) && port == getDelegate().getGitPort() && "ssh".equals(scheme)) { this.repository = repository; break; } } catch (Exception e) { e.printStackTrace(); } finally { if (git != null) { git.close(); git = null; } } } } } } catch (Exception e) { e.printStackTrace(); } } return repository; }
From source file:org.omegat.convert.ConvertProject26to37team.java
License:Open Source License
/** * Get repository URL for SVN./* w w w . ja va 2 s . com*/ */ private static String getGITUrl(File wc) throws Exception { Repository repository = Git.open(wc).getRepository(); StoredConfig config = repository.getConfig(); return config.getString("remote", "origin", "url"); }
From source file:org.springframework.cloud.config.server.environment.JGitEnvironmentRepositoryTests.java
License:Apache License
@Test public void shouldPullForcepullNotClean() throws Exception { Git git = mock(Git.class); StatusCommand statusCommand = mock(StatusCommand.class); Status status = mock(Status.class); Repository repository = mock(Repository.class); StoredConfig storedConfig = mock(StoredConfig.class); when(git.status()).thenReturn(statusCommand); when(git.getRepository()).thenReturn(repository); when(repository.getConfig()).thenReturn(storedConfig); when(storedConfig.getString("remote", "origin", "url")).thenReturn("http://example/git"); when(statusCommand.call()).thenReturn(status); when(status.isClean()).thenReturn(false); JGitEnvironmentRepository repo = new JGitEnvironmentRepository(this.environment); repo.setForcePull(true);/*from www .j a v a 2 s . com*/ boolean shouldPull = repo.shouldPull(git); assertThat("shouldPull was false", shouldPull, is(true)); }
From source file:org.springframework.cloud.config.server.environment.JGitEnvironmentRepositoryTests.java
License:Apache License
@Test public void shouldPullNotClean() throws Exception { Git git = mock(Git.class); StatusCommand statusCommand = mock(StatusCommand.class); Status status = mock(Status.class); Repository repository = mock(Repository.class); StoredConfig storedConfig = mock(StoredConfig.class); when(git.status()).thenReturn(statusCommand); when(git.getRepository()).thenReturn(repository); when(repository.getConfig()).thenReturn(storedConfig); when(storedConfig.getString("remote", "origin", "url")).thenReturn("http://example/git"); when(statusCommand.call()).thenReturn(status); when(status.isClean()).thenReturn(false); JGitEnvironmentRepository repo = new JGitEnvironmentRepository(this.environment); boolean shouldPull = repo.shouldPull(git); assertThat("shouldPull was true", shouldPull, is(false)); }
From source file:org.springframework.cloud.config.server.environment.JGitEnvironmentRepositoryTests.java
License:Apache License
@Test public void shouldPullClean() throws Exception { Git git = mock(Git.class); StatusCommand statusCommand = mock(StatusCommand.class); Status status = mock(Status.class); Repository repository = mock(Repository.class); StoredConfig storedConfig = mock(StoredConfig.class); when(git.status()).thenReturn(statusCommand); when(git.getRepository()).thenReturn(repository); when(repository.getConfig()).thenReturn(storedConfig); when(storedConfig.getString("remote", "origin", "url")).thenReturn("http://example/git"); when(statusCommand.call()).thenReturn(status); when(status.isClean()).thenReturn(true); JGitEnvironmentRepository repo = new JGitEnvironmentRepository(this.environment); boolean shouldPull = repo.shouldPull(git); assertThat("shouldPull was false", shouldPull, is(true)); }
From source file:org.springframework.cloud.config.server.environment.JGitEnvironmentRepositoryTests.java
License:Apache License
@Test public void testFetchException() throws Exception { Git git = mock(Git.class); CloneCommand cloneCommand = mock(CloneCommand.class); MockGitFactory factory = new MockGitFactory(git, cloneCommand); JGitEnvironmentRepository repo = new JGitEnvironmentRepository(this.environment); this.repository.setGitFactory(factory); //refresh()->shouldPull StatusCommand statusCommand = mock(StatusCommand.class); Status status = mock(Status.class); when(git.status()).thenReturn(statusCommand); Repository repository = mock(Repository.class); when(git.getRepository()).thenReturn(repository); StoredConfig storedConfig = mock(StoredConfig.class); when(repository.getConfig()).thenReturn(storedConfig); when(storedConfig.getString("remote", "origin", "url")).thenReturn("http://example/git"); when(statusCommand.call()).thenReturn(status); when(status.isClean()).thenReturn(true); //refresh()->fetch FetchCommand fetchCommand = mock(FetchCommand.class); when(git.fetch()).thenReturn(fetchCommand); when(fetchCommand.setRemote(anyString())).thenReturn(fetchCommand); when(fetchCommand.call()).thenThrow(new InvalidRemoteException("invalid mock remote")); //here is our exception we are testing //refresh()->checkout CheckoutCommand checkoutCommand = mock(CheckoutCommand.class); //refresh()->checkout->containsBranch ListBranchCommand listBranchCommand = mock(ListBranchCommand.class); when(git.checkout()).thenReturn(checkoutCommand); when(git.branchList()).thenReturn(listBranchCommand); List<Ref> refs = new ArrayList<>(); Ref ref = mock(Ref.class); refs.add(ref);//from w ww. j av a2 s . co m when(ref.getName()).thenReturn("/master"); when(listBranchCommand.call()).thenReturn(refs); //refresh()->merge MergeCommand mergeCommand = mock(MergeCommand.class); when(git.merge()).thenReturn(mergeCommand); when(mergeCommand.call()).thenThrow(new NotMergedException()); //here is our exception we are testing //refresh()->return git.getRepository().getRef("HEAD").getObjectId().getName(); Ref headRef = mock(Ref.class); when(repository.getRef(anyString())).thenReturn(headRef); ObjectId newObjectId = ObjectId.fromRaw(new int[] { 1, 2, 3, 4, 5 }); when(headRef.getObjectId()).thenReturn(newObjectId); SearchPathLocator.Locations locations = this.repository.getLocations("bar", "staging", null); assertEquals(locations.getVersion(), newObjectId.getName()); }