use of org.eclipse.jgit.transport.RemoteConfig in project egit by eclipse.
the class PushWizard method createPushOperation.
private PushOperation createPushOperation(boolean calledFromRepoPage) {
try {
final PushOperationSpecification spec;
final RemoteConfig config = repoPage.getSelection().getConfig();
if (calledFromRepoPage) {
// obtain the push ref specs from the configuration
// use our own list here, as the config returns a non-modifiable
// list
final Collection<RefSpec> pushSpecs = new ArrayList<>();
pushSpecs.addAll(config.getPushRefSpecs());
final Collection<RemoteRefUpdate> updates = Transport.findRemoteRefUpdatesFor(localDb, pushSpecs, config.getFetchRefSpecs());
spec = new PushOperationSpecification();
for (final URIish uri : repoPage.getSelection().getPushURIs()) spec.addURIRefUpdates(uri, ConfirmationPage.copyUpdates(updates));
} else if (confirmPage.isConfirmed()) {
final PushOperationResult confirmedResult = confirmPage.getConfirmedResult();
spec = confirmedResult.deriveSpecification(confirmPage.isRequireUnchangedSelected());
} else {
final Collection<RefSpec> fetchSpecs;
if (config != null)
fetchSpecs = config.getFetchRefSpecs();
else
fetchSpecs = null;
final Collection<RemoteRefUpdate> updates = Transport.findRemoteRefUpdatesFor(localDb, refSpecPage.getRefSpecs(), fetchSpecs);
if (updates.isEmpty()) {
ErrorDialog.openError(getShell(), UIText.PushWizard_missingRefsTitle, null, new Status(IStatus.ERROR, Activator.getPluginId(), UIText.PushWizard_missingRefsMessage));
return null;
}
spec = new PushOperationSpecification();
for (final URIish uri : repoPage.getSelection().getPushURIs()) spec.addURIRefUpdates(uri, ConfirmationPage.copyUpdates(updates));
}
int timeout = Activator.getDefault().getPreferenceStore().getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT);
return new PushOperation(localDb, spec, false, timeout);
} catch (final IOException e) {
ErrorDialog.openError(getShell(), UIText.PushWizard_cantPrepareUpdatesTitle, UIText.PushWizard_cantPrepareUpdatesMessage, new Status(IStatus.ERROR, Activator.getPluginId(), e.getMessage(), e));
return null;
}
}
use of org.eclipse.jgit.transport.RemoteConfig in project egit by eclipse.
the class SimpleConfigurePushDialog method getConfiguredRemote.
/**
* @param repository
* @return the configured remote for the current branch if any, or null
*/
public static RemoteConfig getConfiguredRemote(Repository repository) {
String branch;
try {
branch = repository.getBranch();
} catch (IOException e) {
Activator.handleError(e.getMessage(), e, true);
return null;
}
if (branch == null)
return null;
String remoteName = null;
if (!ObjectId.isId(branch))
remoteName = repository.getConfig().getString(ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_REMOTE_SECTION);
// check if we find the configured and default Remotes
List<RemoteConfig> allRemotes;
try {
allRemotes = RemoteConfig.getAllRemoteConfigs(repository.getConfig());
} catch (URISyntaxException e) {
allRemotes = new ArrayList<>();
}
RemoteConfig configuredConfig = null;
RemoteConfig defaultConfig = null;
for (RemoteConfig config : allRemotes) {
if (remoteName != null && config.getName().equals(remoteName))
configuredConfig = config;
if (config.getName().equals(Constants.DEFAULT_REMOTE_NAME))
defaultConfig = config;
}
if (configuredConfig != null)
return configuredConfig;
if (defaultConfig != null)
if (!defaultConfig.getPushRefSpecs().isEmpty())
return defaultConfig;
return null;
}
use of org.eclipse.jgit.transport.RemoteConfig in project egit by eclipse.
the class PushBranchWizard method configureNewRemote.
private void configureNewRemote(URIish uri) throws URISyntaxException, IOException {
StoredConfig config = repository.getConfig();
String remoteName = getRemoteName();
RemoteConfig remoteConfig = new RemoteConfig(config, remoteName);
remoteConfig.addURI(uri);
RefSpec defaultFetchSpec = new RefSpec().setForceUpdate(true).setSourceDestination(// $NON-NLS-1$
Constants.R_HEADS + "*", // $NON-NLS-1$
Constants.R_REMOTES + remoteName + "/*");
remoteConfig.addFetchRefSpec(defaultFetchSpec);
remoteConfig.update(config);
config.save();
}
use of org.eclipse.jgit.transport.RemoteConfig in project Android-Password-Store by zeapo.
the class PasswordRepository method addRemote.
// TODO add multiple remotes support for pull/push
public static void addRemote(String name, String url, Boolean replace) {
StoredConfig storedConfig = repository.getConfig();
Set<String> remotes = storedConfig.getSubsections("remote");
if (!remotes.contains(name)) {
try {
URIish uri = new URIish(url);
RefSpec refSpec = new RefSpec("+refs/head/*:refs/remotes/" + name + "/*");
RemoteConfig remoteConfig = new RemoteConfig(storedConfig, name);
remoteConfig.addFetchRefSpec(refSpec);
remoteConfig.addPushRefSpec(refSpec);
remoteConfig.addURI(uri);
remoteConfig.addPushURI(uri);
remoteConfig.update(storedConfig);
storedConfig.save();
} catch (Exception e) {
e.printStackTrace();
}
} else if (replace) {
try {
URIish uri = new URIish(url);
RemoteConfig remoteConfig = new RemoteConfig(storedConfig, name);
// remove the first and eventually the only uri
if (remoteConfig.getURIs().size() > 0) {
remoteConfig.removeURI(remoteConfig.getURIs().get(0));
}
if (remoteConfig.getPushURIs().size() > 0) {
remoteConfig.removePushURI(remoteConfig.getPushURIs().get(0));
}
remoteConfig.addURI(uri);
remoteConfig.addPushURI(uri);
remoteConfig.update(storedConfig);
storedConfig.save();
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of org.eclipse.jgit.transport.RemoteConfig in project jbosstools-openshift by jbosstools.
the class EGitUtils method getRemoteURIs.
/**
* Returns the URIish's for the remote on the given project.
*
* @param remoteName
* @param project
* @return
* @throws CoreException
*/
public static List<URIish> getRemoteURIs(String remoteName, IProject project) throws CoreException {
List<URIish> uris = Collections.emptyList();
RemoteConfig remoteConfig = getRemoteByName(remoteName, getRepository(project));
if (remoteConfig != null) {
uris = remoteConfig.getURIs();
}
return uris;
}
Aggregations