Author: rob.stryker(a)jboss.com
Date: 2011-10-19 04:08:26 -0400 (Wed, 19 Oct 2011)
New Revision: 35793
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.egit.core/src/org/jboss/ide/eclipse/as/egit/core/EGitUtils.java
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/behaviour/ExpressPublishMethod.java
Log:
JBIDE-9793 - If there are NO changes to be commit, then do not ask to commit / push, and
do not commit / push.
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.egit.core/src/org/jboss/ide/eclipse/as/egit/core/EGitUtils.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.egit.core/src/org/jboss/ide/eclipse/as/egit/core/EGitUtils.java 2011-10-19
06:54:34 UTC (rev 35792)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.egit.core/src/org/jboss/ide/eclipse/as/egit/core/EGitUtils.java 2011-10-19
08:08:26 UTC (rev 35793)
@@ -22,13 +22,17 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.egit.core.EclipseGitProgressTransformer;
+import org.eclipse.egit.core.IteratorService;
import org.eclipse.egit.core.op.CommitOperation;
import org.eclipse.egit.core.op.PushOperation;
import org.eclipse.egit.core.op.PushOperationSpecification;
import org.eclipse.egit.core.project.RepositoryMapping;
+import org.eclipse.egit.ui.UIText;
import org.eclipse.jgit.errors.NotSupportedException;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.IndexDiff;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
@@ -445,4 +449,27 @@
}
return status;
}
+
+ public static int countCommitableChanges(IProject project, IProgressMonitor monitor) {
+ try {
+ Repository repo = getRepository(project);
+
+ EclipseGitProgressTransformer jgitMonitor = new
EclipseGitProgressTransformer(monitor);
+ IndexDiff indexDiff = new IndexDiff(repo, Constants.HEAD,
+ IteratorService.createInitialIterator(repo));
+ indexDiff.diff(jgitMonitor, 0, 0, NLS.bind(
+ UIText.CommitActionHandler_repository, repo.getDirectory().getPath()));
+ System.out.println(indexDiff.getAdded().size());
+ System.out.println(indexDiff.getChanged().size());
+ System.out.println(indexDiff.getConflicting().size());
+ System.out.println(indexDiff.getMissing().size());
+ System.out.println(indexDiff.getModified().size());
+ System.out.println(indexDiff.getRemoved().size());
+ System.out.println(indexDiff.getUntracked().size());
+
+ return indexDiff.getModified().size();
+ } catch( IOException ioe ) {
+ }
+ return -1;
+ }
}
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/behaviour/ExpressPublishMethod.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/behaviour/ExpressPublishMethod.java 2011-10-19
06:54:34 UTC (rev 35792)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/behaviour/ExpressPublishMethod.java 2011-10-19
08:08:26 UTC (rev 35793)
@@ -4,7 +4,12 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethod;
@@ -37,16 +42,37 @@
int deltaKind, IModule[] module, IProgressMonitor monitor)
throws CoreException {
int state = behaviour.getServer().getModulePublishState(module);
- if( kind == IServer.PUBLISH_FULL || state == IServer.PUBLISH_STATE_FULL) {
- IProject p = module[module.length-1].getProject();
- monitor.beginTask("Publishing " + p.getName(), 200);
- EGitUtils.commit(p, new SubProgressMonitor(monitor, 100));
- EGitUtils.push(EGitUtils.getRepository(p), new SubProgressMonitor(monitor, 100));
- return IServer.PUBLISH_STATE_NONE;
+ IProject p = module[module.length-1].getProject();
+ int changed = EGitUtils.countCommitableChanges(p, new NullProgressMonitor() );
+ if( changed != 0 && (kind == IServer.PUBLISH_FULL || state ==
IServer.PUBLISH_STATE_FULL)) {
+ if( requestApproval(module)) {
+ monitor.beginTask("Publishing " + p.getName(), 200);
+ EGitUtils.commit(p, new SubProgressMonitor(monitor, 100));
+ EGitUtils.push(EGitUtils.getRepository(p), new SubProgressMonitor(monitor, 100));
+ return IServer.PUBLISH_STATE_NONE;
+ }
}
return IServer.PUBLISH_STATE_INCREMENTAL;
}
+ private boolean requestApproval(final IModule[] module) {
+ final boolean[] b = new boolean[1];
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ MessageBox messageBox = new MessageBox(new Shell(), SWT.ICON_QUESTION | SWT.YES |
SWT.NO);
+ String projName = module[module.length-1].getProject().getName();
+ String msg = "Do you wish to publish \"" + projName + "\" to
OpenShift by commiting and pushing it's git repository?";
+ messageBox.setMessage(msg);
+ messageBox.setText("Publish " + projName + "?");
+ int response = messageBox.open();
+ if (response == SWT.YES)
+ b[0] = true;
+ b[1] = false;
+ }
+ });
+ return b[0];
+ }
+
@Override
public IPublishCopyCallbackHandler getCallbackHandler(IPath path,
IServer server) {