Author: adietish
Date: 2012-01-30 12:20:58 -0500 (Mon, 30 Jan 2012)
New Revision: 38280
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/EGitUtils.java
trunk/openshift/tests/org.jboss.tools.openshift.egit.test/src/org/jboss/tools/openshift/egit/internal/test/EGitUtilsTest.java
Log:
[JBIDE-10479] corrected EGitUtils#isDirty to report dirty repos & added tests
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/EGitUtils.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/EGitUtils.java 2012-01-30
17:10:03 UTC (rev 38279)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/EGitUtils.java 2012-01-30
17:20:58 UTC (rev 38280)
@@ -22,6 +22,8 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.Assert;
@@ -685,6 +687,22 @@
repository.toString()));
}
}
+
+ public static boolean hasRemote(String regex, Repository repository) throws
CoreException {
+ return hasRemote(Pattern.compile(regex), repository);
+ }
+
+ public static boolean hasRemote(Pattern pattern, Repository repository) throws
CoreException {
+ for (RemoteConfig config : getAllRemoteConfigs(repository)) {
+ for(URIish uri : config.getURIs()) {
+ Matcher matcher = pattern.matcher(uri.toString());
+ if (matcher.find()) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
/**
* Returns <code>true</code> if the given repository has several configured
@@ -774,7 +792,13 @@
/**
* Returns <code>true</code> if the given repository has uncommitted
- * changes.
+ * changes. Uncommitted changes taken into account are
+ * <ul>
+ * <li>freshly added (but uncommitted resources)</li>
+ * <li>changed (but uncommitted)</li>
+ * <li>modified (but uncommitted resources)</li>
+ * <li>removed (but uncommitted resources)</li>
+ * </ul>
*
* @param repository
* the repository to check for uncommitted changes
@@ -788,7 +812,9 @@
hasChanges |= !repoStatus.getAdded().isEmpty();
hasChanges |= !repoStatus.getChanged().isEmpty();
hasChanges |= !repoStatus.getModified().isEmpty();
- hasChanges |= repoStatus.getRemoved().isEmpty();
+ hasChanges |= !repoStatus.getRemoved().isEmpty();
+ hasChanges |= !repoStatus.getConflicting().isEmpty();
+ hasChanges |= !repoStatus.getMissing().isEmpty();
return hasChanges;
}
Modified:
trunk/openshift/tests/org.jboss.tools.openshift.egit.test/src/org/jboss/tools/openshift/egit/internal/test/EGitUtilsTest.java
===================================================================
---
trunk/openshift/tests/org.jboss.tools.openshift.egit.test/src/org/jboss/tools/openshift/egit/internal/test/EGitUtilsTest.java 2012-01-30
17:10:03 UTC (rev 38279)
+++
trunk/openshift/tests/org.jboss.tools.openshift.egit.test/src/org/jboss/tools/openshift/egit/internal/test/EGitUtilsTest.java 2012-01-30
17:20:58 UTC (rev 38280)
@@ -3,6 +3,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
import java.io.File;
import java.io.IOException;
@@ -17,6 +18,7 @@
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
+import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.openshift.egit.core.EGitUtils;
import org.jboss.tools.openshift.egit.internal.test.util.TestProject;
import org.jboss.tools.openshift.egit.internal.test.util.TestRepository;
@@ -190,4 +192,43 @@
assertTrue(subsections.contains(remoteName));
assertEquals(gitUri, config.getString(ConfigConstants.CONFIG_REMOTE_SECTION,
remoteName, ConfigConstants.CONFIG_KEY_URL));
}
+
+ @Test
+ public void addedButNotCommittedIsDirty() throws IOException {
+ assertFalse(EGitUtils.isDirty(testRepository.getRepository()));
+ File file = testRepository.createFile("a.txt", "protoculture");
+ testRepository.add(file);
+ assertTrue(EGitUtils.isDirty(testRepository.getRepository()));
+ }
+
+ @Test
+ public void changedButNotCommittedIsDirty() throws Exception {
+ assertFalse(EGitUtils.isDirty(testRepository.getRepository()));
+ File file = testRepository.createFile("a.txt", "ethnica");
+ testRepository.addAndCommit(file, "commit-by-junit-tests");
+ assertFalse(EGitUtils.isDirty(testRepository.getRepository()));
+ FileUtil.writeFileDefault(file, "depeche-mode");
+ testRepository.add(file);
+ assertTrue(EGitUtils.isDirty(testRepository.getRepository()));
+ }
+
+ @Test
+ public void modifiedButNotCommittedIsDirty() throws Exception {
+ assertFalse(EGitUtils.isDirty(testRepository.getRepository()));
+ File file = testRepository.createFile("a.txt", "protonica");
+ testRepository.addAndCommit(file, "commit-by-junit-tests");
+ FileUtil.writeFileDefault(file, "atrix");
+ assertTrue(EGitUtils.isDirty(testRepository.getRepository()));
+ }
+
+ @Test
+ public void removedButNotCommittedIsDirty() throws Exception {
+ assertFalse(EGitUtils.isDirty(testRepository.getRepository()));
+ File file = testRepository.createFile("a.txt", "protonica");
+ testRepository.addAndCommit(file, "commit-by-junit-tests");
+ assertFalse(EGitUtils.isDirty(testRepository.getRepository()));
+ file.delete();
+ assertTrue(EGitUtils.isDirty(testRepository.getRepository()));
+ }
+
}
Show replies by date