List of usage examples for org.eclipse.jgit.lib Repository getConfig
@NonNull public abstract StoredConfig getConfig();
From source file:org.eclipse.egit.ui.view.repositories.GitRepositoriesViewTestBase.java
License:Open Source License
protected static File createProjectAndCommitToRepository() throws Exception { File gitDir = new File(new File(getTestDirectory(), REPO1), Constants.DOT_GIT); gitDir.mkdir();//from www. j a v a2s .c o m Repository myRepository = lookupRepository(gitDir); myRepository.create(); // TODO Bug: for some reason, this seems to be required myRepository.getConfig().setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, "0"); myRepository.getConfig().save(); // we need to commit into master first IProject firstProject = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1); if (firstProject.exists()) firstProject.delete(true, null); IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(PROJ1); desc.setLocation(new Path(new File(myRepository.getWorkTree(), PROJ1).getPath())); firstProject.create(desc, null); firstProject.open(null); IFolder folder = firstProject.getFolder(FOLDER); folder.create(false, true, null); IFile textFile = folder.getFile(FILE1); textFile.create(new ByteArrayInputStream("Hello, world".getBytes(firstProject.getDefaultCharset())), false, null); IFile textFile2 = folder.getFile(FILE2); textFile2.create(new ByteArrayInputStream("Some more content".getBytes(firstProject.getDefaultCharset())), false, null); new ConnectProviderOperation(firstProject, gitDir).execute(null); IProject secondPoject = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ2); if (secondPoject.exists()) secondPoject.delete(true, null); desc = ResourcesPlugin.getWorkspace().newProjectDescription(PROJ2); desc.setLocation(new Path(new File(myRepository.getWorkTree(), PROJ2).getPath())); secondPoject.create(desc, null); secondPoject.open(null); IFolder secondfolder = secondPoject.getFolder(FOLDER); secondfolder.create(false, true, null); IFile secondtextFile = secondfolder.getFile(FILE1); secondtextFile.create(new ByteArrayInputStream("Hello, world".getBytes(firstProject.getDefaultCharset())), false, null); IFile secondtextFile2 = secondfolder.getFile(FILE2); secondtextFile2.create( new ByteArrayInputStream("Some more content".getBytes(firstProject.getDefaultCharset())), false, null); new ConnectProviderOperation(secondPoject, gitDir).execute(null); IFile[] commitables = new IFile[] { firstProject.getFile(".project"), textFile, textFile2, secondtextFile, secondtextFile2 }; ArrayList<IFile> untracked = new ArrayList<IFile>(); untracked.addAll(Arrays.asList(commitables)); // commit to stable CommitOperation op = new CommitOperation(commitables, new ArrayList<IFile>(), untracked, "Test Author <test.author@test.com>", "Test Committer <test.commiter@test.com>", "Initial commit"); op.execute(null); // now create a stable branch (from master) createStableBranch(myRepository); // and check in some stuff into master again touchAndSubmit(null); return gitDir; }
From source file:org.eclipse.egit.ui.view.repositories.GitRepositoriesViewTestBase.java
License:Open Source License
protected static File createRemoteRepository(File repositoryDir) throws Exception { Repository myRepository = org.eclipse.egit.core.Activator.getDefault().getRepositoryCache() .lookupRepository(repositoryDir); File gitDir = new File(getTestDirectory(), REPO2); Repository myRemoteRepository = lookupRepository(gitDir); myRemoteRepository.create();//ww w . jav a 2 s .c om createStableBranch(myRepository); // now we configure the push destination myRepository.getConfig().setString("remote", "push", "pushurl", "file:///" + myRemoteRepository.getDirectory().getPath()); myRepository.getConfig().setString("remote", "push", "push", "+refs/heads/*:refs/heads/*"); // TODO Bug: for some reason, this seems to be required myRepository.getConfig().setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, "0"); myRepository.getConfig().save(); // and push PushConfiguredRemoteAction pa = new PushConfiguredRemoteAction(myRepository, "push"); pa.run(null, false); TestUtil.joinJobs(JobFamilies.PUSH); try { // delete the stable branch again RefUpdate op = myRepository.updateRef("refs/heads/stable"); op.setRefLogMessage("branch deleted", //$NON-NLS-1$ false); // we set the force update in order // to avoid having this rejected // due to minor issues op.setForceUpdate(true); op.delete(); } catch (IOException ioe) { throw new InvocationTargetException(ioe); } return myRemoteRepository.getDirectory(); }
From source file:org.eclipse.mylyn.internal.gerrit.core.egit.GerritToGitMappingTest.java
License:Open Source License
private Repository createRepository(String project) { StoredConfig config = mock(StoredConfig.class); Set<String> configSubSections = new HashSet<String>(); String remoteName = "remotename"; //$NON-NLS-1$ configSubSections.add(remoteName);//from w w w . ja v a2 s . c om String remoteSection = "remote"; //$NON-NLS-1$ when(config.getSubsections(remoteSection)).thenReturn(configSubSections); when(config.getStringList(eq(remoteSection), eq(remoteName), anyString())).thenReturn(new String[0]); when(config.getStringList(eq(remoteSection), eq(remoteName), matches("url"))).thenReturn( //$NON-NLS-1$ new String[] { "git://" + GERRIT_GIT_HOST + "/" + project }); //$NON-NLS-1$//$NON-NLS-2$ Repository repo = mock(Repository.class); when(repo.getConfig()).thenReturn(config); return repo; }
From source file:org.eclipse.mylyn.internal.github.core.pr.PullRequestUtils.java
License:Open Source License
/** * Get Git repository for pull request//from w w w . jav a 2 s . c o m * * @param request * @return repository or null if none found */ public static Repository getRepository(PullRequest request) { org.eclipse.egit.github.core.Repository remoteRepo = request.getBase().getRepo(); String id = remoteRepo.getOwner().getLogin() + '/' + remoteRepo.getName() + Constants.DOT_GIT; RepositoryCache cache = Activator.getDefault().getRepositoryCache(); for (String path : Activator.getDefault().getRepositoryUtil().getConfiguredRepositories()) try { Repository repo = cache.lookupRepository(new File(path)); RemoteConfig rc = new RemoteConfig(repo.getConfig(), Constants.DEFAULT_REMOTE_NAME); for (URIish uri : rc.getURIs()) if (uri.toString().endsWith(id)) return repo; } catch (IOException e) { GitHub.logError(e); continue; } catch (URISyntaxException e) { GitHub.logError(e); continue; } return null; }
From source file:org.eclipse.mylyn.internal.github.core.pr.PullRequestUtils.java
License:Open Source License
/** * Configure pull request topic branch to use head remote * * @param repo//from w ww . ja v a2 s . c om * @param request * @throws IOException */ public static void configureTopicBranch(Repository repo, PullRequest request) throws IOException { String branch = getBranchName(request); String remote = request.getHead().getRepo().getOwner().getLogin(); StoredConfig config = repo.getConfig(); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_KEY_MERGE, getHeadBranch(request)); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_KEY_REMOTE, remote); config.save(); }
From source file:org.eclipse.mylyn.internal.github.core.pr.PullRequestUtils.java
License:Open Source License
/** * Get remote config with given name//from w w w. j a v a 2 s. c o m * * @param repo * @param name * @return remote config * @throws URISyntaxException */ public static RemoteConfig getRemoteConfig(Repository repo, String name) throws URISyntaxException { for (RemoteConfig candidate : RemoteConfig.getAllRemoteConfigs(repo.getConfig())) if (name.equals(candidate.getName())) return candidate; return null; }
From source file:org.eclipse.mylyn.internal.github.core.pr.PullRequestUtils.java
License:Open Source License
/** * Add remote for the head of a pull request if it doesn't exist * * @param repo//from w ww . j a v a 2 s .c om * @param request * @return remote configuration * @throws IOException * @throws URISyntaxException */ public static RemoteConfig addRemote(Repository repo, PullRequest request) throws IOException, URISyntaxException { RemoteConfig remote = getRemote(repo, request); if (remote != null) return remote; StoredConfig config = repo.getConfig(); org.eclipse.egit.github.core.Repository head = request.getHead().getRepo(); remote = new RemoteConfig(config, head.getOwner().getLogin()); if (head.isPrivate()) remote.addURI(new URIish(UrlUtils.createRemoteSshUrl(head))); else remote.addURI(new URIish(UrlUtils.createRemoteReadOnlyUrl(head))); remote.addFetchRefSpec(new RefSpec(HEAD_SOURCE + ":" + getDesintationRef(remote))); //$NON-NLS-1$ remote.update(config); config.save(); return remote; }
From source file:org.eclipse.mylyn.reviews.r4e.core.rfs.ReviewsRFSProxy.java
License:Open Source License
/** * @param aReviewGroupDir/*w w w. ja v a2s .co m*/ * @return * @throws ReviewsFileStorageException */ private Repository initializeRepo(File aReviewGroupDir) throws ReviewsFileStorageException { try { Repository newRepo = new FileRepository(aReviewGroupDir); newRepo.create(true); newRepo.getConfig().setString("core", null, "sharedrepository", "0666"); newRepo.getConfig().save(); return newRepo; } catch (IOException e) { throw new ReviewsFileStorageException(e); } }
From source file:org.eclipse.mylyn.reviews.r4e.ui.tests.utils.TestUtils.java
License:Open Source License
private static Repository createRepository(IProject aProject) throws CoreException, IOException { TestUtils.waitForJobs();/*from w w w. j av a2 s. c om*/ File gitDir = new File(aProject.getLocation().toOSString(), Constants.DOT_GIT); Repository repository = new FileRepository(gitDir); try { repository.create(); Config storedConfig = repository.getConfig(); storedConfig.setEnum("core", null, "autocrlf", AutoCRLF.FALSE); } catch (IllegalStateException e) { //Jusy go on } return repository; }
From source file:org.eclipse.mylyn.reviews.r4e_gerrit.internal.utils.R4EGerritServerUtility.java
License:Open Source License
/** * This method use the Gerrit from the git server in the workspace *//*w w w . java 2 s . co m*/ private void addWorkspaceGerritRepo() { RepositoryUtil repoUtil = org.eclipse.egit.core.Activator.getDefault().getRepositoryUtil(); List<String> repoPaths = repoUtil.getConfiguredRepositories(); RepositoryCache repositoryCache = org.eclipse.egit.core.Activator.getDefault().getRepositoryCache(); Repository repo = null; for (String repoPath : repoPaths) { R4EGerritPlugin.Ftracer.traceInfo("List Gerrit repository: " + repoPath); File gitDir = new File(repoPath); if (!gitDir.exists()) { R4EGerritPlugin.Ftracer.traceInfo("Gerrit repository do not exist: " + gitDir.getPath()); continue; } try { repo = repositoryCache.lookupRepository(gitDir); R4EGerritPlugin.Ftracer.traceInfo("\trepository config after lookup: " + repo.getConfig()); } catch (IOException e) { e.printStackTrace(); } if (repo != null) { Config config = new Config(repo.getConfig()); //Look to get the remotes URL Set<String> remotes = config.getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION); for (String remote : remotes) { String remoteURL = config.getString(ConfigConstants.CONFIG_REMOTE_SECTION, remote, ConfigConstants.CONFIG_KEY_URL); R4EGerritPlugin.Ftracer.traceInfo("\t\t " + remote + " -> remoteURL: " + remoteURL); //Test if this is a Gerrit server and add it to the Dialogue combo String convertedRemoteURL = getReformatGerritServer(remoteURL); if (null != convertedRemoteURL) { TaskRepository taskRepo = new TaskRepository(GerritConnector.CONNECTOR_KIND, convertedRemoteURL); taskRepo.setRepositoryLabel(convertedRemoteURL); fResultTask.put(taskRepo, taskRepo.getRepositoryUrl()); adjustTemplatemanager(taskRepo); } } } } }