aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-05-05 20:59:09 (EDT)
committerChris Aniszczyk2011-05-06 10:26:30 (EDT)
commitf15d35db7742d9a3f8f5492e0d66ebbd5e0962a5 (patch)
treeee424eb6db51c1cbbe0f95b7937136861f93e8df
parentb333d83ef50cec2673e72adc3c5f3c4238b70591 (diff)
downloadegit-f15d35db7742d9a3f8f5492e0d66ebbd5e0962a5.zip
egit-f15d35db7742d9a3f8f5492e0d66ebbd5e0962a5.tar.gz
egit-f15d35db7742d9a3f8f5492e0d66ebbd5e0962a5.tar.bz2
Add Replace With HEAD, commit, and ref menu actionsrefs/changes/49/3349/8
Bug: 326638 Change-Id: I0beef8da40c8e0c194f61678000f0b65bd6598b9 Signed-off-by: Kevin Sawicki <kevin@github.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/op/DiscardChangesOperation.java46
-rw-r--r--org.eclipse.egit.ui/plugin.properties6
-rw-r--r--org.eclipse.egit.ui/plugin.xml33
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ActionCommands.java9
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/DiscardChangesActionHandler.java19
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithCommitAction.java24
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithCommitActionHandler.java33
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithHeadAction.java24
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithHeadActionHandler.java30
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithRefAction.java24
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithRefActionHandler.java37
11 files changed, 263 insertions, 22 deletions
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/DiscardChangesOperation.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/DiscardChangesOperation.java
index 38e2f26..e1432ec 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/DiscardChangesOperation.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/DiscardChangesOperation.java
@@ -12,8 +12,6 @@
*******************************************************************************/
package org.eclipse.egit.core.op;
-import java.io.File;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -35,19 +33,21 @@ import org.eclipse.egit.core.Activator;
import org.eclipse.egit.core.CoreText;
import org.eclipse.egit.core.internal.util.ProjectUtil;
import org.eclipse.egit.core.project.RepositoryMapping;
-import org.eclipse.jgit.dircache.DirCache;
-import org.eclipse.jgit.dircache.DirCacheCheckout;
-import org.eclipse.jgit.dircache.DirCacheEntry;
+import org.eclipse.jgit.api.CheckoutCommand;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.osgi.util.NLS;
/**
* The operation discards changes on a set of resources. In case of a folder
- * resource all file resources in the sub tree are processed.
- * Untracked files are ignored.
+ * resource all file resources in the sub tree are processed. Untracked files
+ * are ignored.
*/
public class DiscardChangesOperation implements IEGitOperation {
+ String revision;
+
IResource[] files;
ISchedulingRule schedulingRule;
@@ -58,12 +58,25 @@ public class DiscardChangesOperation implements IEGitOperation {
* @param files
*/
public DiscardChangesOperation(IResource[] files) {
+ this(files, null);
+ }
+
+ /**
+ * Construct a {@link DiscardChangesOperation} object.
+ *
+ * @param files
+ * @param revision
+ */
+ public DiscardChangesOperation(IResource[] files, String revision) {
this.files = new IResource[files.length];
System.arraycopy(files, 0, this.files, 0, files.length);
+ this.revision = revision;
schedulingRule = calcRefreshRule(files);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.eclipse.egit.core.op.IEGitOperation#getSchedulingRule()
*/
public ISchedulingRule getSchedulingRule() {
@@ -117,7 +130,7 @@ public class DiscardChangesOperation implements IEGitOperation {
}
try {
discardChange(res, repo);
- } catch (IOException e) {
+ } catch (GitAPIException e) {
errorOccurred = true;
String message = NLS.bind(
CoreText.DiscardChangesOperation_discardFailed, res
@@ -154,19 +167,12 @@ public class DiscardChangesOperation implements IEGitOperation {
}
private void discardChange(IResource res, Repository repository)
- throws IOException {
+ throws GitAPIException {
String resRelPath = RepositoryMapping.getMapping(res)
.getRepoRelativePath(res);
- DirCache dc = repository.lockDirCache();
- try {
- DirCacheEntry entry = dc.getEntry(resRelPath);
- if (entry != null) {
- File file = new File(res.getLocationURI());
- DirCacheCheckout.checkoutEntry(repository, file, entry);
- }
- } finally {
- dc.unlock();
- }
+ CheckoutCommand co = new Git(repository).checkout().addPath(resRelPath);
+ co.setStartPoint(this.revision);
+ co.call();
}
/**
diff --git a/org.eclipse.egit.ui/plugin.properties b/org.eclipse.egit.ui/plugin.properties
index 11de2f7..77206c4 100644
--- a/org.eclipse.egit.ui/plugin.properties
+++ b/org.eclipse.egit.ui/plugin.properties
@@ -29,6 +29,9 @@ AddToIndexAction_tooltip=Add to Git Index
BranchAction_label=&Switch to ...
BranchAction_tooltip=Checkout branch, tag or Reference
DiscardChangesAction_label=&File in Git Index
+ReplaceWithHeadAction_label=&HEAD Revision
+ReplaceWithCommitAction_label=Commit...
+ReplaceWithRefAction_label=&Branch, Tag, or Reference...
FetchAction_label=&Fetch From...
FetchAction_tooltip=Fetch changes from upstream
PushAction_label=&Push...
@@ -190,6 +193,9 @@ CompareWithHeadCommand.name = Compare with HEAD Revision
CompareWithHistoryCommand.name = Compare with History
CompareWithIndexCommand.name = Compare with Git Index
ReplaceWithIndexCommand.name = Replace with File in Git Index
+ReplaceWithHeadCommand.name = Replace with HEAD revision
+ReplaceWithCommitCommand.name = Replace with commit
+ReplaceWithRefCommand.name = Replace with branch, tag, or reference
FetchCommand.name = Fetch
IgnoreCommand.name = Ignore
MergeCommand.name = Merge
diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml
index 7c67357..f750c6d 100644
--- a/org.eclipse.egit.ui/plugin.xml
+++ b/org.eclipse.egit.ui/plugin.xml
@@ -148,6 +148,21 @@
label="%DiscardChangesAction_label"
menubarPath="replaceWithMenu/gitReplaceWithGroup"/>
<action
+ class="org.eclipse.egit.ui.internal.actions.ReplaceWithRefAction"
+ id="org.eclipse.egit.ui.internal.actions.ReplaceWithRefAction"
+ label="%ReplaceWithRefAction_label"
+ menubarPath="replaceWithMenu/gitReplaceWithGroup"/>
+ <action
+ class="org.eclipse.egit.ui.internal.actions.ReplaceWithHeadAction"
+ id="org.eclipse.egit.ui.internal.actions.ReplaceWithHeadAction"
+ label="%ReplaceWithHeadAction_label"
+ menubarPath="replaceWithMenu/gitReplaceWithGroup"/>
+ <action
+ class="org.eclipse.egit.ui.internal.actions.ReplaceWithCommitAction"
+ id="org.eclipse.egit.ui.internal.actions.ReplaceWithCommitAction"
+ label="%ReplaceWithCommitAction_label"
+ menubarPath="replaceWithMenu/gitReplaceWithGroup"/>
+ <action
class="org.eclipse.egit.ui.internal.actions.ApplyPatchAction"
definitionId="org.eclipse.egit.ui.team.ApplyPatch"
enablesFor="*"
@@ -3244,6 +3259,24 @@
id="org.eclipse.egit.ui.team.Discard"
name="%ReplaceWithIndexCommand.name">
</command>
+ <command
+ categoryId="org.eclipse.egit.ui.commandCategory"
+ defaultHandler="org.eclipse.egit.ui.internal.actions.ReplaceWithHeadActionHandler"
+ id="org.eclipse.egit.ui.team.ReplaceWithHead"
+ name="%ReplaceWithHeadCommand.name">
+ </command>
+ <command
+ categoryId="org.eclipse.egit.ui.commandCategory"
+ defaultHandler="org.eclipse.egit.ui.internal.actions.ReplaceWithCommitActionHandler"
+ id="org.eclipse.egit.ui.team.ReplaceWithCommit"
+ name="%ReplaceWithCommitCommand.name">
+ </command>
+ <command
+ categoryId="org.eclipse.egit.ui.commandCategory"
+ defaultHandler="org.eclipse.egit.ui.internal.actions.ReplaceWithRefActionHandler"
+ id="org.eclipse.egit.ui.team.ReplaceWithRef"
+ name="%ReplaceWithRefCommand.name">
+ </command>
<command
categoryId="org.eclipse.egit.ui.commandCategory"
defaultHandler="org.eclipse.egit.ui.internal.actions.IgnoreActionHandler"
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ActionCommands.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ActionCommands.java
index 6d4b5b5..1f657ae 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ActionCommands.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ActionCommands.java
@@ -56,6 +56,15 @@ public class ActionCommands {
/** "Discard changes" action command id */
public static final String DISCARD_CHANGES_ACTION = "org.eclipse.egit.ui.team.Discard"; //$NON-NLS-1$
+ /** "Replace with HEAD" action command id */
+ public static final String REPLACE_WITH_HEAD_ACTION = "org.eclipse.egit.ui.team.ReplaceWithHead"; //$NON-NLS-1$
+
+ /** "Replace with Commit" action command id */
+ public static final String REPLACE_WITH_COMMIT_ACTION = "org.eclipse.egit.ui.team.ReplaceWithCommit"; //$NON-NLS-1$
+
+ /** "Replace with Ref" action command id */
+ public static final String REPLACE_WITH_REF_ACTION = "org.eclipse.egit.ui.team.ReplaceWithRef"; //$NON-NLS-1$
+
/** "Disconnect" action command id */
public static final String DISCONNECT_ACTION = "org.eclipse.egit.ui.internal.actions.Disconnect"; //$NON-NLS-1$
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/DiscardChangesActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/DiscardChangesActionHandler.java
index c892ead..a03e9a4 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/DiscardChangesActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/DiscardChangesActionHandler.java
@@ -36,8 +36,9 @@ public class DiscardChangesActionHandler extends RepositoryActionHandler {
UIText.DiscardChangesAction_confirmActionMessage);
if (!performAction)
return null;
- final DiscardChangesOperation operation = new DiscardChangesOperation(
- getSelectedResources(event));
+ final DiscardChangesOperation operation = createOperation(event);
+ if (operation == null)
+ return null;
String jobname = UIText.DiscardChangesAction_discardChanges;
Job job = new Job(jobname) {
@Override
@@ -72,4 +73,18 @@ public class DiscardChangesActionHandler extends RepositoryActionHandler {
return true;
}
+ /**
+ * Create discard operation to execute. Returning a null operation aborts
+ * this execution of this handler.
+ *
+ * @param event
+ * @return revision
+ * @throws ExecutionException
+ */
+ protected DiscardChangesOperation createOperation(ExecutionEvent event)
+ throws ExecutionException {
+ return new DiscardChangesOperation(getSelectedResources(event), null);
+
+ }
+
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithCommitAction.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithCommitAction.java
new file mode 100644
index 0000000..d3fc4e5
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithCommitAction.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2011 GitHub Inc.
+ * 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
+ *
+ * Contributors:
+ * Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.actions;
+
+/**
+ * Replace with Commit action
+ */
+public class ReplaceWithCommitAction extends RepositoryAction {
+
+ /** Create action */
+ public ReplaceWithCommitAction() {
+ super(ActionCommands.REPLACE_WITH_COMMIT_ACTION,
+ new ReplaceWithCommitActionHandler());
+ }
+
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithCommitActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithCommitActionHandler.java
new file mode 100644
index 0000000..9b92d27
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithCommitActionHandler.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2011 GitHub Inc.
+ * 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
+ *
+ * Contributors:
+ * Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.actions;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.egit.core.op.DiscardChangesOperation;
+import org.eclipse.egit.ui.internal.history.CommitSelectionDialog;
+import org.eclipse.jface.window.Window;
+
+/**
+ * Replace with commit action handler
+ */
+public class ReplaceWithCommitActionHandler extends DiscardChangesActionHandler {
+
+ @Override
+ protected DiscardChangesOperation createOperation(ExecutionEvent event)
+ throws ExecutionException {
+ CommitSelectionDialog dlg = new CommitSelectionDialog(getShell(event),
+ getRepository(true, event));
+ return dlg.open() == Window.OK ? new DiscardChangesOperation(
+ getSelectedResources(event), dlg.getCommitId().name()) : null;
+ }
+
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithHeadAction.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithHeadAction.java
new file mode 100644
index 0000000..92a5f55
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithHeadAction.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2011 GitHub Inc.
+ * 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
+ *
+ * Contributors:
+ * Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.actions;
+
+/**
+ * Replace with HEAD revision action
+ */
+public class ReplaceWithHeadAction extends RepositoryAction {
+
+ /** Create action */
+ public ReplaceWithHeadAction() {
+ super(ActionCommands.REPLACE_WITH_HEAD_ACTION,
+ new ReplaceWithHeadActionHandler());
+ }
+
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithHeadActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithHeadActionHandler.java
new file mode 100644
index 0000000..5f76c33
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithHeadActionHandler.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2011 GitHub Inc.
+ * 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
+ *
+ * Contributors:
+ * Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.actions;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.egit.core.op.DiscardChangesOperation;
+import org.eclipse.jgit.lib.Constants;
+
+/**
+ * Replace with HEAD revision action handler
+ */
+public class ReplaceWithHeadActionHandler extends DiscardChangesActionHandler {
+
+ @Override
+ protected DiscardChangesOperation createOperation(ExecutionEvent event)
+ throws ExecutionException {
+ return new DiscardChangesOperation(getSelectedResources(event),
+ Constants.HEAD);
+ }
+
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithRefAction.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithRefAction.java
new file mode 100644
index 0000000..6f0771a
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithRefAction.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2011 GitHub Inc.
+ * 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
+ *
+ * Contributors:
+ * Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.actions;
+
+/**
+ * Replace with reference action
+ */
+public class ReplaceWithRefAction extends RepositoryAction {
+
+ /** Create action */
+ public ReplaceWithRefAction() {
+ super(ActionCommands.REPLACE_WITH_REF_ACTION,
+ new ReplaceWithRefActionHandler());
+ }
+
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithRefActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithRefActionHandler.java
new file mode 100644
index 0000000..086a9ab
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ReplaceWithRefActionHandler.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2011 GitHub Inc.
+ * 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
+ *
+ * Contributors:
+ * Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.actions;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.egit.core.op.DiscardChangesOperation;
+import org.eclipse.egit.ui.internal.dialogs.CompareTargetSelectionDialog;
+import org.eclipse.jface.window.Window;
+
+/**
+ * Replace with ref action handler
+ */
+public class ReplaceWithRefActionHandler extends DiscardChangesActionHandler {
+
+ @Override
+ protected DiscardChangesOperation createOperation(ExecutionEvent event)
+ throws ExecutionException {
+ final IResource[] resources = getSelectedResources(event);
+ CompareTargetSelectionDialog dlg = new CompareTargetSelectionDialog(
+ getShell(event), getRepository(true, event),
+ resources.length == 1 ? resources[0].getFullPath().toString()
+ : null);
+ return dlg.open() == Window.OK ? new DiscardChangesOperation(resources,
+ dlg.getRefName()) : null;
+ }
+
+}