Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/op/DiscardChangesOperation.java15
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java10
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/BranchAndResetActionTest.java34
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java2
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/branch/CleanupUncomittedChangesDialog.java17
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CheckoutConflictDialog.java13
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties6
7 files changed, 76 insertions, 21 deletions
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/DiscardChangesOperation.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/DiscardChangesOperation.java
index c18ed0f36..c28491377 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/DiscardChangesOperation.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/DiscardChangesOperation.java
@@ -17,6 +17,7 @@
package org.eclipse.egit.core.op;
import java.util.Collection;
+import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
@@ -108,6 +109,20 @@ public class DiscardChangesOperation implements IEGitOperation {
this(ResourceUtil.splitPathsByRepository(paths));
}
+ /**
+ * A {@link DiscardChangesOperation} that resets the given repo-relative
+ * paths in the given repository.
+ *
+ * @param repository
+ * to work on
+ * @param paths
+ * collection of repository-relative paths to reset
+ */
+ public DiscardChangesOperation(Repository repository,
+ Collection<String> paths) {
+ this(Collections.singletonMap(repository, paths));
+ }
+
private DiscardChangesOperation(
Map<Repository, Collection<String>> pathsByRepository) {
this.pathsByRepository = pathsByRepository;
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java
index 53c56ff0b..a1b6f4e8f 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java
@@ -756,13 +756,17 @@ public abstract class LocalRepositoryTestCase extends EGitTestCase {
}
protected String getTestFileContent() throws Exception {
+ return getTestFileContent(FILE1);
+ }
+
+ protected String getTestFileContent(String fileName) throws Exception {
IFile file = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1)
- .getFile(new Path("folder/test.txt"));
+ .getFolder(FOLDER).getFile(fileName);
if (file.exists()) {
byte[] bytes = IO.readFully(file.getLocation().toFile());
return new String(bytes, file.getCharset());
- } else
- return "";
+ }
+ return "";
}
/**
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/BranchAndResetActionTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/BranchAndResetActionTest.java
index 9a984b58d..65e0d934d 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/BranchAndResetActionTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/BranchAndResetActionTest.java
@@ -36,6 +36,7 @@ import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.egit.core.op.CommitOperation;
import org.eclipse.egit.core.op.TagOperation;
+import org.eclipse.egit.core.test.TestUtils;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.JobFamilies;
import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
@@ -130,6 +131,39 @@ public class BranchAndResetActionTest extends LocalRepositoryTestCase {
}
@Test
+ public void testCheckoutWithConflictsAndReset() throws Exception {
+ String charset = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(PROJ1).getDefaultCharset();
+ String file1Content = getTestFileContent();
+ checkoutAndVerify(new String[] { LOCAL_BRANCHES, "stable" });
+ ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1)
+ .getFolder(FOLDER).getFile(FILE1).setContents(
+ new ByteArrayInputStream(
+ "New content".getBytes(charset)),
+ IResource.NONE, null);
+ String file2Content = "Also changed";
+ ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1)
+ .getFolder(FOLDER).getFile(FILE2).setContents(
+ new ByteArrayInputStream(
+ file2Content.getBytes(charset)),
+ IResource.NONE, null);
+ checkout(new String[] { LOCAL_BRANCHES, "master" });
+ SWTBotShell showConflicts = bot
+ .shell(UIText.BranchResultDialog_CheckoutConflictsTitle);
+ SWTBot shellBot = showConflicts.bot();
+ SWTBotTreeItem[] items = shellBot.tree().getAllItems();
+ assertEquals(1, items.length);
+ assertEquals(FILE1, items[0].getItems()[0].getItems()[0].getText());
+ shellBot.button(UIText.BranchResultDialog_buttonDiscardChanges).click();
+ TestUtils.waitForJobs(500, 5000, JobFamilies.DISCARD_CHANGES);
+ TestUtil.joinJobs(JobFamilies.CHECKOUT);
+ assertEquals(file1Content, getTestFileContent());
+ // FILE2 should _not_ have been reset since it didn't conflict with the
+ // checkout and wasn't shown in the conflict dialog
+ assertEquals(file2Content, getTestFileContent(FILE2));
+ }
+
+ @Test
public void testCheckoutWithNonDeleted() throws Exception {
// we need to check if this file system has problems to
// delete a file with an open FileInputStrem
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
index 7a5f992bf..d58e3fe66 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
@@ -3295,7 +3295,7 @@ public class UIText extends NLS {
public static String BranchResultDialog_buttonCommit;
/** */
- public static String BranchResultDialog_buttonReset;
+ public static String BranchResultDialog_buttonDiscardChanges;
/** */
public static String BranchResultDialog_buttonStash;
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/branch/CleanupUncomittedChangesDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/branch/CleanupUncomittedChangesDialog.java
index 2d1e0e916..be96d3b38 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/branch/CleanupUncomittedChangesDialog.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/branch/CleanupUncomittedChangesDialog.java
@@ -14,7 +14,7 @@ import java.util.List;
import org.eclipse.core.resources.IResource;
import org.eclipse.egit.core.internal.job.JobUtil;
-import org.eclipse.egit.core.op.ResetOperation;
+import org.eclipse.egit.core.op.DiscardChangesOperation;
import org.eclipse.egit.ui.JobFamilies;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.commit.CommitUI;
@@ -23,10 +23,7 @@ import org.eclipse.egit.ui.internal.stash.StashCreateUI;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
-import org.eclipse.jgit.api.ResetCommand.ResetType;
-import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository;
-import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridLayout;
@@ -88,11 +85,11 @@ public class CleanupUncomittedChangesDialog extends MessageDialog {
shouldContinue = commitUI.commit();
break;
case IDialogConstants.ABORT_ID:
- final ResetOperation operation = new ResetOperation(repository,
- Constants.HEAD, ResetType.HARD);
- String jobname = NLS.bind(UIText.ResetAction_reset, Constants.HEAD);
- JobUtil.scheduleUserWorkspaceJob(operation, jobname,
- JobFamilies.RESET);
+ DiscardChangesOperation operation = new DiscardChangesOperation(
+ repository, fileList);
+ JobUtil.scheduleUserWorkspaceJob(operation,
+ UIText.DiscardChangesAction_discardChanges,
+ JobFamilies.DISCARD_CHANGES);
shouldContinue = true;
break;
case IDialogConstants.SKIP_ID:
@@ -114,7 +111,7 @@ public class CleanupUncomittedChangesDialog extends MessageDialog {
createButton(parent, IDialogConstants.SKIP_ID,
UIText.BranchResultDialog_buttonStash, false);
createButton(parent, IDialogConstants.ABORT_ID,
- UIText.BranchResultDialog_buttonReset, false);
+ UIText.BranchResultDialog_buttonDiscardChanges, false);
createButton(parent, IDialogConstants.CANCEL_ID,
IDialogConstants.CANCEL_LABEL, true);
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CheckoutConflictDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CheckoutConflictDialog.java
index 921d74311..2217b0527 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CheckoutConflictDialog.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CheckoutConflictDialog.java
@@ -16,11 +16,13 @@ package org.eclipse.egit.ui.internal.dialogs;
import java.util.List;
+import org.eclipse.egit.core.internal.job.JobUtil;
+import org.eclipse.egit.core.op.DiscardChangesOperation;
+import org.eclipse.egit.ui.JobFamilies;
import org.eclipse.egit.ui.internal.CommonUtils;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.actions.ActionCommands;
import org.eclipse.egit.ui.internal.repository.tree.RepositoryNode;
-import org.eclipse.egit.ui.internal.repository.tree.command.ResetCommand;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
@@ -80,8 +82,11 @@ public class CheckoutConflictDialog extends MessageDialog {
new StructuredSelection(repository));
break;
case IDialogConstants.ABORT_ID:
- CommonUtils.runCommand(ResetCommand.ID, new StructuredSelection(
- new RepositoryNode(null, repository)));
+ DiscardChangesOperation operation = new DiscardChangesOperation(
+ repository, this.conflicts);
+ JobUtil.scheduleUserWorkspaceJob(operation,
+ UIText.DiscardChangesAction_discardChanges,
+ JobFamilies.DISCARD_CHANGES);
break;
case IDialogConstants.SKIP_ID:
CommonUtils.runCommand(ActionCommands.STASH_CREATE,
@@ -98,7 +103,7 @@ public class CheckoutConflictDialog extends MessageDialog {
protected void createButtonsForButtonBar(Composite parent) {
super.createButtonsForButtonBar(parent);
createButton(parent, IDialogConstants.ABORT_ID,
- UIText.BranchResultDialog_buttonReset, false);
+ UIText.BranchResultDialog_buttonDiscardChanges, false);
createButton(parent, IDialogConstants.PROCEED_ID,
UIText.BranchResultDialog_buttonCommit, false);
createButton(parent, IDialogConstants.SKIP_ID,
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
index f06fd42c2..81dd5c4c6 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
@@ -1174,9 +1174,9 @@ BranchPropertySource_RemoteDescriptor=Remote
BranchPropertySource_UpstreamBranchDescriptor=Upstream Branch
BranchPropertySource_UpstreamConfigurationCategory=Upstream Configuration
BranchPropertySource_ValueNotSet=<Not set>
-BranchResultDialog_buttonCommit=Commit...
-BranchResultDialog_buttonReset=Reset
-BranchResultDialog_buttonStash=Stash...
+BranchResultDialog_buttonCommit=Co&mmit...
+BranchResultDialog_buttonDiscardChanges=&Discard Changes
+BranchResultDialog_buttonStash=&Stash...
BranchResultDialog_CheckoutConflictsTitle=Checkout Conflicts
BranchResultDialog_DetachedHeadWarningDontShowAgain=Don't show any dialogs about this again
BranchSelectionAndEditDialog_Message=Select a ref and choose action to execute

Back to the top