Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2016-07-30 14:45:14 +0000
committerMatthias Sohn2016-08-15 09:35:28 +0000
commit5b0551308d74595d1be4c99596d3c4851dc78180 (patch)
tree415d48e1bccca47d37efe74966cfb78f8ad5e8ab /org.eclipse.egit.ui.test/src
parent3d4673aec08ee3a5653c8194180ec722542522aa (diff)
downloadegit-5b0551308d74595d1be4c99596d3c4851dc78180.tar.gz
egit-5b0551308d74595d1be4c99596d3c4851dc78180.tar.xz
egit-5b0551308d74595d1be4c99596d3c4851dc78180.zip
Auto-stage selected files on "Commit..." when staging view is used
* New preference UiPreferences.AUTO_STAGE_ON_COMMIT for auto-staging when the staging view is used. Default is true. * Change some private operations from CommitUI to public static utility operations, so they can be re-used. * Add auto-staging functionality in CommitActionHandler Auto-staging honors the UiPreferences.COMMIT_DIALOG_INCLUDE_UNTRACKED setting. Staging occurs in a background job. Bug: 497574 Change-Id: I5273400b602e1e4681fe0be6ed34b8fefef795a5 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui.test/src')
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/StagingUtil.java43
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CommitActionStagingViewTest.java71
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/StageUnstageActionTest.java33
3 files changed, 121 insertions, 26 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/StagingUtil.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/StagingUtil.java
new file mode 100644
index 0000000000..7581de2aa3
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/StagingUtil.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Thomas Wolf <thomas.wolf@paranor.ch>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.egit.ui.test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.egit.ui.internal.resources.IResourceState;
+import org.eclipse.egit.ui.internal.resources.ResourceStateFactory;
+
+public final class StagingUtil {
+
+ private StagingUtil() {
+ // Utility class shall not be instantiated
+ }
+
+ public static void assertStaging(String projectName, String filePath,
+ boolean expected) {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(projectName);
+ IResource resource = project.findMember(filePath);
+ assertNotNull(filePath + " should exist", resource);
+ IResourceState state = ResourceStateFactory.getInstance().get(resource);
+ if (expected) {
+ assertTrue(projectName + '/' + filePath + " should be staged",
+ state.isStaged());
+ } else {
+ assertFalse(projectName + '/' + filePath + " should be unstaged",
+ state.isStaged());
+ }
+ }
+
+}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CommitActionStagingViewTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CommitActionStagingViewTest.java
index dcab5bd543..7b9ad251d3 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CommitActionStagingViewTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CommitActionStagingViewTest.java
@@ -7,19 +7,24 @@
*******************************************************************************/
package org.eclipse.egit.ui.test.team.actions;
+import static org.eclipse.egit.ui.JobFamilies.ADD_TO_INDEX;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
+import java.util.concurrent.TimeUnit;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.egit.core.JobFamilies;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIPreferences;
import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
import org.eclipse.egit.ui.internal.staging.StagingView;
import org.eclipse.egit.ui.test.ContextMenuHelper;
+import org.eclipse.egit.ui.test.JobJoiner;
+import org.eclipse.egit.ui.test.StagingUtil;
import org.eclipse.egit.ui.test.TestUtil;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
@@ -40,6 +45,8 @@ public class CommitActionStagingViewTest extends LocalRepositoryTestCase {
private boolean initialUseStagingView;
+ private boolean initialAutoStage;
+
@Before
public void setup() throws Exception {
TestUtil.hideView(StagingView.VIEW_ID);
@@ -47,6 +54,10 @@ public class CommitActionStagingViewTest extends LocalRepositoryTestCase {
.getBoolean(UIPreferences.ALWAYS_USE_STAGING_VIEW);
Activator.getDefault().getPreferenceStore()
.setValue(UIPreferences.ALWAYS_USE_STAGING_VIEW, true);
+ initialAutoStage = Activator.getDefault().getPreferenceStore()
+ .getBoolean(UIPreferences.AUTO_STAGE_ON_COMMIT);
+ Activator.getDefault().getPreferenceStore()
+ .setValue(UIPreferences.AUTO_STAGE_ON_COMMIT, false);
Activator.getDefault().getPreferenceStore()
.setDefault(UIPreferences.STAGING_VIEW_SYNC_SELECTION, false);
Activator.getDefault().getPreferenceStore()
@@ -67,6 +78,8 @@ public class CommitActionStagingViewTest extends LocalRepositoryTestCase {
Activator.getDefault().getPreferenceStore().setValue(
UIPreferences.ALWAYS_USE_STAGING_VIEW, initialUseStagingView);
Activator.getDefault().getPreferenceStore()
+ .setValue(UIPreferences.AUTO_STAGE_ON_COMMIT, initialAutoStage);
+ Activator.getDefault().getPreferenceStore()
.setDefault(UIPreferences.STAGING_VIEW_SYNC_SELECTION, true);
Activator.getDefault().getPreferenceStore()
.setValue(UIPreferences.STAGING_VIEW_SYNC_SELECTION, true);
@@ -80,6 +93,7 @@ public class CommitActionStagingViewTest extends LocalRepositoryTestCase {
String menuString = util.getPluginLocalizedValue("CommitAction_label");
ContextMenuHelper.clickContextMenu(projectExplorerTree, "Team",
menuString);
+ TestUtil.joinJobs(ADD_TO_INDEX);
TestUtil.waitUntilViewWithGivenIdShows(StagingView.VIEW_ID);
final Repository[] repo = { null };
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@@ -102,4 +116,61 @@ public class CommitActionStagingViewTest extends LocalRepositoryTestCase {
assertEquals("Repository mismatch", repository, repo[0]);
}
+ @Test
+ public void testCommitWithoutAutoStage() throws Exception {
+ setTestFileContent("I have changed this");
+ SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
+ util.getProjectItems(projectExplorerTree, PROJ1)[0].select();
+ String menuString = util.getPluginLocalizedValue("CommitAction_label");
+ ContextMenuHelper.clickContextMenu(projectExplorerTree, "Team",
+ menuString);
+ TestUtil.joinJobs(ADD_TO_INDEX);
+ TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
+ TestUtil.waitUntilViewWithGivenIdShows(StagingView.VIEW_ID);
+ StagingUtil.assertStaging(PROJ1, FOLDER + '/' + FILE1, false);
+ }
+
+ @Test
+ public void testCommitWithAutoStageNoUntracked() throws Exception {
+ assertCommitWithAutoStage(false);
+ }
+
+ @Test
+ public void testCommitWithAutoStageWithUntracked() throws Exception {
+ assertCommitWithAutoStage(true);
+ }
+
+ private void assertCommitWithAutoStage(boolean withUntracked)
+ throws Exception {
+ Activator.getDefault().getPreferenceStore()
+ .setValue(UIPreferences.AUTO_STAGE_ON_COMMIT, true);
+ boolean initialIncludeUntracked = Activator.getDefault()
+ .getPreferenceStore()
+ .getBoolean(UIPreferences.COMMIT_DIALOG_INCLUDE_UNTRACKED);
+ Activator.getDefault().getPreferenceStore().setValue(
+ UIPreferences.COMMIT_DIALOG_INCLUDE_UNTRACKED, withUntracked);
+ String newFile = "newFile.txt";
+ try {
+ setTestFileContent("I have changed this");
+ touch(PROJ1, newFile, "New file content");
+ SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
+ util.getProjectItems(projectExplorerTree, PROJ1)[0].select();
+ String menuString = util
+ .getPluginLocalizedValue("CommitAction_label");
+ JobJoiner joiner = JobJoiner.startListening(ADD_TO_INDEX, 10,
+ TimeUnit.SECONDS);
+ ContextMenuHelper.clickContextMenu(projectExplorerTree, "Team",
+ menuString);
+ joiner.join();
+ TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
+ TestUtil.waitUntilViewWithGivenIdShows(StagingView.VIEW_ID);
+ StagingUtil.assertStaging(PROJ1, FOLDER + '/' + FILE1, true);
+ StagingUtil.assertStaging(PROJ1, newFile, withUntracked);
+ } finally {
+ Activator.getDefault().getPreferenceStore().setValue(
+ UIPreferences.COMMIT_DIALOG_INCLUDE_UNTRACKED,
+ initialIncludeUntracked);
+ }
+ }
+
}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/StageUnstageActionTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/StageUnstageActionTest.java
index 00a7b08c3f..206df9eedd 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/StageUnstageActionTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/StageUnstageActionTest.java
@@ -10,17 +10,13 @@ package org.eclipse.egit.ui.test.team.actions;
import static org.eclipse.egit.ui.JobFamilies.ADD_TO_INDEX;
import static org.eclipse.egit.ui.JobFamilies.REMOVE_FROM_INDEX;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.egit.core.JobFamilies;
import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
-import org.eclipse.egit.ui.internal.resources.IResourceState;
-import org.eclipse.egit.ui.internal.resources.ResourceStateFactory;
import org.eclipse.egit.ui.test.ContextMenuHelper;
+import org.eclipse.egit.ui.test.StagingUtil;
import org.eclipse.egit.ui.test.TestUtil;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
@@ -127,7 +123,7 @@ public class StageUnstageActionTest extends LocalRepositoryTestCase {
TestUtil.joinJobs(ADD_TO_INDEX);
TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
// Verify file got staged
- verifyStaging(PROJ_A, filePath, true);
+ StagingUtil.assertStaging(PROJ_A, filePath, true);
// Remove from index
util.getProjectItems(projectExplorerTree, PROJ_A)[0].select();
assertFalse("Add To Index should not be present",
@@ -138,7 +134,7 @@ public class StageUnstageActionTest extends LocalRepositoryTestCase {
TestUtil.joinJobs(REMOVE_FROM_INDEX);
TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
// Verify file is unstaged again
- verifyStaging(PROJ_A, filePath, false);
+ StagingUtil.assertStaging(PROJ_A, filePath, false);
}
@Test
@@ -159,8 +155,8 @@ public class StageUnstageActionTest extends LocalRepositoryTestCase {
TestUtil.joinJobs(ADD_TO_INDEX);
TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
// Verify both files got staged
- verifyStaging(PROJ_A, filePath, true);
- verifyStaging(PROJ_B, filePath, true);
+ StagingUtil.assertStaging(PROJ_A, filePath, true);
+ StagingUtil.assertStaging(PROJ_B, filePath, true);
// Select both projects
projectExplorerTree.select(projectExplorerTree.getAllItems());
// Remove from index
@@ -169,23 +165,8 @@ public class StageUnstageActionTest extends LocalRepositoryTestCase {
TestUtil.joinJobs(REMOVE_FROM_INDEX);
TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
// Verify both files got unstaged
- verifyStaging(PROJ_A, filePath, false);
- verifyStaging(PROJ_B, filePath, false);
+ StagingUtil.assertStaging(PROJ_A, filePath, false);
+ StagingUtil.assertStaging(PROJ_B, filePath, false);
}
- private void verifyStaging(String projectName, String filePath,
- boolean expected) {
- IProject project = ResourcesPlugin.getWorkspace().getRoot()
- .getProject(projectName);
- IResource resource = project.findMember(filePath);
- assertNotNull(filePath + " should exist", resource);
- IResourceState state = ResourceStateFactory.getInstance().get(resource);
- if (expected) {
- assertTrue(projectName + '/' + filePath + " should be staged",
- state.isStaged());
- } else {
- assertFalse(projectName + '/' + filePath + " should be unstaged",
- state.isStaged());
- }
- }
}

Back to the top