use of org.eclipse.egit.core.op.ListRemoteOperation in project egit by eclipse.
the class FeatureListOperation method execute.
@Override
public void execute(IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, 2);
String uriString = FILE + repository.getRepository().getDirectory().getPath();
try {
operationResult = fetch(progress.newChild(1), timeout);
URIish uri = new URIish(uriString);
ListRemoteOperation listRemoteOperation = new ListRemoteOperation(repository.getRepository(), uri, timeout);
listRemoteOperation.run(progress.newChild(1));
Collection<Ref> remoteRefs = listRemoteOperation.getRemoteRefs();
for (Ref ref : remoteRefs) {
if (ref.getName().startsWith(REMOTE_ORIGIN_FEATURE_PREFIX + repository.getConfig().getFeaturePrefix())) {
result.add(ref);
}
}
} catch (URISyntaxException e) {
String message = NLS.bind(CoreText.FeatureListOperation_unableToParse, uriString);
throw new CoreException(error(message, e));
} catch (InvocationTargetException e) {
Throwable targetException = e.getTargetException();
throw new CoreException(error(targetException.getMessage(), targetException));
} catch (InterruptedException e) {
throw new CoreException(error(e.getMessage(), e));
}
}
use of org.eclipse.egit.core.op.ListRemoteOperation in project egit by eclipse.
the class SourceBranchPage method revalidateImpl.
private void revalidateImpl(final RepositorySelection newRepoSelection) {
if (label.isDisposed() || !isCurrentPage())
return;
final ListRemoteOperation listRemoteOp;
final URIish uri = newRepoSelection.getURI();
try {
int timeout = Activator.getDefault().getPreferenceStore().getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT);
listRemoteOp = new ListRemoteOperation(uri, timeout);
if (credentials != null)
listRemoteOp.setCredentialsProvider(new EGitCredentialsProvider(credentials.getUser(), credentials.getPassword()));
getContainer().run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
listRemoteOp.run(monitor);
}
});
} catch (InvocationTargetException e) {
Throwable why = e.getCause();
transportError(why);
if (showDetailedFailureDialog())
SourceBranchFailureDialog.show(getShell(), uri);
return;
} catch (InterruptedException e) {
transportError(UIText.SourceBranchPage_remoteListingCancelled);
return;
}
final Ref idHEAD = listRemoteOp.getRemoteRef(Constants.HEAD);
head = null;
boolean headIsMaster = false;
final String masterBranchRef = Constants.R_HEADS + Constants.MASTER;
for (final Ref r : listRemoteOp.getRemoteRefs()) {
final String n = r.getName();
if (!n.startsWith(Constants.R_HEADS)) {
continue;
}
availableRefs.add(r);
if (idHEAD == null || headIsMaster) {
continue;
}
ObjectId objectId = r.getObjectId();
if (objectId == null) {
continue;
}
if (objectId.equals(idHEAD.getObjectId())) {
headIsMaster = masterBranchRef.equals(r.getName());
if (head == null || headIsMaster) {
head = r;
}
}
}
Collections.sort(availableRefs, new Comparator<Ref>() {
@Override
public int compare(final Ref o1, final Ref o2) {
return o1.getName().compareToIgnoreCase(o2.getName());
}
});
if (idHEAD != null && head == null) {
head = idHEAD;
availableRefs.add(0, idHEAD);
}
validatedRepoSelection = newRepoSelection;
refsViewer.setInput(availableRefs);
refsViewer.setAllChecked(true);
checkPage();
checkForEmptyRepo();
}
use of org.eclipse.egit.core.op.ListRemoteOperation in project egit by eclipse.
the class LocalRepositoryTestCase method getRemoteRefs.
protected static Collection<Ref> getRemoteRefs(URIish uri) throws Exception {
int timeout = 20;
ListRemoteOperation listRemoteOp = new ListRemoteOperation(uri, timeout);
listRemoteOp.run(null);
return listRemoteOp.getRemoteRefs();
}
use of org.eclipse.egit.core.op.ListRemoteOperation in project egit by eclipse.
the class RefContentAssistProvider method getRefsForContentAssist.
/**
* @param source whether we want proposals for the source or the destination of the operation
* @param pushMode whether the operation is a push or a fetch
* @return a list of all refs for the given mode.
*/
public List<Ref> getRefsForContentAssist(boolean source, boolean pushMode) {
if (source) {
if (sourceRefs != null)
return sourceRefs;
} else if (destinationRefs != null)
return destinationRefs;
List<Ref> result = new ArrayList<>();
try {
boolean local = pushMode == source;
if (!local) {
final ListRemoteOperation lop = new ListRemoteOperation(repo, uri, Activator.getDefault().getPreferenceStore().getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT));
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask(UIText.RefSpecDialog_GettingRemoteRefsMonitorMessage, IProgressMonitor.UNKNOWN);
lop.run(monitor);
monitor.done();
}
};
if (shell != null) {
new ProgressMonitorDialog(shell).run(true, true, runnable);
} else {
container.run(true, true, runnable);
}
for (Ref ref : lop.getRemoteRefs()) if (ref.getName().startsWith(Constants.R_HEADS) || (!pushMode && ref.getName().startsWith(Constants.R_TAGS)))
result.add(ref);
} else if (pushMode)
for (Ref ref : repo.getRefDatabase().getRefs(RefDatabase.ALL).values()) {
if (ref.getName().startsWith(Constants.R_REMOTES))
continue;
result.add(ref);
}
else
for (Ref ref : repo.getRefDatabase().getRefs(Constants.R_REMOTES).values()) result.add(ref);
} catch (RuntimeException e) {
throw e;
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
Activator.handleError(cause.getMessage(), cause, true);
return result;
} catch (Exception e) {
Activator.handleError(e.getMessage(), e, true);
return result;
}
Collections.sort(result, CommonUtils.REF_ASCENDING_COMPARATOR);
if (source)
sourceRefs = result;
else
destinationRefs = result;
return result;
}
Aggregations