List of usage examples for org.eclipse.jgit.lib Repository getFS
public FS getFS()
From source file:org.eclipse.egit.ui.internal.repository.RepositoryPropertySource.java
License:Open Source License
/** * @param repository/*from w ww .jav a 2 s .c om*/ * 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.ptp.internal.rdt.sync.git.core.GitRepo.java
License:Open Source License
/** * Upload the file filter from the given JGit repository * * @param localJGitRepo//from www .ja v a 2 s .c o m * @param monitor * * @throws MissingConnectionException * on missing connection * @throws RemoteSyncException * on problems executing remote commands */ public void uploadFilter(JGitRepo localJGitRepo, IProgressMonitor monitor) throws MissingConnectionException, RemoteSyncException { final RecursiveSubMonitor subMon = RecursiveSubMonitor.convert(monitor, 10); IRemoteConnection conn = remoteLoc.getConnection(); Repository repository = localJGitRepo.getRepository(); try { //copy info/exclude to remote File exclude = repository.getFS().resolve(repository.getDirectory(), Constants.INFO_EXCLUDE); IFileStore local = EFS.getLocalFileSystem().getStore(new Path(exclude.getAbsolutePath())); String remoteExclude = remoteLoc.getDirectory() + "/" + GitSyncService.gitDir + "/" //$NON-NLS-1$//$NON-NLS-2$ + Constants.INFO_EXCLUDE; IFileStore remote = conn.getFileManager().getResource(remoteExclude); subMon.subTask(Messages.GitRepo_6); local.copy(remote, EFS.OVERWRITE, subMon.newChild(3)); //remove ignored files from index if (remoteGitVersion >= 1080102) { final String command = gitCommand() + " ls-files -X " + GitSyncService.gitDir + "/" //$NON-NLS-1$//$NON-NLS-2$ + Constants.INFO_EXCLUDE + " -i | " + //$NON-NLS-1$ gitCommand() + " update-index --force-remove --stdin ; " + //$NON-NLS-1$ gitCommand() + " commit --allow-empty -m \"" + GitSyncService.commitMessage + "\""; //$NON-NLS-1$ //$NON-NLS-2$ subMon.subTask(Messages.GitRepo_7); CommandResults commandResults = this.executeRemoteCommand(command, subMon.newChild(7)); if (commandResults.getExitCode() != 0) { throw new RemoteSyncException(Messages.GitRepo_8 + commandResults.getStderr()); } } else { final String command = gitCommand() + " rev-parse HEAD"; //$NON-NLS-1$ subMon.subTask(Messages.GitRepo_9); CommandResults commandResults = this.executeRemoteCommand(command, subMon.newChild(2)); ObjectId objectId = null; if (commandResults.getExitCode() == 0) objectId = repository.resolve(commandResults.getStdout().trim()); RevTree ref = null; try { if (objectId != null) ref = new RevWalk(repository).parseTree(objectId); } catch (Exception e) { //ignore. Can happen if the local repo doesn't yet have the remote commit } if (ref != null) { Set<String> filesToRemove = localJGitRepo.getFilter().getIgnoredFiles(ref); subMon.subTask(Messages.GitRepo_7); deleteRemoteFiles(filesToRemove, subMon.newChild(8)); } } } catch (RemoteConnectionException e) { throw new RemoteSyncException(e); } catch (CoreException e) { throw new RemoteSyncException(e); } catch (IOException e) { throw new RemoteSyncException(e); } catch (InterruptedException e) { throw new RemoteSyncException(e); } catch (RemoteExecutionException e) { throw new RemoteSyncException(e); } }
From source file:org.eclipse.ptp.internal.rdt.sync.git.core.GitSyncFileFilter.java
License:Open Source License
@Override public void saveFilter() throws IOException { Repository repo = jgitRepo.getRepository(); File exclude = repo.getFS().resolve(repo.getDirectory(), Constants.INFO_EXCLUDE); exclude.getParentFile().mkdirs();// ww w. j av a 2s . com FileOutputStream file = new FileOutputStream(exclude); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(file, Constants.CHARSET)); try { for (AbstractIgnoreRule rule : rules) { out.write(rule.toString()); out.newLine(); } } finally { out.close(); } final RmCommand rmCommand = new RmCommand(repo); rmCommand.setCached(true); for (String fileName : getIgnoredFiles(null)) { rmCommand.addFilepattern(fileName); } try { rmCommand.call(); } catch (NoFilepatternException e) { new IOException(e); // TODO: a bit ugly to wrap it into IOExcpetion } catch (GitAPIException e) { new IOException(e); } }
From source file:org.eclipse.ptp.internal.rdt.sync.git.core.GitSyncFileFilter.java
License:Open Source License
/** * Load filtering rules from the file system * @throws IOException/*from w w w .j a va2s . com*/ * on problems reading from the file system */ public void loadFilter() throws IOException { Repository repo = jgitRepo.getRepository(); File exclude = repo.getFS().resolve(repo.getDirectory(), Constants.INFO_EXCLUDE); if (exclude.exists()) { FileInputStream in = new FileInputStream(exclude); try { IgnoreNode node = new IgnoreNode(); node.parse(in); for (org.eclipse.jgit.ignore.IgnoreRule rule : node.getRules()) { rules.add(new GitIgnoreRule(rule)); } } finally { in.close(); } } else { initialize(SyncManager.getDefaultFileFilter()); } }