diff options
author | Andreas Hermann | 2014-05-08 14:41:28 +0000 |
---|---|---|
committer | Andreas Hermann | 2014-05-22 07:56:59 +0000 |
commit | 0a41e638df13b093aefe2fec3e4b685c0ac96ba8 (patch) | |
tree | 75e44debe0ff3661410765ba25f535b89460c8fb | |
parent | 5463421e94ed9fa93749fb3437e5153780e7dc12 (diff) | |
download | egit-0a41e638df13b093aefe2fec3e4b685c0ac96ba8.tar.gz egit-0a41e638df13b093aefe2fec3e4b685c0ac96ba8.tar.xz egit-0a41e638df13b093aefe2fec3e4b685c0ac96ba8.zip |
Add a flag in the StashCreateDialog to include untracked changes
This allows to stash everything away in order to clean the workspace.
Bug: 434429
JGit-Dependency: I2af784deb0c2320bb57bc4fd472a8daad8674e7d
Change-Id: I19e149e403a95c65da8442d8973284e1b428da57
Signed-off-by: Andreas Hermann <a.v.hermann@gmail.com>
6 files changed, 127 insertions, 10 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/StashCreateOperationTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/StashCreateOperationTest.java index 103eec35c2..8de5d3ff04 100644 --- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/StashCreateOperationTest.java +++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/StashCreateOperationTest.java @@ -79,4 +79,19 @@ public class StashCreateOperationTest extends GitTestCase { assertEquals(message, commit.getFullMessage()); } + @Test + public void testUntrackedFlag() throws Exception { + testUtils.addFileToProject(project.getProject(), "foo/untracked.txt", + "some text"); + String message = "stash with untracked files"; + StashCreateOperation stashCreateOperation = new StashCreateOperation( + repository, message, true); + stashCreateOperation.execute(null); + + RevWalk revWalk = new RevWalk(repository); + RevCommit commit = revWalk.parseCommit(repository.resolve("stash@{0}")); + // untracked commit is the third parent + assertEquals(commit.getParentCount(), 3); + } + } diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/StashCreateOperation.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/StashCreateOperation.java index d726d70642..8cdd7f97ec 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/StashCreateOperation.java +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/StashCreateOperation.java @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright (c) 2012 GitHub Inc. + * Copyright (c) 2012, 2014 GitHub Inc and others. * 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 @@ -37,13 +37,26 @@ public class StashCreateOperation implements IEGitOperation { private RevCommit commit; + private final boolean includeUntracked; + /** * Create operation for repository * * @param repository */ public StashCreateOperation(final Repository repository) { - this(repository, null); + this(repository, null, false); + } + + /** + * Create operation for repository + * + * @param repository + * @param message + */ + public StashCreateOperation(final Repository repository, + final String message) { + this(repository, message, false); } /** @@ -51,10 +64,13 @@ public class StashCreateOperation implements IEGitOperation { * * @param repository * @param message + * @param includeUntracked */ - public StashCreateOperation(final Repository repository, final String message) { + public StashCreateOperation(final Repository repository, + final String message, final boolean includeUntracked) { this.repository = repository; this.message = message; + this.includeUntracked = includeUntracked; } /** @@ -74,6 +90,7 @@ public class StashCreateOperation implements IEGitOperation { StashCreateCommand command = Git.wrap(repository).stashCreate(); if (message != null) command.setWorkingDirectoryMessage(message); + command.setIncludeUntracked(includeUntracked); commit = command.call(); } catch (JGitInternalException e) { throw new TeamException(e.getLocalizedMessage(), diff --git a/org.eclipse.egit.ui/plugin.properties b/org.eclipse.egit.ui/plugin.properties index 18efee32ac..ef18435f4b 100644 --- a/org.eclipse.egit.ui/plugin.properties +++ b/org.eclipse.egit.ui/plugin.properties @@ -312,7 +312,7 @@ SubmoduleAddCommand.label = Add Submodule... CleanCommand.name = Clean... CleanCommand.label = C&lean... StashCreateCommand.name = Stash Changes -StashCreateCommand.label = Stash Changes +StashCreateCommand.label = Stash Changes... StashApplyCommand.name = Apply Stashed Changes StashApplyCommand.label = Apply Stashed Changes StashDropCommand.name = Delete Stashed Commit... 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 9efeb3b02f..9df7d0cce6 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 @@ -4977,6 +4977,9 @@ public class UIText extends NLS { public static String StashCreateCommand_titleNoChanges; /** */ + public static String StashCreateCommand_includeUntrackedLabel; + + /** */ public static String StashDropCommand_confirmSingle; /** */ diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/stash/StashCreateUI.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/stash/StashCreateUI.java index 289692434b..e4e7a7f526 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/stash/StashCreateUI.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/stash/StashCreateUI.java @@ -22,13 +22,21 @@ import org.eclipse.egit.ui.Activator; import org.eclipse.egit.ui.JobFamilies; import org.eclipse.egit.ui.UIUtils; import org.eclipse.egit.ui.internal.UIText; -import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.window.Window; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; import org.eclipse.ui.PlatformUI; /** @@ -52,17 +60,17 @@ public class StashCreateUI { public boolean createStash(Shell shell) { if (!UIUtils.saveAllEditors(repo)) return false; - InputDialog commitMessageDialog = new InputDialog(shell, - UIText.StashCreateCommand_titleEnterCommitMessage, - UIText.StashCreateCommand_messageEnterCommitMessage, - null, null); + StashCreateDialog commitMessageDialog = new StashCreateDialog(shell); if (commitMessageDialog.open() != Window.OK) return false; String message = commitMessageDialog.getValue(); if (message.length() == 0) message = null; - final StashCreateOperation op = new StashCreateOperation(repo, message); + boolean includeUntracked = commitMessageDialog.getIncludeUntracked(); + + final StashCreateOperation op = new StashCreateOperation(repo, message, + includeUntracked); Job job = new WorkspaceJob(UIText.StashCreateCommand_jobTitle) { @Override @@ -108,4 +116,77 @@ public class StashCreateUI { }); } + private static class StashCreateDialog extends Dialog { + + /** + * Commit message widget. + */ + private Text text; + + /** + * Include untracked checkbox. + */ + private Button untrackedButton; + + /** + * The input value; the empty string by default. + */ + private String commitMessage = ""; //$NON-NLS-1$ + + private boolean includeUntracked; + + public StashCreateDialog(Shell shell) { + super(shell); + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + + getShell().setText( + UIText.StashCreateCommand_titleEnterCommitMessage); + + Label label = new Label(composite, SWT.WRAP); + label.setText(UIText.StashCreateCommand_messageEnterCommitMessage); + GridData data = new GridData(GridData.GRAB_HORIZONTAL + | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL + | GridData.VERTICAL_ALIGN_CENTER); + data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); + label.setLayoutData(data); + label.setFont(parent.getFont()); + + text = new Text(composite, SWT.SINGLE | SWT.BORDER); + text.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL + | GridData.HORIZONTAL_ALIGN_FILL)); + + untrackedButton = new Button(composite, SWT.CHECK); + untrackedButton + .setText(UIText.StashCreateCommand_includeUntrackedLabel); + + text.setFocus(); + return composite; + } + + protected void buttonPressed(int buttonId) { + if (buttonId == IDialogConstants.OK_ID) { + commitMessage = text.getText(); + includeUntracked = untrackedButton.getSelection(); + } else { + commitMessage = null; + includeUntracked = false; + } + super.buttonPressed(buttonId); + } + + public String getValue() { + return commitMessage; + } + + public boolean getIncludeUntracked() { + return includeUntracked; + } + + + } + } 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 8bdf8314ba..f1fa77f2b6 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 @@ -1727,6 +1727,7 @@ StagingView_MergeTool=Merge Tool StagingViewContentProvider_SubmoduleError=Unhandled exception while analyzing submodules StashApplyCommand_applyFailed=Applying stashed commit ''{0}'' failed due to ''{1}'' StashApplyCommand_jobTitle=Apply changes from stashed commit ''{0}'' +StashCreateCommand_includeUntrackedLabel=Include untracked files StashCreateCommand_jobTitle=Stashing local changes StashCreateCommand_messageEnterCommitMessage=Enter stash commit message (optional): StashCreateCommand_messageNoChanges=The repository does not contain any local changes to stash. |