summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorTomasz Zarna2012-04-18 19:33:26 (EDT)
committer Matthias Sohn2012-04-18 19:33:51 (EDT)
commit878e2622d0df5087c6a2f47ae795bc9748f56509 (patch)
tree651cecf70f311ce29f576c99caaf6eeabcffb842
parent48d06a026afa1921412560b42127667fe5a3c23a (diff)
downloadegit-878e2622d0df5087c6a2f47ae795bc9748f56509.zip
egit-878e2622d0df5087c6a2f47ae795bc9748f56509.tar.gz
egit-878e2622d0df5087c6a2f47ae795bc9748f56509.tar.bz2
Create Patch on staged file brokenrefs/changes/45/5545/5
The patch wizard should open if the selection contains a modified, untracked or missing file. Otherwise, the "No changes" dialog should be shown. The fix utilizes IndexDiffCache to achieve that. Bug: 376187 Change-Id: I7dd7358dfc1b2a05fcbd6dec24bc819d96d31c4f Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java29
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CreatePatchActionTest.java14
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/patch/PatchOperationUI.java49
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties2
4 files changed, 78 insertions, 16 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java
index 0148f53..c3c151d 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java
@@ -31,6 +31,7 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
import org.eclipse.egit.core.Activator;
import org.eclipse.egit.core.RepositoryCache;
+import org.eclipse.egit.core.op.AddToIndexOperation;
import org.eclipse.egit.core.op.CloneOperation;
import org.eclipse.egit.core.op.CommitOperation;
import org.eclipse.egit.core.op.ConnectProviderOperation;
@@ -458,17 +459,41 @@ public abstract class LocalRepositoryTestCase extends EGitTestCase {
* @throws Exception
*/
protected static IFile touch(final String newContent) throws Exception {
+ return touch(PROJ1, "folder/test.txt", newContent);
+ }
+
+ /**
+ * Modify the specified file with the given content.
+ *
+ * @param projectName
+ * project name
+ * @param filePath
+ * file path under the given project
+ * @param newContent
+ * new file content
+ * @return the modified file
+ * @throws Exception
+ */
+ protected static IFile touch(String projectName, String filePath,
+ String newContent) throws Exception {
IProject prj = ResourcesPlugin.getWorkspace().getRoot()
- .getProject(PROJ1);
+ .getProject(projectName);
if (!prj.isAccessible())
throw new IllegalStateException("No project to touch");
- IFile file = prj.getFile(new Path("folder/test.txt"));
+ IFile file = prj.getFile(new Path(filePath));
file.setContents(
new ByteArrayInputStream(newContent.getBytes(prj
.getDefaultCharset())), 0, null);
return file;
}
+ protected static void stage(IFile file) throws Exception {
+ ArrayList<IFile> unstaged = new ArrayList<IFile>();
+ unstaged.addAll(Arrays.asList(new IFile[] { file }));
+ AddToIndexOperation op = new AddToIndexOperation(unstaged);
+ op.execute(null);
+ }
+
protected static void addAndCommit(IFile file, String commitMessage)
throws Exception {
IProject prj = file.getProject();
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CreatePatchActionTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CreatePatchActionTest.java
index ff48bf8..5462212 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CreatePatchActionTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CreatePatchActionTest.java
@@ -171,6 +171,20 @@ public class CreatePatchActionTest extends LocalRepositoryTestCase {
}
@Test
+ public void testNoChangesInSelection() throws Exception {
+ IFile fileToStage = touch(PROJ1, "folder/test.txt", "new content in "
+ + PROJ1);
+ stage(fileToStage);
+ touch(PROJ2, "folder/test.txt", "new content in " + PROJ2);
+
+ CreatePatchWizard.openWizard(PROJ1);
+
+ NoChangesPopup popup = new NoChangesPopup(
+ bot.shell(UIText.GitCreatePatchAction_cannotCreatePatch));
+ popup.cancelPopup();
+ }
+
+ @Test
public void testClipboard() throws Exception {
touchAndSubmit("oldContent", null);
touch("newContent");
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/patch/PatchOperationUI.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/patch/PatchOperationUI.java
index 9ba4c0f..b8fd95c 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/patch/PatchOperationUI.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/patch/PatchOperationUI.java
@@ -8,15 +8,18 @@
*******************************************************************************/
package org.eclipse.egit.ui.internal.patch;
+import static org.eclipse.jgit.lib.Repository.stripWorkDir;
+
import java.util.Collection;
+import java.util.Set;
import org.eclipse.core.resources.IResource;
+import org.eclipse.egit.core.internal.indexdiff.IndexDiffCache;
+import org.eclipse.egit.core.internal.indexdiff.IndexDiffData;
import org.eclipse.egit.core.op.CreatePatchOperation;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.internal.history.GitCreatePatchWizard;
import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jgit.api.Git;
-import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.swt.widgets.Shell;
@@ -104,21 +107,41 @@ public class PatchOperationUI {
}
private boolean isWorkingTreeClean() {
- Git git = new Git(repository);
- try {
- Status status = git.status().call();
- return status.getModified().isEmpty()
- && status.getUntracked().isEmpty()
- && status.getMissing().isEmpty();
- } catch (Exception e) {
- MessageDialog.openError(getShell(),
- UIText.GitCreatePatchAction_cannotCreatePatch, e
- .getMessage() == null ? e.getMessage()
- : UIText.GitCreatePatchWizard_InternalError);
+ IndexDiffCache diffCache = org.eclipse.egit.core.Activator.getDefault()
+ .getIndexDiffCache();
+ if (diffCache != null) {
+ IndexDiffData diffData = diffCache.getIndexDiffCacheEntry(
+ repository).getIndexDiff();
+ if (diffData != null) {
+ Set<String> modified = diffData.getModified();
+ Set<String> untracked = diffData.getUntracked();
+ Set<String> missing = diffData.getMissing();
+ for (IResource resource : resources) {
+ String repoRelativePath = makeRepoRelative(resource);
+ if (containsPrefix(modified, repoRelativePath))
+ return false;
+ if (containsPrefix(untracked, repoRelativePath))
+ return false;
+ if (containsPrefix(missing, repoRelativePath))
+ return false;
+ }
+ }
}
return true;
}
+ private String makeRepoRelative(IResource res) {
+ return stripWorkDir(repository.getWorkTree(), res.getLocation()
+ .toFile());
+ }
+
+ private boolean containsPrefix(Set<String> collection, String prefix) {
+ for (String path : collection)
+ if (path.startsWith(prefix))
+ return true;
+ return false;
+ }
+
private Shell getShell() {
return getShell(part);
}
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 b9022cb..5340436 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
@@ -1044,7 +1044,7 @@ GitCreateGeneralProjectPage_FileNotDirMessage=File {0} is not a directory
GitCreateGeneralProjectPage_PorjectAlreadyExistsMessage=Project {0} already exists
GitCreateGeneralProjectPage_ProjectNameLabel=Project name
GitCreatePatchAction_cannotCreatePatch=Cannot create patch
-GitCreatePatchAction_workingTreeClean=There are no changes in working tree
+GitCreatePatchAction_workingTreeClean=There are no changes in working tree for the current selection
GitCreatePatchWizard_Browse=B&rowse...
GitCreatePatchWizard_Clipboard=&Clipboard
GitCreatePatchWizard_ContextMustBePositiveInt=Context must be a valid number of lines ( >= 0 )