List of usage examples for org.eclipse.jgit.lib Repository getConfig
@NonNull public abstract StoredConfig getConfig();
From source file:org.eclipse.egit.ui.internal.repository.RepositoryPropertyPage.java
License:Open Source License
protected Control createContents(Composite parent) { Composite displayArea = new Composite(parent, SWT.NONE); GridLayoutFactory.fillDefaults().applyTo(displayArea); GridDataFactory.fillDefaults().applyTo(displayArea); Repository repo = (Repository) getElement().getAdapter(Repository.class); if (repo == null) return displayArea; StoredConfig config = repo.getConfig(); if (config instanceof FileBasedConfig) { File configFile = ((FileBasedConfig) config).getFile(); config = new FileBasedConfig(configFile, repo.getFS()); }/*from www . j av a 2s . co m*/ editor = new ConfigurationEditorComponent(displayArea, config, true, false) { @Override protected void setErrorMessage(String message) { RepositoryPropertyPage.this.setErrorMessage(message); } }; editor.createContents(); return displayArea; }
From source file:org.eclipse.egit.ui.internal.repository.RepositoryPropertySource.java
License:Open Source License
/** * @param repository/*w w w. java 2 s .c o m*/ * the repository * @param page * the page showing the properties */ public RepositoryPropertySource(Repository repository, PropertySheetPage page) { myPage = page; effectiveConfig = repository.getConfig(); userHomeConfig = SystemReader.getInstance().openUserConfig(FS.DETECTED); if (effectiveConfig instanceof FileBasedConfig) { File configFile = ((FileBasedConfig) effectiveConfig).getFile(); repositoryConfig = new FileBasedConfig(configFile, repository.getFS()); } else { repositoryConfig = effectiveConfig; } synchronized (myPage) { // check if the actions are already there, if not, create them IActionBars bars = myPage.getSite().getActionBars(); changeModeAction = (ActionContributionItem) bars.getToolBarManager().find(CHANGEMODEACTIONID); singleValueToggleAction = (ActionContributionItem) bars.getToolBarManager().find(SINGLEVALUEACTIONID); if (changeModeAction != null) { return; } changeModeAction = new ActionContributionItem( new Action(DisplayMode.REPO.getText(), IAction.AS_DROP_DOWN_MENU) { @Override public String getId() { return CHANGEMODEACTIONID; } @Override public void run() { MenuManager mgr = new MenuManager(); ToolItem item = (ToolItem) changeModeAction.getWidget(); ToolBar control = item.getParent(); final Menu ctxMenu = mgr.createContextMenu(control); for (final DisplayMode aMode : DisplayMode.values()) { mgr.add(new Action(aMode.getText()) { @Override public void run() { changeModeAction.getAction().setText(aMode.getText()); editAction.getAction().setEnabled(aMode != DisplayMode.EFFECTIVE); myPage.refresh(); } @Override public boolean isEnabled() { return aMode != getCurrentMode(); } @Override public boolean isChecked() { return aMode == getCurrentMode(); } @Override public int getStyle() { return IAction.AS_CHECK_BOX; } }); } ctxMenu.setVisible(true); } @Override public String getToolTipText() { return UIText.RepositoryPropertySource_SelectModeTooltip; } @Override public int getStyle() { return IAction.AS_DROP_DOWN_MENU; } }); editAction = new ActionContributionItem( new Action(UIText.RepositoryPropertySource_EditConfigButton, UIIcons.EDITCONFIG) { @Override public String getId() { return EDITACTIONID; } @Override public void run() { final StoredConfig config; switch (getCurrentMode()) { case EFFECTIVE: return; case USER: config = userHomeConfig; break; case REPO: config = repositoryConfig; break; default: return; } new EditDialog(myPage.getSite().getShell(), (FileBasedConfig) config, getCurrentMode().getText()).open(); myPage.refresh(); } @Override public int getStyle() { return IAction.AS_PUSH_BUTTON; } }); singleValueToggleAction = new ActionContributionItem( new Action(UIText.RepositoryPropertySource_SingleValueButton) { @Override public String getId() { return SINGLEVALUEACTIONID; } @Override public void run() { myPage.refresh(); } @Override public int getStyle() { return IAction.AS_CHECK_BOX; } @Override public String getToolTipText() { return UIText.RepositoryPropertySource_SuppressMultipleValueTooltip; } }); bars.getToolBarManager().add(new Separator()); bars.getToolBarManager().add(changeModeAction); bars.getToolBarManager().add(singleValueToggleAction); bars.getToolBarManager().add(editAction); bars.getToolBarManager().update(false); } }
From source file:org.eclipse.egit.ui.internal.repository.tree.PropertyTester.java
License:Open Source License
/** * TODO javadoc missing/*from ww w .j a va 2 s. co m*/ */ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { if (!(receiver instanceof RepositoryTreeNode)) return false; RepositoryTreeNode node = (RepositoryTreeNode) receiver; if (property.equals("isBare")) { //$NON-NLS-1$ Repository rep = node.getRepository(); return rep.getConfig().getBoolean("core", "bare", false); //$NON-NLS-1$//$NON-NLS-2$ } if (property.equals("isRefCheckedOut")) { //$NON-NLS-1$ if (!(node.getObject() instanceof Ref)) return false; Ref ref = (Ref) node.getObject(); try { return ref.getName().equals(node.getRepository().getFullBranch()); } catch (IOException e) { return false; } } if (property.equals("isLocalBranch")) { //$NON-NLS-1$ if (!(node.getObject() instanceof Ref)) return false; Ref ref = (Ref) node.getObject(); return ref.getName().startsWith(Constants.R_HEADS); } if (property.equals("fetchExists")) { //$NON-NLS-1$ if (node instanceof RemoteNode) { String configName = ((RemoteNode) node).getObject(); RemoteConfig rconfig; try { rconfig = new RemoteConfig(node.getRepository().getConfig(), configName); } catch (URISyntaxException e2) { // TODO Exception handling rconfig = null; } boolean fetchExists = rconfig != null && !rconfig.getURIs().isEmpty(); return fetchExists; } } if (property.equals("pushExists")) { //$NON-NLS-1$ if (node instanceof RemoteNode) { String configName = ((RemoteNode) node).getObject(); RemoteConfig rconfig; try { rconfig = new RemoteConfig(node.getRepository().getConfig(), configName); } catch (URISyntaxException e2) { // TODO Exception handling rconfig = null; } boolean pushExists = rconfig != null && !rconfig.getPushURIs().isEmpty(); return pushExists; } } if (property.equals("canMerge")) { //$NON-NLS-1$ Repository rep = node.getRepository(); try { return rep.getFullBranch().startsWith(Constants.R_HEADS); } catch (IOException e) { return false; } } return false; }
From source file:org.eclipse.egit.ui.internal.synchronize.action.PushAction.java
License:Open Source License
private void runPushOperation(final int timeout) { GitSynchronizeDataSet gsds = (GitSynchronizeDataSet) getConfiguration().getProperty(SYNCHRONIZATION_DATA); for (GitSynchronizeData gsd : gsds) { String remoteName = gsd.getSrcRemoteName(); if (remoteName == null) continue; RemoteConfig rc;/*from www . jav a 2 s . co m*/ Repository repo = gsd.getRepository(); StoredConfig config = repo.getConfig(); try { rc = new RemoteConfig(config, remoteName); } catch (URISyntaxException e) { Activator.logError("Unable to create RemoteConfiguration for remote: " + remoteName, e); //$NON-NLS-1$ continue; } if (rc.getPushRefSpecs().isEmpty()) rc.addPushRefSpec(new RefSpec(HEAD + ":" + gsd.getDstMerge())); //$NON-NLS-1$ PushOperationUI push = new PushOperationUI(repo, rc, timeout, false); push.setCredentialsProvider(new EGitCredentialsProvider()); push.start(); } }
From source file:org.eclipse.egit.ui.internal.synchronize.SynchronizeFetchJob.java
License:Open Source License
@Override protected IStatus run(IProgressMonitor monitor) { monitor.beginTask(UIText.SynchronizeFetchJob_TaskName, gsdSet.size()); for (GitSynchronizeData gsd : gsdSet) { Repository repo = gsd.getRepository(); StoredConfig repoConfig = repo.getConfig(); String remoteName = gsd.getDstRemoteName(); if (remoteName == null) continue; monitor.subTask(NLS.bind(UIText.SynchronizeFetchJob_SubTaskName, remoteName)); RemoteConfig config;/* w ww . j a v a2s .com*/ try { config = new RemoteConfig(repoConfig, remoteName); } catch (URISyntaxException e) { Activator.logError(e.getMessage(), e); continue; } FetchOperationUI fetchOperationUI = new FetchOperationUI(repo, config, timeout, false); fetchOperationUI.setCredentialsProvider(new EGitCredentialsProvider()); SubMonitor subMonitor = SubMonitor.convert(monitor); try { fetchOperationUI.execute(subMonitor); gsd.updateRevs(); } catch (Exception e) { showInformationDialog(remoteName); Activator.logError(e.getMessage(), e); } monitor.worked(1); } monitor.done(); return Status.OK_STATUS; }
From source file:org.eclipse.egit.ui.internal.variables.GitTemplateVariableResolver.java
License:Open Source License
/** * Resolves the git_config variable for a project * * @param variable//from ww w . j av a 2 s .c o m * the current template variable. * @param project * the current project. */ protected static void resolveVariable(TemplateVariable variable, IProject project) { final List<String> params = variable.getVariableType().getParams(); if (params.isEmpty()) { variable.setValue(""); //$NON-NLS-1$ return; } final String gitKey = params.get(0); if (gitKey == null || gitKey.length() == 0) { variable.setValue(""); //$NON-NLS-1$ return; } // Get git's config RepositoryMapping mapping = RepositoryMapping.getMapping(project); Repository repository = null; if (mapping != null) { repository = mapping.getRepository(); } if (repository == null) { variable.setValue(""); //$NON-NLS-1$ return; } StoredConfig config = repository.getConfig(); // Get the value of the key final String[] splits = gitKey.split("\\."); //$NON-NLS-1$ String section = null; String subSection = null; String name = null; if (splits.length == 3) { section = splits[0]; subSection = splits[1]; name = splits[2]; } else if (splits.length == 2) { section = splits[0]; name = splits[1]; } else { variable.setValue(""); //$NON-NLS-1$ return; } String gitValue = config.getString(section, subSection, name); if (gitValue != null) { variable.setValue(gitValue); } }
From source file:org.eclipse.egit.ui.submodule.SubmoduleSyncTest.java
License:Open Source License
@Test public void syncSubmodule() throws Exception { deleteAllProjects();// w ww . ja v a 2 s .c o m assertProjectExistence(PROJ1, false); clearView(); Activator.getDefault().getRepositoryUtil().addConfiguredRepository(repositoryFile); shareProjects(repositoryFile); assertProjectExistence(PROJ1, true); refreshAndWait(); assertHasRepo(repositoryFile); FileRepository repo = lookupRepository(repositoryFile); SubmoduleAddCommand command = new SubmoduleAddCommand(repo); String path = "sub"; command.setPath(path); String uri = new URIish(repo.getDirectory().toURI().toString()).toString(); command.setURI(uri); Repository subRepo = command.call(); assertNotNull(subRepo); String newUri = "git://server/repo.git"; File modulesFile = new File(repo.getWorkTree(), Constants.DOT_GIT_MODULES); FileBasedConfig config = new FileBasedConfig(modulesFile, repo.getFS()); config.load(); config.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.CONFIG_KEY_URL, newUri); config.save(); assertEquals(uri, repo.getConfig().getString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.CONFIG_KEY_URL)); assertEquals(uri, subRepo.getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL)); refreshAndWait(); SWTBotTree tree = getOrOpenView().bot().tree(); tree.getAllItems()[0].expand().expandNode(UIText.RepositoriesViewLabelProvider_SubmodulesNodeText).select(); ContextMenuHelper.clickContextMenuSync(tree, myUtil.getPluginLocalizedValue(SYNC_SUBMODULE_CONTEXT_MENU_LABEL)); TestUtil.joinJobs(JobFamilies.SUBMODULE_SYNC); refreshAndWait(); assertEquals(newUri, repo.getConfig().getString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.CONFIG_KEY_URL)); assertEquals(newUri, subRepo.getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL)); }
From source file:org.eclipse.egit.ui.test.TestUtil.java
License:Open Source License
public static void configureTestCommitterAsUser(Repository repository) { StoredConfig config = repository.getConfig(); config.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_NAME, TestUtil.TESTCOMMITTER_NAME); config.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_EMAIL, TestUtil.TESTCOMMITTER_EMAIL); }
From source file:org.eclipse.egit.ui.view.repositories.GitRepositoriesViewFetchAndPushTest.java
License:Open Source License
@Test public void testPushToOrigin() throws Exception { Activator.getDefault().getRepositoryUtil().addConfiguredRepository(clonedRepositoryFile); shareProjects(clonedRepositoryFile); SWTBotTree tree = getOrOpenView().bot().tree(); tree.select(0);//w w w. j av a 2 s . co m Repository repository = lookupRepository(clonedRepositoryFile); // add the configuration for push repository.getConfig().setString("remote", "origin", "push", "refs/heads/*:refs/remotes/origin/*"); repository.getConfig().save(); myRepoViewUtil.getRemotesItem(tree, clonedRepositoryFile).expand().getNode("origin").expand().getNode(1) .select(); ContextMenuHelper.clickContextMenu(tree, myUtil.getPluginLocalizedValue("SimplePushCommand")); String destinationString = clonedRepositoryFile.getParentFile().getName() + " - " + "origin"; String dialogTitle = NLS.bind(UIText.ResultDialog_title, destinationString); // first time: expect new branch SWTBotShell confirmed = bot.shell(dialogTitle); SWTBotTable table = confirmed.bot().table(); int rowCount = table.rowCount(); boolean newBranch = false; for (int i = 0; i < rowCount; i++) { newBranch = table.getTableItem(i).getText(3).equals(UIText.PushResultTable_statusOkNewBranch); if (newBranch) break; } confirmed.close(); assertTrue("New branch expected", newBranch); // second time: expect up to date myRepoViewUtil.getRemotesItem(tree, clonedRepositoryFile).expand().getNode("origin").expand().getNode(1) .select(); ContextMenuHelper.clickContextMenu(tree, myUtil.getPluginLocalizedValue("SimplePushCommand")); confirmed = bot.shell(dialogTitle); table = confirmed.bot().table(); rowCount = table.rowCount(); boolean uptodate = false; for (int i = 0; i < rowCount; i++) { uptodate = table.getTableItem(i).getText(3).equals(UIText.PushResultTable_statusUpToDate); if (uptodate) break; } confirmed.close(); assertTrue("Up to date expected", uptodate); // touch and run again: expect new branch String objectIdBefore = repository.getRef("refs/heads/master").getLeaf().getObjectId().name(); objectIdBefore = objectIdBefore.substring(0, 7); touchAndSubmit(null); myRepoViewUtil.getRemotesItem(tree, clonedRepositoryFile).expand().getNode("origin").expand().getNode(1) .select(); ContextMenuHelper.clickContextMenu(tree, myUtil.getPluginLocalizedValue("SimplePushCommand")); confirmed = bot.shell(dialogTitle); table = confirmed.bot().table(); rowCount = table.rowCount(); newBranch = false; for (int i = 0; i < rowCount; i++) { newBranch = table.getTableItem(i).getText(3).startsWith(objectIdBefore); if (newBranch) break; } confirmed.close(); assertTrue("New branch expected", newBranch); }
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 ww. j a va 2 s. c om waitInUI(); }