Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaik Schreiber2014-03-25 12:09:14 +0000
committerMatthias Sohn2014-04-04 15:39:37 +0000
commitd6b7699ef7d5c7d31324b6e92dee55fcb96f81b0 (patch)
tree63e47906f68bca9b44471dc0b2279a39da006df9 /org.eclipse.egit.ui/src/org/eclipse/egit
parentd89162b594f98a2846184b589681d1c9b9f92d63 (diff)
downloadegit-d6b7699ef7d5c7d31324b6e92dee55fcb96f81b0.tar.gz
egit-d6b7699ef7d5c7d31324b6e92dee55fcb96f81b0.tar.xz
egit-d6b7699ef7d5c7d31324b6e92dee55fcb96f81b0.zip
Add ability to edit a commit directly from the history view.
This adds a new menu item Modify > Edit to the context menu of the history view. It can be used to edit a commit, then manually amending the commit afterwards. An error will be displayed if the selected commit cannot be reached from the current HEAD commit. This is done so as to avoid the need to checkout another commit automatically before executing the edit procedure. CQ: 8158 Bug: 431751 Change-Id: Idef404f2d712cccb862a7eb11571a7a4151badb8 Signed-off-by: Maik Schreiber <blizzy@blizzy.de> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.egit.ui/src/org/eclipse/egit')
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/JobFamilies.java5
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java21
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/command/EditHandler.java60
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitGraphTable.java6
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/EditHandler.java109
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/HistoryViewCommands.java3
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties8
7 files changed, 211 insertions, 1 deletions
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 c8088c0676..6f5210c046 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
@@ -125,6 +125,11 @@ public class JobFamilies {
public static final Object REWORD = new Object();
/**
+ * Edit commit job
+ */
+ public static final Object EDIT = new Object();
+
+ /**
* Revert commit job
*/
public static final Object REVERT_COMMIT = new Object();
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 7736c4ec3c..4ea163a053 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
@@ -571,6 +571,9 @@ public class UIText extends NLS {
public static String GitHistoryPage_rewordMenuItem;
/** */
+ public static String GitHistoryPage_editMenuItem;
+
+ /** */
public static String GitHistoryPage_SetAsBaselineMenuLabel;
/** */
@@ -5060,6 +5063,24 @@ public class UIText extends NLS {
public static String RewordHandler_JobName;
/** */
+ public static String EditHandler_JobName;
+
+ /** */
+ public static String EditHandler_CommitNotOnCurrentBranch;
+
+ /** */
+ public static String EditHandler_Error_Title;
+
+ /** */
+ public static String EditHandler_ErrorCheckingIfCommitIsOnCurrentBranch;
+
+ /** */
+ public static String EditHandler_InternalError;
+
+ /** */
+ public static String EditHandler_OpenStagingAndRebaseInteractiveViews;
+
+ /** */
public static String SynchronizeCommand_jobName;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/command/EditHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/command/EditHandler.java
new file mode 100644
index 0000000000..0f0bdff96a
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/command/EditHandler.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Maik Schreiber
+ * 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:
+ * Maik Schreiber - initial implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.commit.command;
+
+import java.text.MessageFormat;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.egit.core.internal.job.JobUtil;
+import org.eclipse.egit.core.op.EditCommitOperation;
+import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.JobFamilies;
+import org.eclipse.egit.ui.internal.UIRepositoryUtils;
+import org.eclipse.egit.ui.internal.UIText;
+import org.eclipse.egit.ui.internal.handler.SelectionHandler;
+import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.swt.widgets.Shell;
+
+/** Handler to edit an existing commit. */
+public class EditHandler extends SelectionHandler {
+
+ /** Command id */
+ public static final String ID = "org.eclipse.egit.ui.commit.Edit"; //$NON-NLS-1$
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ RevCommit commit = getSelectedItem(RevCommit.class, event);
+ if (commit == null)
+ return null;
+ Repository repo = getSelectedItem(Repository.class, event);
+ if (repo == null)
+ return null;
+
+ try {
+ Shell shell = getPart(event).getSite().getShell();
+ if (!UIRepositoryUtils.handleUncommittedFiles(repo, shell))
+ return null;
+ } catch (GitAPIException e) {
+ Activator.logError(e.getMessage(), e);
+ return null;
+ }
+
+ final EditCommitOperation op = new EditCommitOperation(repo, commit);
+
+ JobUtil.scheduleUserWorkspaceJob(
+ op,
+ MessageFormat.format(UIText.EditHandler_JobName, commit.name()),
+ JobFamilies.EDIT);
+ return null;
+ }
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitGraphTable.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitGraphTable.java
index 152e138ece..d2f1b8f3b9 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitGraphTable.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitGraphTable.java
@@ -890,10 +890,14 @@ class CommitGraphTable {
popupMgr.add(modifyManager);
- if (selectionSize == 1)
+ if (selectionSize == 1) {
modifyManager.add(getCommandContributionItem(
HistoryViewCommands.REWORD,
UIText.GitHistoryPage_rewordMenuItem));
+ modifyManager.add(getCommandContributionItem(
+ HistoryViewCommands.EDIT,
+ UIText.GitHistoryPage_editMenuItem));
+ }
if (selectionSize >= 2)
modifyManager.add(getCommandContributionItem(
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/EditHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/EditHandler.java
new file mode 100644
index 0000000000..d4398170ec
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/EditHandler.java
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Maik Schreiber
+ * 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:
+ * Maik Schreiber - initial implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.history.command;
+
+import java.io.IOException;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.egit.core.CommitUtil;
+import org.eclipse.egit.core.internal.job.RuleUtil;
+import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.internal.CommonUtils;
+import org.eclipse.egit.ui.internal.UIText;
+import org.eclipse.egit.ui.internal.commit.RepositoryCommit;
+import org.eclipse.egit.ui.internal.history.GitHistoryPage;
+import org.eclipse.egit.ui.internal.rebase.RebaseInteractiveView;
+import org.eclipse.egit.ui.internal.staging.StagingView;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.RepositoryState;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.progress.UIJob;
+
+/** Checks out a commit (in interactive rebase mode) for editing. */
+public class EditHandler extends AbstractHistoryCommandHandler {
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ final Repository repository = getRepository(event);
+ final RevCommit commit = (RevCommit) getSelection(getPage())
+ .getFirstElement();
+
+ try {
+ if (!CommitUtil.isCommitInCurrentBranch(commit, repository)) {
+ MessageDialog.openError(getPage().getSite().getShell(),
+ UIText.EditHandler_Error_Title,
+ UIText.EditHandler_CommitNotOnCurrentBranch);
+ return null;
+ }
+ } catch (IOException e) {
+ throw new ExecutionException(
+ UIText.EditHandler_ErrorCheckingIfCommitIsOnCurrentBranch,
+ e);
+ }
+
+ final IStructuredSelection selected = new StructuredSelection(
+ new RepositoryCommit(repository, commit));
+ CommonUtils.runCommand(
+ org.eclipse.egit.ui.internal.commit.command.EditHandler.ID,
+ selected);
+ openStagingAndRebaseInteractiveViews(repository);
+
+ return null;
+ }
+
+ private void openStagingAndRebaseInteractiveViews(final Repository repository) {
+ Job job = new UIJob(UIText.EditHandler_OpenStagingAndRebaseInteractiveViews) {
+ @Override
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ try {
+ IWorkbenchPage workbenchPage = getPage().getSite()
+ .getPage();
+ final StagingView stagingView = (StagingView) workbenchPage
+ .showView(StagingView.VIEW_ID);
+ stagingView.setAmending(true);
+ stagingView.reload(repository);
+ RebaseInteractiveView rebaseView = (RebaseInteractiveView) workbenchPage
+ .showView(RebaseInteractiveView.VIEW_ID);
+ rebaseView.setInput(repository);
+ } catch (PartInitException e) {
+ Activator.logError(e.getMessage(), e);
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ job.setRule(RuleUtil.getRule(repository));
+ job.setUser(true);
+ job.schedule();
+ }
+
+ @Override
+ public boolean isEnabled() {
+ GitHistoryPage page = getPage();
+ if (page == null)
+ return false;
+ IStructuredSelection selection = getSelection(page);
+ if (selection.size() != 1)
+ return false;
+ Repository repository = getRepository(page);
+ if (repository.getRepositoryState() != RepositoryState.SAFE)
+ return false;
+ RevCommit commit = (RevCommit) selection.getFirstElement();
+ return (commit.getParentCount() == 1);
+ }
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/HistoryViewCommands.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/HistoryViewCommands.java
index 216b44e2b4..1bfb850846 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/HistoryViewCommands.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/HistoryViewCommands.java
@@ -83,6 +83,9 @@ public class HistoryViewCommands {
/** reword a commit's message */
public static final String REWORD = "org.eclipse.egit.ui.history.Reword"; //$NON-NLS-1$
+ /** edit an existing commit */
+ public static final String EDIT = "org.eclipse.egit.ui.history.Edit"; //$NON-NLS-1$
+
/** revert a commit */
public static final String REVERT = "org.eclipse.egit.ui.history.Revert"; //$NON-NLS-1$
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 3f57b516ed..338b50add9 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
@@ -204,6 +204,7 @@ GitHistoryPage_mergeMenuItem=Merge
GitHistoryPage_rebaseMenuItem=Rebase on
GitHistoryPage_rebaseInteractiveMenuItem=Rebase Interactive
GitHistoryPage_rewordMenuItem=Reword
+GitHistoryPage_editMenuItem=Edit
GitHistoryPage_SetAsBaselineMenuLabel=&Set as Baseline
GitHistoryPage_ShowAdditionalRefsMenuLabel=&Additional Refs
GitHistoryPage_ShowAllBranchesMenuLabel=All &Branches and Tags
@@ -1780,6 +1781,13 @@ RewordHandler_ErrorCheckingIfCommitIsOnCurrentBranch=Error checking if commit is
RewordHandler_InternalError=An internal error occurred
RewordHandler_JobName=Rewording Commit {0}
+EditHandler_CommitNotOnCurrentBranch=The selected commit cannot be edited because it is not on the currently checked-out branch.
+EditHandler_Error_Title=Error Editing Commit
+EditHandler_ErrorCheckingIfCommitIsOnCurrentBranch=Error checking if commit is on current branch
+EditHandler_InternalError=An internal error occurred
+EditHandler_JobName=Editing Commit {0}
+EditHandler_OpenStagingAndRebaseInteractiveViews=Open Staging and Interactive Rebase Views
+
GitModelSynchronizeParticipant_initialScopeName=Git
GitModelSynchronizeParticipant_noCachedSourceVariant=Could not locate cached source variant for resource: {0}

Back to the top