ProgressMonitor gitMonitor = new EclipseGitProgressTransformer(monitor);
Repository db = null;
try {
db = getRepository();
Git git = new Git(db);
FetchCommand fc = git.fetch();
fc.setProgressMonitor(gitMonitor);
RemoteConfig remoteConfig = new RemoteConfig(git.getRepository().getConfig(), remote);
credentials.setUri(remoteConfig.getURIs().get(0));
if (this.cookie != null) {
fc.setTransportConfigCallback(new TransportConfigCallback() {
@Override
public void configure(Transport t) {
if (t instanceof TransportHttp && cookie != null) {
HashMap<String, String> map = new HashMap<String, String>();
map.put(GitConstants.KEY_COOKIE, cookie.getName() + "=" + cookie.getValue());
((TransportHttp) t).setAdditionalHeaders(map);
}
}
});
}
fc.setCredentialsProvider(credentials);
fc.setRemote(remote);
if (branch != null) {
// refs/heads/{branch}:refs/remotes/{remote}/{branch}
String remoteBranch = branch;
if (branch.startsWith("for/")) {
remoteBranch = branch.substring(4);
}
RefSpec spec = new RefSpec(Constants.R_HEADS + remoteBranch + ":" + Constants.R_REMOTES + remote + "/" + branch); //$NON-NLS-1$ //$NON-NLS-2$
spec = spec.setForceUpdate(force);
fc.setRefSpecs(spec);
}
FetchResult fetchResult = fc.call();
if (monitor.isCanceled()) {
return new Status(IStatus.CANCEL, GitActivator.PI_GIT, "Cancelled");
}
GitJobUtils.packRefs(db, gitMonitor);
if (monitor.isCanceled()) {