Created
June 30, 2012 13:09
-
-
Save peichhorn/3023685 to your computer and use it in GitHub Desktop.
Patch to add 'Remove Untracked Files' to the EGit StageView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 917c156..9ebfc86 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 | |
@@ -79,6 +79,11 @@ | |
public final static Object ASSUME_NOASSUME_UNCHANGED = new Object(); | |
/** | |
+ * Removed Untracked Files | |
+ */ | |
+ public final static Object REMOVED_UNTRACKED_FILES = new Object(); | |
+ | |
+ /** | |
* Untrack | |
*/ | |
public final static Object UNTRACK = new Object(); | |
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java | |
index a5e9a85..f9f60fe 100644 | |
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java | |
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java | |
@@ -3443,6 +3443,12 @@ | |
public static String UnmergedBranchDialog_Title; | |
/** */ | |
+ public static String RemoveUntrackedFiles_removingUntrackedFiles; | |
+ | |
+ /** */ | |
+ public static String StagingView_RemoveUntrackedFilesMenuLabel; | |
+ | |
+ /** */ | |
public static String Untrack_untrack; | |
/** */ | |
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 7d5cb91..049d1cc 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 | |
@@ -20,6 +20,7 @@ | |
import java.util.Iterator; | |
import java.util.List; | |
+import org.eclipse.core.commands.ExecutionException; | |
import org.eclipse.core.expressions.IEvaluationContext; | |
import org.eclipse.core.resources.IFile; | |
import org.eclipse.core.resources.IProject; | |
@@ -28,7 +29,11 @@ | |
import org.eclipse.core.resources.ResourcesPlugin; | |
import org.eclipse.core.runtime.CoreException; | |
import org.eclipse.core.runtime.IAdaptable; | |
+import org.eclipse.core.runtime.IProgressMonitor; | |
+import org.eclipse.core.runtime.IStatus; | |
import org.eclipse.core.runtime.Path; | |
+import org.eclipse.core.runtime.Status; | |
+import org.eclipse.core.runtime.jobs.Job; | |
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; | |
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; | |
import org.eclipse.core.runtime.preferences.InstanceScope; | |
@@ -39,6 +44,7 @@ | |
import org.eclipse.egit.core.op.CommitOperation; | |
import org.eclipse.egit.core.project.RepositoryMapping; | |
import org.eclipse.egit.ui.Activator; | |
+import org.eclipse.egit.ui.JobFamilies; | |
import org.eclipse.egit.ui.UIIcons; | |
import org.eclipse.egit.ui.UIPreferences; | |
import org.eclipse.egit.ui.UIText; | |
@@ -116,6 +122,7 @@ | |
import org.eclipse.swt.graphics.Image; | |
import org.eclipse.swt.widgets.Composite; | |
import org.eclipse.swt.widgets.Control; | |
+import org.eclipse.swt.widgets.Shell; | |
import org.eclipse.swt.widgets.Text; | |
import org.eclipse.ui.IEditorInput; | |
import org.eclipse.ui.IEditorPart; | |
@@ -134,6 +141,8 @@ | |
import org.eclipse.ui.forms.widgets.FormToolkit; | |
import org.eclipse.ui.forms.widgets.Section; | |
import org.eclipse.ui.handlers.IHandlerService; | |
+import org.eclipse.ui.ide.undo.DeleteResourcesOperation; | |
+import org.eclipse.ui.ide.undo.WorkspaceUndoUtil; | |
import org.eclipse.ui.menus.CommandContributionItem; | |
import org.eclipse.ui.menus.CommandContributionItemParameter; | |
import org.eclipse.ui.part.ViewPart; | |
@@ -801,6 +810,7 @@ | |
}; | |
boolean addReplaceWithFileInGitIndex = false; | |
boolean addReplaceWithHeadRevision = false; | |
+ boolean addRemoveUntrackedFiles = false; | |
boolean addStage = false; | |
boolean addUnstage = false; | |
boolean addLaunchMergeTool = false; | |
@@ -829,9 +839,12 @@ | |
case MISSING: | |
case MODIFIED: | |
case PARTIALLY_MODIFIED: | |
- case UNTRACKED: | |
- addReplaceWithFileInGitIndex = true; | |
addReplaceWithHeadRevision = true; | |
+ addReplaceWithFileInGitIndex = true; | |
+ addStage = true; | |
+ break; | |
+ case UNTRACKED: | |
+ addRemoveUntrackedFiles = true; | |
addStage = true; | |
break; | |
} | |
@@ -862,6 +875,13 @@ | |
menuMgr.add(createItem(ActionCommands.REPLACE_WITH_HEAD_ACTION, tableViewer)); | |
if (addLaunchMergeTool) | |
menuMgr.add(createItem(ActionCommands.MERGE_TOOL_ACTION, tableViewer)); | |
+ if (addRemoveUntrackedFiles) | |
+ menuMgr.add(new Action(UIText.StagingView_RemoveUntrackedFilesMenuLabel) { | |
+ @Override | |
+ public void run() { | |
+ removeUntracked((IStructuredSelection) tableViewer.getSelection()); | |
+ } | |
+ }); | |
} | |
}); | |
@@ -1107,6 +1127,72 @@ | |
} | |
} | |
+ private void removeUntracked(final IStructuredSelection selection) { | |
+ if (selection.isEmpty()) | |
+ return; | |
+ | |
+ final Shell shell = form.getShell(); | |
+ | |
+ Job deleteJob = new Job( | |
+ UIText.RemoveUntrackedFiles_removingUntrackedFiles) { | |
+ public IStatus run(final IProgressMonitor monitor) { | |
+ final List<IResource> resources = new ArrayList<IResource>(); | |
+ Iterator iterator = selection.iterator(); | |
+ while (iterator.hasNext()) { | |
+ StagingEntry entry = (StagingEntry) iterator.next(); | |
+ switch (entry.getState()) { | |
+ case UNTRACKED: | |
+ String path = currentRepository.getWorkTree() + "/" + entry.getPath(); //$NON-NLS-1$ | |
+ IResource resource = getResource(path); | |
+ if (resource == null) { | |
+ continue; | |
+ } | |
+ resources.add(resource); | |
+ break; | |
+ default: | |
+ continue; | |
+ } | |
+ } | |
+ | |
+ if (resources.isEmpty()) return Status.OK_STATUS; | |
+ | |
+ try { | |
+ final DeleteResourcesOperation op = new DeleteResourcesOperation( | |
+ resources.toArray(new IResource[resources.size()]), | |
+ UIText.RemoveUntrackedFiles_removingUntrackedFiles, | |
+ false); | |
+ return PlatformUI | |
+ .getWorkbench() | |
+ .getOperationSupport() | |
+ .getOperationHistory() | |
+ .execute(op, monitor, | |
+ WorkspaceUndoUtil.getUIInfoAdapter(shell)); | |
+ } catch (ExecutionException e) { | |
+ if (e.getCause() instanceof CoreException) { | |
+ return ((CoreException) e.getCause()).getStatus(); | |
+ } | |
+ return new Status(IStatus.ERROR, Activator.getPluginId(), | |
+ e.getMessage(), e); | |
+ } | |
+ } | |
+ | |
+ /* | |
+ * (non-Javadoc) | |
+ * | |
+ * @see | |
+ * org.eclipse.core.runtime.jobs.Job#belongsTo(java.lang.Object) | |
+ */ | |
+ public boolean belongsTo(Object family) { | |
+ if (JobFamilies.REMOVED_UNTRACKED_FILES.equals(family)) { | |
+ return true; | |
+ } | |
+ return super.belongsTo(family); | |
+ } | |
+ }; | |
+ deleteJob.setUser(true); | |
+ deleteJob.schedule(); | |
+ } | |
+ | |
private void updateDirCache(IStructuredSelection selection, | |
final RevCommit headRev, final DirCacheEditor edit) { | |
Iterator iterator = selection.iterator(); | |
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties | |
index ffa6b3f..6a8d427 100644 | |
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties | |
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties | |
@@ -1186,6 +1186,7 @@ | |
UIUtils_StartTypingForPreviousValuesMessage=Start typing to see a filtered list of previously used values (use "*" as wildcard) | |
UnmergedBranchDialog_Message=Not all commits of these branches have been merged into the currently checked out branch.\n\nDo you still want to delete these branches? | |
UnmergedBranchDialog_Title=Confirm Branch Deletion | |
+RemoveUntrackedFiles_removingUntrackedFiles = Removing Untracked Files | |
Untrack_untrack=Untrack | |
TagAction_cannotCheckout=Cannot checkout now | |
@@ -1547,6 +1548,7 @@ | |
StagingView_UnstageItemMenuLabel=Remove from Git Index | |
StagingView_StageItemMenuLabel=Add to Git Index | |
StagingViewContentProvider_SubmoduleError=Unhandled exception while analyzing submodules | |
+StagingView_RemoveUntrackedFilesMenuLabel=Remove Untracked Files | |
StashApplyCommand_applyFailed=Applying stashed commit ''{0}'' failed | |
StashApplyCommand_jobTitle=Apply changes from stashed commit ''{0}'' | |
StashCreateCommand_jobTitle=Stashing local changes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment