summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorMaik Schreiber2012-04-30 18:02:42 (EDT)
committer Matthias Sohn2012-04-30 18:02:42 (EDT)
commit265092703aadd67f25e55f0f19e2c4a8d1e269b5 (patch)
tree08e460521e5bf685e44bf042b5e9445e72f022d4
parent45ecae45a9dd7d04a77f5cf389796e32f5d7cd56 (diff)
downloadegit-265092703aadd67f25e55f0f19e2c4a8d1e269b5.zip
egit-265092703aadd67f25e55f0f19e2c4a8d1e269b5.tar.gz
egit-265092703aadd67f25e55f0f19e2c4a8d1e269b5.tar.bz2
Allow for optional commit message for stash commits.refs/changes/50/5550/5
Bug: 376303 Change-Id: I0429edb29739e11d4e665a61fe70a5c4e1b565df Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/StashCreateOperationTest.java75
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/op/StashCreateOperation.java21
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java6
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/StashCreateCommand.java14
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties2
5 files changed, 116 insertions, 2 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
new file mode 100644
index 0000000..47a1608
--- /dev/null
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/StashCreateOperationTest.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (C) 2012, Maik Schreiber <blizzy@blizzy.de>
+ *
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.egit.core.test.op;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.eclipse.egit.core.op.StashCreateOperation;
+import org.eclipse.egit.core.test.GitTestCase;
+import org.eclipse.egit.core.test.TestRepository;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevWalk;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class StashCreateOperationTest extends GitTestCase {
+
+ TestRepository testRepository;
+
+ Repository repository;
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ gitDir = new File(project.getProject()
+ .getLocationURI().getPath(), Constants.DOT_GIT);
+ testRepository = new TestRepository(gitDir);
+ repository = testRepository.getRepository();
+ testRepository.connect(project.getProject());
+ testRepository.commit("initial commit");
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ testRepository.dispose();
+ repository = null;
+ super.tearDown();
+ }
+
+ @Test
+ public void testDefaultMessage() throws Exception {
+ testUtils.addFileToProject(project.getProject(), "foo/a.txt", "some text");
+ StashCreateOperation stashCreateOperation = new StashCreateOperation(repository);
+ stashCreateOperation.execute(null);
+
+ RevWalk revWalk = new RevWalk(repository);
+ RevCommit commit = revWalk.parseCommit(repository.resolve("stash@{0}"));
+ assertTrue(commit.getFullMessage().length() > 0);
+ }
+
+ @Test
+ public void testCustomMessage() throws Exception {
+ testUtils.addFileToProject(project.getProject(), "foo/a.txt", "some text");
+ String message = "stash message";
+ StashCreateOperation stashCreateOperation = new StashCreateOperation(repository, message);
+ stashCreateOperation.execute(null);
+
+ RevWalk revWalk = new RevWalk(repository);
+ RevCommit commit = revWalk.parseCommit(repository.resolve("stash@{0}"));
+ assertEquals(message, commit.getFullMessage());
+ }
+
+}
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 1a988f3..d278d1b 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
@@ -17,6 +17,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.StashCreateCommand;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.lib.Repository;
@@ -30,6 +31,8 @@ public class StashCreateOperation implements IEGitOperation {
private final Repository repository;
+ private final String message;
+
private RevCommit commit;
/**
@@ -38,7 +41,18 @@ public class StashCreateOperation implements IEGitOperation {
* @param repository
*/
public StashCreateOperation(final Repository repository) {
+ this(repository, null);
+ }
+
+ /**
+ * Create operation for repository
+ *
+ * @param repository
+ * @param message
+ */
+ public StashCreateOperation(final Repository repository, final String message) {
this.repository = repository;
+ this.message = message;
}
/**
@@ -55,7 +69,12 @@ public class StashCreateOperation implements IEGitOperation {
public void run(IProgressMonitor pm) throws CoreException {
try {
- commit = Git.wrap(repository).stashCreate().call();
+ StashCreateCommand command = Git.wrap(repository).stashCreate();
+ if (message != null) {
+ command.setIndexMessage(message);
+ command.setWorkingDirectoryMessage(message);
+ }
+ commit = command.call();
} catch (JGitInternalException e) {
throw new TeamException(e.getLocalizedMessage(),
e.getCause());
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 8d0e488..25f710b 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
@@ -4349,12 +4349,18 @@ public class UIText extends NLS {
public static String StashCreateCommand_jobTitle;
/** */
+ public static String StashCreateCommand_messageEnterCommitMessage;
+
+ /** */
public static String StashCreateCommand_messageNoChanges;
/** */
public static String StashCreateCommand_stashFailed;
/** */
+ public static String StashCreateCommand_titleEnterCommitMessage;
+
+ /** */
public static String StashCreateCommand_titleNoChanges;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/StashCreateCommand.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/StashCreateCommand.java
index 8c820f8..8fcf153 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/StashCreateCommand.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/StashCreateCommand.java
@@ -24,7 +24,9 @@ import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.JobFamilies;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.internal.repository.tree.RepositoryNode;
+import org.eclipse.jface.dialogs.InputDialog;
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.widgets.Shell;
@@ -49,8 +51,18 @@ public class StashCreateCommand extends
if (repo == null)
return null;
- final StashCreateOperation op = new StashCreateOperation(repo);
final Shell shell = HandlerUtil.getActiveShell(event);
+ InputDialog commitMessageDialog = new InputDialog(shell,
+ UIText.StashCreateCommand_titleEnterCommitMessage,
+ UIText.StashCreateCommand_messageEnterCommitMessage,
+ null, null);
+ if (commitMessageDialog.open() != Window.OK)
+ return null;
+ String message = commitMessageDialog.getValue();
+ if (message.length() == 0)
+ message = null;
+
+ final StashCreateOperation op = new StashCreateOperation(repo, message);
Job job = new Job(UIText.StashCreateCommand_jobTitle) {
@Override
protected IStatus run(IProgressMonitor monitor) {
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 dd04bbb..471be29 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
@@ -1515,8 +1515,10 @@ StagingViewContentProvider_SubmoduleError=Unhandled exception while analyzing su
StashApplyCommand_applyFailed=Applying stashed commit ''{0}'' failed
StashApplyCommand_jobTitle=Apply changes from stashed commit ''{0}''
StashCreateCommand_jobTitle=Stashing local changes
+StashCreateCommand_messageEnterCommitMessage=Enter stash commit message (optional):
StashCreateCommand_messageNoChanges=The repository does not contain any local changes to stash.
StashCreateCommand_stashFailed=Stash create error
+StashCreateCommand_titleEnterCommitMessage=Commit Stash
StashCreateCommand_titleNoChanges=No Changes
StashDropCommand_confirmMessage=Are you sure you want to delete stashed commit stash@'{'{0}'}'?
StashDropCommand_confirmTitle=Confirm Stashed Commit Deletion