Skip to content

Commit

Permalink
[JBIDE-15059] fetching after push so that isAhead-state gets updated
Browse files Browse the repository at this point in the history
  • Loading branch information
adietish committed Jun 29, 2013
1 parent 4650174 commit 0ad497b
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.jboss.tools.openshift.express.internal.core.behaviour;

import java.io.File;
import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
Expand All @@ -29,6 +30,7 @@
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
Expand Down Expand Up @@ -256,6 +258,7 @@ protected PushOperationResult push(IProject project, IServer server, IProgressMo
PushOperationResult result = EGitUtils.push(
remoteName, repository, new SubProgressMonitor(monitor, 100),
ConsoleUtils.getConsoleOutputStream(server));
safeFetch(remoteName, repository, monitor);
monitor.done();
return result;
} catch (CoreException ce) {
Expand Down Expand Up @@ -305,6 +308,33 @@ remoteName, repository, new SubProgressMonitor(monitor, 100),
}
}

/**
* Workaround needed to get correct "isAhead" state for the repository we
* were pushing to. Otherwise git branch state will be erroneous compared to
* the remote, behave as if we did not push yet.
*
* @param remoteName
* the remote to push to
* @param repository
* the repository to push
* @param monitor
* the montior to report progress to
*
* @see <a href="https://issues.jboss.org/browse/JBIDE-15059">https://issues.jboss.org/browse/JBIDE-15059</a>
*/
private void safeFetch(String remoteName, Repository repository, IProgressMonitor monitor) {
try {
RemoteConfig remoteConfig = EGitUtils.getRemoteConfig(remoteName, EGitUtils.getAllRemoteConfigs(repository));
EGitUtils.fetch(remoteConfig, repository, monitor);
} catch (CoreException e) {
OpenShiftUIActivator.log(
NLS.bind("Could not get remote configs for repository {0}", repository.getDirectory()), e);
} catch (InvocationTargetException e) {
OpenShiftUIActivator.log(
NLS.bind("Could not fetch remote {0} for repository {1}", remoteName, repository.getDirectory()), e);
}
}

protected String getModuleProjectName(IModule[] module) {
return module[module.length - 1].getProject().getName();
}
Expand Down

0 comments on commit 0ad497b

Please sign in to comment.