List of usage examples for org.eclipse.jgit.transport RemoteConfig getPushRefSpecs
public List<RefSpec> getPushRefSpecs()
From source file:com.chungkwong.jgitgui.RemoteTreeItem.java
License:Open Source License
public RemoteTreeItem(RemoteConfig ref) { super(ref);// w w w .java 2 s . co 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:com.google.gerrit.server.git.PushReplication.java
License:Apache License
private List<ReplicationConfig> allConfigs(final SitePaths site) throws ConfigInvalidException, IOException { final FileBasedConfig cfg = new FileBasedConfig(site.replication_config, FS.DETECTED); if (!cfg.getFile().exists()) { log.warn("No " + cfg.getFile() + "; not replicating"); return Collections.emptyList(); }//from w w w. j a v a 2 s .c o m if (cfg.getFile().length() == 0) { log.info("Empty " + cfg.getFile() + "; not replicating"); return Collections.emptyList(); } try { cfg.load(); } catch (ConfigInvalidException e) { throw new ConfigInvalidException("Config file " + cfg.getFile() + " is invalid: " + e.getMessage(), e); } catch (IOException e) { throw new IOException("Cannot read " + cfg.getFile() + ": " + e.getMessage(), e); } final List<ReplicationConfig> r = new ArrayList<ReplicationConfig>(); for (final RemoteConfig c : allRemotes(cfg)) { if (c.getURIs().isEmpty()) { continue; } for (final URIish u : c.getURIs()) { if (u.getPath() == null || !u.getPath().contains("${name}")) { throw new ConfigInvalidException("remote." + c.getName() + ".url" + " \"" + u + "\" lacks ${name} placeholder in " + cfg.getFile()); } } // In case if refspec destination for push is not set then we assume it is // equal to source for (RefSpec ref : c.getPushRefSpecs()) { if (ref.getDestination() == null) { ref.setDestination(ref.getSource()); } } if (c.getPushRefSpecs().isEmpty()) { RefSpec spec = new RefSpec(); spec = spec.setSourceDestination("refs/*", "refs/*"); spec = spec.setForceUpdate(true); c.addPushRefSpec(spec); } r.add(new ReplicationConfig(injector, workQueue, c, cfg, database, replicationUserFactory)); } return Collections.unmodifiableList(r); }
From source file:com.googlesource.gerrit.plugins.github.replication.GitHubDestinations.java
License:Apache License
private List<Destination> getDestinations(File cfgPath) throws ConfigInvalidException, IOException { FileBasedConfig cfg = new FileBasedConfig(cfgPath, FS.DETECTED); if (!cfg.getFile().exists() || cfg.getFile().length() == 0) { return Collections.emptyList(); }/* w w w. j ava 2 s . co m*/ try { cfg.load(); } catch (ConfigInvalidException e) { throw new ConfigInvalidException( String.format("Config file %s is invalid: %s", cfg.getFile(), e.getMessage()), e); } catch (IOException e) { throw new IOException(String.format("Cannot read %s: %s", cfg.getFile(), e.getMessage()), e); } ImmutableList.Builder<Destination> dest = ImmutableList.builder(); for (RemoteConfig c : allRemotes(cfg)) { if (c.getURIs().isEmpty()) { continue; } for (URIish u : c.getURIs()) { if (u.getPath() == null || !u.getPath().contains("${name}")) { throw new ConfigInvalidException(String.format( "remote.%s.url \"%s\" lacks ${name} placeholder in %s", c.getName(), u, cfg.getFile())); } } // If destination for push is not set assume equal to source. for (RefSpec ref : c.getPushRefSpecs()) { if (ref.getDestination() == null) { ref.setDestination(ref.getSource()); } } if (c.getPushRefSpecs().isEmpty()) { c.addPushRefSpec(new RefSpec().setSourceDestination("refs/*", "refs/*").setForceUpdate(true)); } dest.add(new Destination(injector, c, cfg, database, replicationUserFactory, pluginUser, gitRepositoryManager, groupBackend)); } return dest.build(); }
From source file:com.googlesource.gerrit.plugins.replication.ReplicationFileBasedConfig.java
License:Apache License
private List<Destination> allDestinations() throws ConfigInvalidException, IOException { if (!config.getFile().exists()) { log.warn("Config file " + config.getFile() + " does not exist; not replicating"); return Collections.emptyList(); }/*from ww w. j av a2 s .c o m*/ if (config.getFile().length() == 0) { log.info("Config file " + config.getFile() + " is empty; not replicating"); return Collections.emptyList(); } try { config.load(); } catch (ConfigInvalidException e) { throw new ConfigInvalidException( String.format("Config file %s is invalid: %s", config.getFile(), e.getMessage()), e); } catch (IOException e) { throw new IOException(String.format("Cannot read %s: %s", config.getFile(), e.getMessage()), e); } replicateAllOnPluginStart = config.getBoolean("gerrit", "replicateOnStartup", true); defaultForceUpdate = config.getBoolean("gerrit", "defaultForceUpdate", false); ImmutableList.Builder<Destination> dest = ImmutableList.builder(); for (RemoteConfig c : allRemotes(config)) { if (c.getURIs().isEmpty()) { continue; } // If destination for push is not set assume equal to source. for (RefSpec ref : c.getPushRefSpecs()) { if (ref.getDestination() == null) { ref.setDestination(ref.getSource()); } } if (c.getPushRefSpecs().isEmpty()) { c.addPushRefSpec( new RefSpec().setSourceDestination("refs/*", "refs/*").setForceUpdate(defaultForceUpdate)); } Destination destination = new Destination(injector, new DestinationConfiguration(c, config), replicationUserFactory, pluginUser, gitRepositoryManager, groupBackend, stateLog, groupIncludeCache); if (!destination.isSingleProjectMatch()) { for (URIish u : c.getURIs()) { if (u.getPath() == null || !u.getPath().contains("${name}")) { throw new ConfigInvalidException( String.format("remote.%s.url \"%s\" lacks ${name} placeholder in %s", c.getName(), u, config.getFile())); } } } dest.add(destination); } return dest.build(); }
From source file:edu.tum.cs.mylyn.provisioning.git.GitProvisioningUtil.java
License:Open Source License
public static URIish getGerritUri(RepositoryWrapper repository) { for (RemoteConfig config : repository.getRemoteConfigs()) { for (RefSpec ref : config.getPushRefSpecs()) { if (ref.getDestination().startsWith(GERRIT_PUSH_REF)) { return config.getURIs().get(0); }// w w w . j a va2 s . c om } } return null; }
From source file:org.commonjava.gitwrap.BareGitRepository.java
License:Open Source License
public BareGitRepository push(final String name) throws GitWrapException { try {//from w ww.j a va 2s. c o m final StoredConfig config = repository.getConfig(); final RemoteConfig remote = new RemoteConfig(config, name); final List<URIish> pushURIs = remote.getPushURIs(); final List<RefSpec> pushRefSpecs = remote.getPushRefSpecs(); final Collection<RemoteRefUpdate> remoteRefUpdates = Transport.findRemoteRefUpdatesFor(repository, pushRefSpecs, null); for (final URIish uri : pushURIs) { final Collection<RemoteRefUpdate> updates = new ArrayList<RemoteRefUpdate>(); for (final RemoteRefUpdate rru : remoteRefUpdates) { updates.add(new RemoteRefUpdate(rru, null)); } Transport transport = null; try { transport = Transport.open(repository, uri); transport.applyConfig(remote); final PushResult result = transport.push(MONITOR, updates); if (result.getMessages().length() > 0 && LOGGER.isDebugEnabled()) { LOGGER.debug(result.getMessages()); } } finally { if (transport != null) { transport.close(); } } } } catch (final NotSupportedException e) { throw new GitWrapException( "Cannot push to repository: %s. Transport is not supported.\nNested error: %s", e, name, e.getMessage()); } catch (final TransportException e) { throw new GitWrapException("Transport failed for repository push: %s.\nNested error: %s", e, name, e.getMessage()); } catch (final URISyntaxException e) { throw new GitWrapException("Invalid URI for repository push: %s.\nNested error: %s", e, name, e.getMessage()); } catch (final IOException e) { throw new GitWrapException("Transport failed for repository push: %s.\nNested error: %s", e, name, e.getMessage()); } return this; }
From source file:org.commonjava.gitwrap.BareGitRepository.java
License:Open Source License
public BareGitRepository setPushTarget(final String name, final String uri, final boolean heads, final boolean tags) throws GitWrapException { try {//from ww w . ja v a 2s .c o m final RemoteConfig remote = new RemoteConfig(repository.getConfig(), name); final URIish uriish = new URIish(uri); final List<URIish> uris = remote.getURIs(); if (uris == null || !uris.contains(uriish)) { remote.addURI(uriish); } final List<URIish> pushURIs = remote.getPushURIs(); if (pushURIs == null || !pushURIs.contains(uriish)) { remote.addPushURI(uriish); } final List<RefSpec> pushRefSpecs = remote.getPushRefSpecs(); if (heads) { final RefSpec headSpec = new RefSpec("+" + Constants.R_HEADS + "*:" + Constants.R_HEADS + "*"); if (pushRefSpecs == null || !pushRefSpecs.contains(headSpec)) { remote.addPushRefSpec(headSpec); } } if (tags) { final RefSpec tagSpec = new RefSpec("+" + Constants.R_TAGS + "*:" + Constants.R_TAGS + "*"); if (pushRefSpecs == null || !pushRefSpecs.contains(tagSpec)) { remote.addPushRefSpec(tagSpec); } } remote.update(repository.getConfig()); repository.getConfig().save(); } catch (final URISyntaxException e) { throw new GitWrapException("Invalid URI-ish: %s. Nested error: %s", e, uri, e.getMessage()); } catch (final IOException e) { throw new GitWrapException("Failed to write Git config: %s", e, e.getMessage()); } return this; }
From source file:org.eclipse.egit.core.internal.gerrit.GerritUtil.java
License:Open Source License
/** * Configure the gerrit push refspec HEAD:refs/for/<gerritBranch> * * @param remoteConfig/*from w ww . ja v a 2 s .c o m*/ * the remote configuration to configure this in * @param gerritBranch * the branch to push to review for */ public static void configurePushRefSpec(RemoteConfig remoteConfig, String gerritBranch) { List<RefSpec> pushRefSpecs = new ArrayList<RefSpec>(remoteConfig.getPushRefSpecs()); for (RefSpec refSpec : pushRefSpecs) { remoteConfig.removePushRefSpec(refSpec); } remoteConfig.addPushRefSpec(new RefSpec("HEAD:" + GerritUtil.REFS_FOR + gerritBranch)); //$NON-NLS-1$ }
From source file:org.eclipse.egit.core.internal.gerrit.GerritUtil.java
License:Open Source License
/** * @param rc/*from w ww .j ava 2s . co m*/ * the remote configuration * @return {@code true} if the remote configuration is configured for * pushing to Gerrit */ public static boolean isGerritPush(RemoteConfig rc) { for (RefSpec pushSpec : rc.getPushRefSpecs()) { String destination = pushSpec.getDestination(); if (destination == null) { continue; } if (destination.startsWith(GerritUtil.REFS_FOR) || destination.startsWith(GerritUtil.REFS_PUBLISH) || destination.startsWith(GerritUtil.REFS_DRAFTS)) { 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//www . ja va2 s. c o m * 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); }