Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-11-07 11:22:35 -0500
committerThomas Wolf2019-11-07 12:30:12 -0500
commit64bc32a1af050e2d5ef8e25359bd638aa94cc4b6 (patch)
treea1be7fb2731c8f105355fc68c27ce4e1990f48f2
parent35ef2d7ac08a3230be498a9e999ec3f516edb821 (diff)
downloadegit-64bc32a1af050e2d5ef8e25359bd638aa94cc4b6.tar.gz
egit-64bc32a1af050e2d5ef8e25359bd638aa94cc4b6.tar.xz
egit-64bc32a1af050e2d5ef8e25359bd638aa94cc4b6.zip
[staging view] Run deletion and discarding changes in background jobs
Run the DeletePathsOperation in a job. The normal DeleteResourceAction also performs the deletion in a job. For resetting, re-use the DiscardChangesOperation and also run it in a job. Name the UI text keys for DeletePathsOperationUI consistently. Fix broken GitRepositoriesViewTest.testDeleteFileNotInProject(); this test actually tested the wrong thing and worked only by chance. It should have failed since commit a422ae25 when the button label was changed. It kept on working because it actually got the platform's "Delete Resources" dialog, not EGit's "Delete Files" dialog, which until now happened to have the same title. Bug: 552776 Change-Id: I8da1967e9bf2151d89ef06fdeedccab0059b7568 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java7
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/JobFamilies.java6
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java21
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/operations/DeletePathsOperationUI.java51
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java66
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties7
6 files changed, 73 insertions, 85 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java
index 21661ddca..cb387c3a9 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java
@@ -775,6 +775,9 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
@Test
public void testDeleteFileNotInProject() throws Exception {
+ // PROJ2 is still a valid Eclipse project at that point, even though the
+ // .project file wasn't committed. Close it.
+ ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ2).close(null);
SWTBotTree tree = getOrOpenView().bot().tree();
refreshAndWait();
@@ -785,8 +788,8 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
myUtil.getPluginLocalizedValue("RepoViewDeleteFile.label"));
SWTBotShell confirm = bot
- .shell(UIText.DeleteResourcesOperationUI_confirmActionTitle);
- confirm.bot().button(IDialogConstants.OK_LABEL).click();
+ .shell(UIText.DeletePathsOperationUI_confirmActionTitle);
+ confirm.bot().button(UIText.DeletePathsOperationUI_ButtonOK).click();
bot.waitUntil(shellCloses(confirm));
TestUtil.joinJobs(JobFamilies.REPO_VIEW_REFRESH);
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/JobFamilies.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/JobFamilies.java
index 33befcaa2..9158589b3 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/JobFamilies.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/JobFamilies.java
@@ -144,6 +144,11 @@ public class JobFamilies {
public final static Object UNTRACK = new JobFamily();
/**
+ * Delete Files
+ */
+ public final static Object DELETE = new JobFamily();
+
+ /**
* Disconnect
*/
public final static Object DISCONNECT = new JobFamily();
@@ -153,7 +158,6 @@ public class JobFamilies {
*/
public final static Object DISCARD_CHANGES = new JobFamily();
-
/**
* Add to index job
*/
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 a37cc913c..9cb50dd5c 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
@@ -3643,6 +3643,15 @@ public class UIText extends NLS {
public static String DeletePathsOperationUI_ButtonOK;
/** */
+ public static String DeletePathsOperationUI_confirmActionTitle;
+
+ /** */
+ public static String DeletePathsOperationUI_confirmActionMessage;
+
+ /** */
+ public static String DeletePathsOperationUI_DeleteFilesJobName;
+
+ /** */
public static String DeleteRepositoryConfirmDialog_DeleteGitDirCheckbox;
/** */
@@ -3690,15 +3699,6 @@ public class UIText extends NLS {
public static String DeleteTagCommand_titleConfirm;
/** */
- public static String DeleteResourcesOperationUI_confirmActionTitle;
-
- /** */
- public static String DeleteResourcesOperationUI_confirmActionMessage;
-
- /** */
- public static String DeleteResourcesOperationUI_deleteFailed;
-
- /** */
public static String IgnoreActionHandler_addToGitignore;
/** */
@@ -5453,9 +5453,6 @@ public class UIText extends NLS {
public static String StagingView_cancelCommitAfterSaving;
/** */
- public static String StagingView_checkoutFailed;
-
- /** */
public static String StagingView_commitFailed;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/operations/DeletePathsOperationUI.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/operations/DeletePathsOperationUI.java
index 1dd9d6fe0..32334c8ed 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/operations/DeletePathsOperationUI.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/operations/DeletePathsOperationUI.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (C) 2012, Robin Stocker <robin@nibor.org>
+ * Copyright (C) 2012, 2019 Robin Stocker <robin@nibor.org> and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -15,18 +15,18 @@ import java.util.Collection;
import java.util.List;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.egit.core.internal.job.JobUtil;
import org.eclipse.egit.core.internal.util.ResourceUtil;
import org.eclipse.egit.core.op.DeletePathsOperation;
-import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.JobFamilies;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.window.IShellProvider;
-import org.eclipse.swt.widgets.Shell;
+import org.eclipse.jface.window.Window;
import org.eclipse.ui.actions.DeleteResourceAction;
/**
@@ -56,10 +56,11 @@ public class DeletePathsOperationUI {
*/
public void run() {
List<IResource> resources = getSelectedResourcesIfAllExist();
- if (resources != null)
+ if (resources != null) {
runNormalAction(resources);
- else
+ } else {
runNonWorkspaceAction();
+ }
}
private void runNormalAction(List<IResource> resources) {
@@ -69,41 +70,29 @@ public class DeletePathsOperationUI {
action.run();
}
- private String[] getButtonLabels() {
- return new String[] { UIText.DeletePathsOperationUI_ButtonOK, IDialogConstants.CANCEL_LABEL };
- }
-
- private boolean openConfirm(Shell parent, String title, String message) {
- MessageDialog dialog = new MessageDialog(parent, title, null, message,
- MessageDialog.CONFIRM, getButtonLabels(), 0);
- return dialog.open() == 0;
- }
-
private void runNonWorkspaceAction() {
- boolean performAction = openConfirm(
- shellProvider.getShell(),
- UIText.DeleteResourcesOperationUI_confirmActionTitle,
- UIText.DeleteResourcesOperationUI_confirmActionMessage);
- if (!performAction)
+ String[] buttonLabels = { UIText.DeletePathsOperationUI_ButtonOK,
+ IDialogConstants.CANCEL_LABEL };
+ MessageDialog dialog = new MessageDialog(shellProvider.getShell(),
+ UIText.DeletePathsOperationUI_confirmActionTitle, null,
+ UIText.DeletePathsOperationUI_confirmActionMessage,
+ MessageDialog.CONFIRM, buttonLabels, 0);
+ if (dialog.open() != Window.OK) {
return;
-
- DeletePathsOperation operation = new DeletePathsOperation(paths);
-
- try {
- operation.execute(null);
- } catch (CoreException e) {
- Activator.handleError(UIText.DeleteResourcesOperationUI_deleteFailed, e, true);
}
+ JobUtil.scheduleUserWorkspaceJob(new DeletePathsOperation(paths),
+ UIText.DeletePathsOperationUI_DeleteFilesJobName,
+ JobFamilies.DELETE);
}
private List<IResource> getSelectedResourcesIfAllExist() {
List<IResource> resources = new ArrayList<>();
for (IPath path : paths) {
IResource resource = ResourceUtil.getResourceForLocation(path, false);
- if (resource != null)
- resources.add(resource);
- else
+ if (resource == null) {
return null;
+ }
+ resources.add(resource);
}
return resources;
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java
index 6f42f2de2..d298841b6 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java
@@ -70,6 +70,7 @@ import org.eclipse.egit.core.internal.job.JobUtil;
import org.eclipse.egit.core.internal.job.RuleUtil;
import org.eclipse.egit.core.op.AssumeUnchangedOperation;
import org.eclipse.egit.core.op.CommitOperation;
+import org.eclipse.egit.core.op.DiscardChangesOperation;
import org.eclipse.egit.core.op.UntrackOperation;
import org.eclipse.egit.core.project.RepositoryMapping;
import org.eclipse.egit.ui.Activator;
@@ -159,7 +160,6 @@ import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.api.AddCommand;
-import org.eclipse.jgit.api.CheckoutCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.ResetCommand;
import org.eclipse.jgit.api.RmCommand;
@@ -3038,7 +3038,7 @@ public class StagingView extends ViewPart
private class ReplaceAction extends Action {
- IStructuredSelection selection;
+ private final IStructuredSelection selection;
private final boolean headRevision;
ReplaceAction(String text, @NonNull IStructuredSelection selection,
@@ -3065,46 +3065,42 @@ public class StagingView extends ViewPart
}
}
- private void replaceWith(@NonNull List<String> files,
- @NonNull List<String> inaccessibleFiles) {
- Repository repository = currentRepository;
- if (files.isEmpty() || repository == null) {
- return;
- }
- try (Git git = new Git(repository)) {
- CheckoutCommand checkoutCommand = git.checkout();
- if (headRevision) {
- checkoutCommand.setStartPoint(Constants.HEAD);
- }
- for (String path : files) {
- checkoutCommand.addPath(path);
- }
- checkoutCommand.call();
- if (!inaccessibleFiles.isEmpty()) {
- IndexDiffCacheEntry indexDiffCacheForRepository = org.eclipse.egit.core.Activator
- .getDefault().getIndexDiffCache()
- .getIndexDiffCacheEntry(repository);
- if (indexDiffCacheForRepository != null) {
- indexDiffCacheForRepository
- .refreshFiles(inaccessibleFiles);
- }
- }
- } catch (Exception e) {
- Activator.handleError(UIText.StagingView_checkoutFailed, e,
- true);
- }
- }
-
@Override
public void run() {
- if (!CommandConfirmation.confirmCheckout(form.getShell(),
- getCurrentRepository())) {
+ Repository repo = getCurrentRepository();
+ if (repo == null) {
return;
}
List<String> files = new ArrayList<>();
List<String> inaccessibleFiles = new ArrayList<>();
getSelectedFiles(files, inaccessibleFiles);
- replaceWith(files, inaccessibleFiles);
+ if (files.isEmpty()) {
+ return;
+ }
+ if (!CommandConfirmation.confirmCheckout(form.getShell(), repo)) {
+ return;
+ }
+ DiscardChangesOperation operation = new DiscardChangesOperation(
+ repo, files, headRevision ? Constants.HEAD : null);
+ JobChangeAdapter refresher = null;
+ if (!inaccessibleFiles.isEmpty()) {
+ refresher = new JobChangeAdapter() {
+
+ @Override
+ public void done(IJobChangeEvent event) {
+ IndexDiffCacheEntry indexDiffCacheForRepository = org.eclipse.egit.core.Activator
+ .getDefault().getIndexDiffCache()
+ .getIndexDiffCacheEntry(repo);
+ if (indexDiffCacheForRepository != null) {
+ indexDiffCacheForRepository
+ .refreshFiles(inaccessibleFiles);
+ }
+ }
+ };
+ }
+ JobUtil.scheduleUserWorkspaceJob(operation,
+ UIText.DiscardChangesAction_discardChanges,
+ JobFamilies.DISCARD_CHANGES, refresher);
}
}
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 bad9bd46d..4f41a5e3e 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
@@ -1287,6 +1287,9 @@ DeleteBranchOnCommitHandler_DeleteBranchesDialogButton=&Delete
DeleteBranchOnCommitHandler_DeleteBranchesDialogMessage=Please select the branches you want to delete
DeleteBranchOnCommitHandler_DeleteBranchesDialogTitle=Delete Branches
DeletePathsOperationUI_ButtonOK=&Delete
+DeletePathsOperationUI_confirmActionTitle=Delete Files
+DeletePathsOperationUI_confirmActionMessage=Delete the selected files from the file system?
+DeletePathsOperationUI_DeleteFilesJobName=Deleting Files
DeleteRepositoryConfirmDialog_DeleteGitDirCheckbox=Delete Git repository data and history:
DeleteRepositoryConfirmDialog_DeleteRepositoryConfirmMessage=Confirm deletion of repository.
DeleteRepositoryConfirmDialog_DeleteRepositoryNoUndoWarning=Repository deletion cannot be undone.
@@ -1303,9 +1306,6 @@ DeleteTagCommand_messageConfirmMultipleTag=Delete these {0} tags?
DeleteTagCommand_messageConfirmSingleTag=Delete tag ''{0}''?
DeleteTagCommand_taskName=Deleting tag
DeleteTagCommand_titleConfirm=Confirm Tag Deletion
-DeleteResourcesOperationUI_confirmActionTitle=Delete Resources
-DeleteResourcesOperationUI_confirmActionMessage=Delete the selected files from the file system?
-DeleteResourcesOperationUI_deleteFailed=Deleting resources failed
IgnoreActionHandler_addToGitignore=Add to .gitignore
IgnoreActionHandler_manyFilesToBeIgnoredTitle=Ignoring {0} files
@@ -1905,7 +1905,6 @@ StagingView_cancelCommitAfterSaving=Do you want to cancel the commit, so you can
StagingView_Commit=&Commit
StagingView_CommitToolTip=Commit ({0})
StagingView_CommitAndPush=Co&mmit and Push...
-StagingView_checkoutFailed=Checking out files failed
StagingView_commitFailed=Commit failed
StagingView_committingNotPossible=Committing is not possible
StagingView_headCommitChanged=\# WARNING: head commit changed in the meantime

Back to the top