List of usage examples for org.eclipse.jgit.transport RemoteConfig getFetchRefSpecs
public List<RefSpec> getFetchRefSpecs()
From source file:com.chungkwong.jgitgui.RemoteTreeItem.java
License:Open Source License
public RemoteTreeItem(RemoteConfig ref) { super(ref);/*from w w w . j a v a2s.c o m*/ for (RefSpec refSpec : ref.getFetchRefSpecs()) { getChildren().add(new RemoteSpecTreeItem(refSpec, true)); } for (RefSpec refSpec : ref.getPushRefSpecs()) { getChildren().add(new RemoteSpecTreeItem(refSpec, false)); } }
From source file:jenkins.plugins.git.GitSCMSourceDefaults.java
License:Open Source License
/** * {@inheritDoc}//from w ww. ja va2 s . co m */ @Override public void decorateCloneCommand(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener, CloneCommand cmd) throws IOException, InterruptedException, GitException { listener.getLogger().printf("Cloning with configured refspecs honoured and %s tags%n", includeTags ? "with" : "without"); RemoteConfig rc = scm.getRepositories().get(0); List<RefSpec> refspecs = rc.getFetchRefSpecs(); cmd.refspecs(refspecs); cmd.tags(includeTags); }
From source file:org.commonjava.gitwrap.BareGitRepository.java
License:Open Source License
public BareGitRepository fetch(final String remoteName) throws GitWrapException { Transport transport = null;// w w w .j av a2 s . c o m try { final RemoteConfig remoteConfig = new RemoteConfig(repository.getConfig(), remoteName); if (remoteConfig.getURIs() == null || remoteConfig.getURIs().isEmpty()) { throw new GitWrapException("Remote: %s has no associated URLs.", remoteName); } if (remoteConfig.getFetchRefSpecs() == null || remoteConfig.getFetchRefSpecs().isEmpty()) { throw new GitWrapException("Remote: %s has no associated fetch ref-specs.", remoteName); } transport = Transport.open(repository, remoteConfig); latestFetch = transport.fetch(MONITOR, null); } catch (final URISyntaxException e) { throw new GitWrapException("Cannot read configuration for remote: %s. Reason: %s", e, remoteName, e.getMessage()); } catch (final NotSupportedException e) { throw new GitWrapException("Transport not supported for remote: %s. Error was: %s", e, remoteName, e.getMessage()); } catch (final TransportException e) { throw new GitWrapException("Transport error while fetching remote: %s. Error was: %s", e, remoteName, e.getMessage()); } finally { if (transport != null) { transport.close(); } } return this; }
From source file:org.eclipse.egit.core.internal.gerrit.GerritUtil.java
License:Open Source License
/** * Configure fetching review summary notes * * @param remoteConfig//from ww w.ja v a 2 s.c o m * the remote configuration to configure this in * @return {@code true} if the {@code remoteConfig} was changed, * {@code false} otherwise. */ public static boolean configureFetchNotes(RemoteConfig remoteConfig) { String notesRef = Constants.R_NOTES + "*"; //$NON-NLS-1$ List<RefSpec> fetchRefSpecs = remoteConfig.getFetchRefSpecs(); for (RefSpec refSpec : fetchRefSpecs) { if (refSpec.matchSource(notesRef)) { return false; } } remoteConfig.addFetchRefSpec(new RefSpec(notesRef + ':' + notesRef)); return true; }
From source file:org.eclipse.egit.core.internal.gerrit.GerritUtil.java
License:Open Source License
/** * @param rc/*from w ww . ja va 2 s . c o m*/ * the remote configuration * @return {@code true} if the remote configuration is configured for * fetching from Gerrit */ public static boolean isGerritFetch(RemoteConfig rc) { for (RefSpec fetchSpec : rc.getFetchRefSpecs()) { String source = fetchSpec.getSource(); String destination = fetchSpec.getDestination(); if (source == null || destination == null) { continue; } if (source.startsWith(Constants.R_NOTES) && destination.startsWith(Constants.R_NOTES)) { return true; } } return false; }
From source file:org.eclipse.egit.ui.internal.components.RefSpecPanel.java
License:Open Source License
/** * Set information needed for assisting user with entering data and * validating user input. This method automatically enables the panel. * * @param localRepo// w ww . ja va 2 s. com * local repository where specifications will be applied. * @param remoteRefs * collection of remote refs as advertised by remote repository. * Typically they are collected by {@link FetchConnection} * implementation. * @param remoteName * optional name for remote configuration, if edited * specification list is related to this remote configuration. * Can be null. When not null, panel is filled with default * fetch/push specifications for this remote configuration. */ public void setAssistanceData(final Repository localRepo, final Collection<Ref> remoteRefs, final String remoteName) { this.localDb = localRepo; this.remoteName = remoteName; final List<RefContentProposal> remoteProposals = createContentProposals(remoteRefs, null); remoteProposalProvider.setProposals(remoteProposals); remoteRefNames = new HashSet<String>(); for (final RefContentProposal p : remoteProposals) remoteRefNames.add(p.getContent()); Ref HEAD = null; try { HEAD = localDb.getRef(Constants.HEAD); } catch (IOException e) { Activator.logError("Couldn't read HEAD from local repository", e); //$NON-NLS-1$ } final List<RefContentProposal> localProposals = createContentProposals(localDb.getAllRefs().values(), HEAD); localProposalProvider.setProposals(localProposals); localRefNames = new HashSet<String>(); for (final RefContentProposal ref : localProposals) localRefNames.add(ref.getContent()); final List<RefContentProposal> localFilteredProposals = createProposalsFilteredLocal(localProposals); final List<RefContentProposal> remoteFilteredProposals = createProposalsFilteredRemote(remoteProposals); if (pushSpecs) { creationSrcComboSupport.setProposals(localFilteredProposals); creationDstComboSupport.setProposals(remoteFilteredProposals); } else { creationSrcComboSupport.setProposals(remoteFilteredProposals); creationDstComboSupport.setProposals(localFilteredProposals); } validateCreationPanel(); if (pushSpecs) { deleteRefComboSupport.setProposals(remoteFilteredProposals); validateDeleteCreationPanel(); } try { if (remoteName == null) predefinedConfigured = Collections.emptyList(); else { final RemoteConfig rc = new RemoteConfig(localDb.getConfig(), remoteName); if (pushSpecs) predefinedConfigured = rc.getPushRefSpecs(); else predefinedConfigured = rc.getFetchRefSpecs(); for (final RefSpec spec : predefinedConfigured) addRefSpec(spec); } } catch (URISyntaxException e) { predefinedConfigured = null; ErrorDialog.openError(panel.getShell(), UIText.RefSpecPanel_errorRemoteConfigTitle, UIText.RefSpecPanel_errorRemoteConfigDescription, new Status(IStatus.ERROR, Activator.getPluginId(), 0, e.getMessage(), e)); } updateAddPredefinedButton(addConfiguredButton, predefinedConfigured); if (pushSpecs) predefinedBranches = Transport.REFSPEC_PUSH_ALL; else { final String r; if (remoteName == null) r = UIText.RefSpecPanel_refChooseRemoteName; else r = remoteName; predefinedBranches = new RefSpec("refs/heads/*:refs/remotes/" //$NON-NLS-1$ + r + "/*"); //$NON-NLS-1$ } updateAddPredefinedButton(addBranchesButton, predefinedBranches); setEnable(true); }
From source file:org.eclipse.egit.ui.internal.fetch.FetchConfiguredRemoteAction.java
License:Open Source License
/** * Runs this action/* w w w . j av a 2s. c o m*/ * <p> * * @param shell * a shell may be null; if provided, a pop up will be displayed * indicating the fetch result; if Exceptions occur, these will * be displayed * */ public void run(final Shell shell) { final RemoteConfig config; Exception prepareException = null; final Transport transport; try { config = new RemoteConfig(repository.getConfig(), remoteName); if (config.getURIs().isEmpty()) { throw new IOException( NLS.bind(UIText.FetchConfiguredRemoteAction_NoUrisDefinedMessage, remoteName)); } if (config.getFetchRefSpecs().isEmpty()) { throw new IOException( NLS.bind(UIText.FetchConfiguredRemoteAction_NoSpecsDefinedMessage, remoteName)); } transport = Transport.open(repository, config); } catch (URISyntaxException e) { prepareException = e; return; } catch (IOException e) { prepareException = e; return; } finally { if (prepareException != null) Activator.handleError(prepareException.getMessage(), prepareException, shell != null); } Job job = new Job( "Fetch from " + repository.getDirectory().getParentFile().getName() + " - " + remoteName) { //$NON-NLS-1$ //$NON-NLS-2$ @Override protected IStatus run(IProgressMonitor monitor) { final FetchResult result; Exception fetchException = null; try { result = transport.fetch(new EclipseGitProgressTransformer(monitor), config.getFetchRefSpecs()); } catch (final NotSupportedException e) { fetchException = e; return new Status(IStatus.ERROR, Activator.getPluginId(), UIText.FetchWizard_fetchNotSupported, e); } catch (final TransportException e) { if (monitor.isCanceled()) return Status.CANCEL_STATUS; fetchException = e; return new Status(IStatus.ERROR, Activator.getPluginId(), UIText.FetchWizard_transportError, e); } finally { if (fetchException != null) Activator.handleError(fetchException.getMessage(), fetchException, shell != null); } if (shell != null) { PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { public void run() { Dialog dialog = new FetchResultDialog(shell, repository, result, repository.getDirectory().getParentFile().getName() + " - " + remoteName); //$NON-NLS-1$ dialog.open(); } }); } return Status.OK_STATUS; } }; job.setUser(true); job.schedule(); }
From source file:org.eclipse.egit.ui.internal.fetch.SimpleConfigureFetchDialog.java
License:Open Source License
/** * @param shell//from ww w. j a va 2s . com * @param repository * @param config * @param showBranchInfo * should be true if this is used for upstream configuration; if * false, branch information will be hidden in the dialog */ private SimpleConfigureFetchDialog(Shell shell, Repository repository, RemoteConfig config, boolean showBranchInfo) { super(shell); setHelpAvailable(false); setShellStyle(getShellStyle() | SWT.SHELL_TRIM); this.repository = repository; this.config = config; this.showBranchInfo = showBranchInfo; // Add default fetch ref spec if this is a new remote config if (config.getFetchRefSpecs().isEmpty() && !repository.getConfig() .getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION).contains(config.getName())) { StringBuilder defaultRefSpec = new StringBuilder(); defaultRefSpec.append('+'); defaultRefSpec.append(Constants.R_HEADS); defaultRefSpec.append('*').append(':'); defaultRefSpec.append(Constants.R_REMOTES); defaultRefSpec.append(config.getName()); defaultRefSpec.append(RefSpec.WILDCARD_SUFFIX); config.addFetchRefSpec(new RefSpec(defaultRefSpec.toString())); } }
From source file:org.eclipse.egit.ui.internal.push.SimplePushRefWizard.java
License:Open Source License
@Override public boolean performFinish() { try {//from www.j a va 2s . c o m int timeout = Activator.getDefault().getPreferenceStore() .getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT); PushOperationSpecification specification = new PushOperationSpecification(); RepositorySelection remote = repoPage.getSelection(); RefSpec refSpec = new RefSpec().setSourceDestination(pushObj.name(), targetPage.getTargetRef()) .setForceUpdate(targetPage.isForceUpdate()); // Include fetchSpecs in calculation so that tracking refs are also updated RemoteConfig remoteConfig = remote.getConfig(); List<RefSpec> fetchSpecs = remoteConfig != null ? remoteConfig.getFetchRefSpecs() : null; Collection<RemoteRefUpdate> remoteRefUpdates = Transport.findRemoteRefUpdatesFor(repo, Collections.singleton(refSpec), fetchSpecs); specification.addURIRefUpdates(remote.getURI(true), remoteRefUpdates); PushOperation pop = new PushOperation(repo, specification, false, timeout); PushJob job = new PushWizard.PushJob(repo, pop, null, PushWizard.getDestinationString(remote)); job.setUser(true); job.schedule(); repoPage.saveUriInPrefs(); } catch (Exception e) { Activator.handleError(e.getMessage(), e, true); } return true; }
From source file:org.eclipse.egit.ui.internal.repository.tree.RepositoriesViewPropertyTester.java
License:Open Source License
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$ return node.getRepository().isBare(); if (property.equals("isSafe")) //$NON-NLS-1$ return node.getRepository().getRepositoryState() == RepositoryState.SAFE; if (property.equals("isRefCheckedOut")) { //$NON-NLS-1$ if (!(node.getObject() instanceof Ref)) return false; Ref ref = (Ref) node.getObject(); try {/*from w w w . jav a2 s . co m*/ if (ref.getName().startsWith(Constants.R_REFS)) { return ref.getName().equals(node.getRepository().getFullBranch()); } else if (ref.getName().equals(Constants.HEAD)) return true; else { String leafname = ref.getLeaf().getName(); if (leafname.startsWith(Constants.R_REFS) && leafname.equals(node.getRepository().getFullBranch())) return true; else ref.getLeaf().getObjectId().equals(node.getRepository().resolve(Constants.HEAD)); } } 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) { return false; } // we need to have a fetch ref spec and a fetch URI return !rconfig.getFetchRefSpecs().isEmpty() && !rconfig.getURIs().isEmpty(); } } 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) { return false; } // we need to have at least a push ref spec and any URI return !rconfig.getPushRefSpecs().isEmpty() && (!rconfig.getPushURIs().isEmpty() || !rconfig.getURIs().isEmpty()); } } if (property.equals("canMerge")) { //$NON-NLS-1$ Repository rep = node.getRepository(); if (rep.getRepositoryState() != RepositoryState.SAFE) return false; try { String branch = rep.getFullBranch(); if (branch == null) return false; // fail gracefully... return branch.startsWith(Constants.R_HEADS); } catch (IOException e) { return false; } } if (property.equals("canAbortRebase")) //$NON-NLS-1$ switch (node.getRepository().getRepositoryState()) { case REBASING_INTERACTIVE: return true; default: return false; } return false; }