Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-05-17 17:07:46 -0400
committerThomas Wolf2019-05-17 17:07:46 -0400
commit01b939fba59f2f6ec04663e84242e2c3cdc8f24c (patch)
tree42e74c27336ce5a34d257180a58ce4a06be7a7d0
parentba0338dadf704ce24a63cd99a22e3acac7887509 (diff)
downloadegit-01b939fba59f2f6ec04663e84242e2c3cdc8f24c.tar.gz
egit-01b939fba59f2f6ec04663e84242e2c3cdc8f24c.tar.xz
egit-01b939fba59f2f6ec04663e84242e2c3cdc8f24c.zip
Fix resetting conflicting files on branch switch
The new code from commit 8a66893 inadvertently reset to the index version instead of to HEAD and thus didn't reset staged changes. Fix this and add a new test. Change-Id: Icf6ffe38949cc8fd42cb35196c090a66c5527901 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/op/DiscardChangesOperation.java5
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/BranchAndResetActionTest.java20
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CleanupUncomittedChangesDialog.java3
3 files changed, 24 insertions, 4 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 b67fd80e2..d6ff2c0d3 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
@@ -118,10 +118,13 @@ public class DiscardChangesOperation implements IEGitOperation {
* to work on
* @param paths
* collection of repository-relative paths to reset
+ * @param revision
+ * to reset to, if {@code null}, reset to the index
*/
public DiscardChangesOperation(Repository repository,
- Collection<String> paths) {
+ Collection<String> paths, String revision) {
this(Collections.singletonMap(repository, paths));
+ this.revision = revision;
}
private DiscardChangesOperation(
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 980ba7663..33c4cc9b4 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
@@ -45,6 +45,7 @@ import org.eclipse.egit.ui.test.ContextMenuHelper;
import org.eclipse.egit.ui.test.TestUtil;
import org.eclipse.jface.bindings.keys.KeyStroke;
import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
@@ -129,8 +130,8 @@ public class BranchAndResetActionTest extends LocalRepositoryTestCase {
}
}
- @Test
- public void testCheckoutWithConflictsAndReset() throws Exception {
+ private void checkoutWithConflictsAndReset(boolean stage)
+ throws Exception {
String charset = ResourcesPlugin.getWorkspace().getRoot()
.getProject(PROJ1).getDefaultCharset();
String file1Content = getTestFileContent();
@@ -140,6 +141,11 @@ public class BranchAndResetActionTest extends LocalRepositoryTestCase {
new ByteArrayInputStream(
"New content".getBytes(charset)),
IResource.NONE, null);
+ if (stage) {
+ try (Git git = new Git(lookupRepository(repositoryFile))) {
+ git.add().addFilepattern(FILE1_PATH).call();
+ }
+ }
String file2Content = "Also changed";
ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1)
.getFolder(FOLDER).getFile(FILE2).setContents(
@@ -163,6 +169,16 @@ public class BranchAndResetActionTest extends LocalRepositoryTestCase {
}
@Test
+ public void testCheckoutWithConflictsAndReset() throws Exception {
+ checkoutWithConflictsAndReset(false);
+ }
+
+ @Test
+ public void testCheckoutWithStagedConflictsAndReset() throws Exception {
+ checkoutWithConflictsAndReset(true);
+ }
+
+ @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/dialogs/CleanupUncomittedChangesDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CleanupUncomittedChangesDialog.java
index 7e63ba1a7..c9bf409c2 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CleanupUncomittedChangesDialog.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CleanupUncomittedChangesDialog.java
@@ -25,6 +25,7 @@ import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
@@ -121,7 +122,7 @@ public class CleanupUncomittedChangesDialog extends MessageDialog {
break;
case IDialogConstants.ABORT_ID:
DiscardChangesOperation operation = new DiscardChangesOperation(
- repository, fileList);
+ repository, fileList, Constants.HEAD);
JobUtil.scheduleUserWorkspaceJob(operation,
UIText.DiscardChangesAction_discardChanges,
JobFamilies.DISCARD_CHANGES);

Back to the top