diff options
author | Thomas Wolf | 2018-04-03 09:42:16 +0000 |
---|---|---|
committer | Thomas Wolf | 2018-05-12 21:56:29 +0000 |
commit | a0840d3207f922189e6baf7abc03606fe1f5e9c4 (patch) | |
tree | 3dda526adeefd78beaf213f1068fdbfde51c9951 /org.eclipse.egit.ui/src/org/eclipse/egit/ui | |
parent | aeb507087b4d9416cd76ec5f1229984c6413f025 (diff) | |
download | egit-a0840d3207f922189e6baf7abc03606fe1f5e9c4.tar.gz egit-a0840d3207f922189e6baf7abc03606fe1f5e9c4.tar.xz egit-a0840d3207f922189e6baf7abc03606fe1f5e9c4.zip |
Allow cherry-picking merge commits
If the commit to be cherry-picked is a merge commit, ask the user to
choose the parent commit to define the changes to be applied. Then
pass on the chosen parent (index) to JGit's CherryPickCommand.
Bug: 531953
Change-Id: I1d9eb551d6db5ad39a4a5d96a0196cfd3f4f4e95
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui/src/org/eclipse/egit/ui')
4 files changed, 90 insertions, 16 deletions
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 f756b82360..57404310e8 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 @@ -1220,6 +1220,9 @@ public class UIText extends NLS { public static String CherryPickHandler_CherryPickFailedMessage; /** */ + public static String CherryPickHandler_CherryPickMergeMessage; + + /** */ public static String CherryPickHandler_CouldNotDeleteFile; /** */ @@ -5130,6 +5133,9 @@ public class UIText extends NLS { public static String CommitSelectDialog_WindowTitle; /** */ + public static String CommitSelectDialog_ChooseParentTitle; + + /** */ public static String CommitSelectionDialog_BuildingCommitListMessage; /** */ diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/command/CherryPickHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/command/CherryPickHandler.java index 4ff37efee8..0b372c4551 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/command/CherryPickHandler.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/command/CherryPickHandler.java @@ -38,6 +38,7 @@ import org.eclipse.egit.ui.internal.UIRepositoryUtils; import org.eclipse.egit.ui.internal.UIText; import org.eclipse.egit.ui.internal.branch.LaunchFinder; import org.eclipse.egit.ui.internal.commit.RepositoryCommit; +import org.eclipse.egit.ui.internal.dialogs.CommitSelectDialog; import org.eclipse.egit.ui.internal.handler.SelectionHandler; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; @@ -74,18 +75,46 @@ public class CherryPickHandler extends SelectionHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { RevCommit commit = getSelectedItem(RevCommit.class, event); - if (commit == null) + if (commit == null) { return null; + } Repository repo = getSelectedItem(Repository.class, event); - if (repo == null) + if (repo == null) { return null; - final Shell parent = getPart(event).getSite().getShell(); + } + final Shell shell = getPart(event).getSite().getShell(); - if (!confirmCherryPick(parent, repo, commit)) + int parentIndex = -1; + if (commit.getParentCount() > 1) { + // Merge commit: select parent + List<RevCommit> parents = new ArrayList<>(); + String branch = null; + try { + for (RevCommit parent : commit.getParents()) { + parents.add(repo.parseCommit(parent)); + } + branch = repo.getBranch(); + } catch (Exception e) { + Activator.handleError(e.getLocalizedMessage(), e, true); + return null; + } + CommitSelectDialog selectCommit = new CommitSelectDialog(shell, + parents, getLaunchMessage(repo)); + selectCommit.create(); + selectCommit.setTitle(UIText.CommitSelectDialog_ChooseParentTitle); + selectCommit.setMessage(MessageFormat.format( + UIText.CherryPickHandler_CherryPickMergeMessage, + commit.abbreviate(7).name(), branch)); + if (selectCommit.open() != Window.OK) { + return null; + } + parentIndex = parents.indexOf(selectCommit.getSelectedCommit()); + } else if (!confirmCherryPick(shell, repo, commit)) { return null; + } try { - if (!UIRepositoryUtils.handleUncommittedFiles(repo, parent)) + if (!UIRepositoryUtils.handleUncommittedFiles(repo, shell)) return null; } catch (GitAPIException e) { Activator.logError(e.getMessage(), e); @@ -93,6 +122,8 @@ public class CherryPickHandler extends SelectionHandler { } final CherryPickOperation op = new CherryPickOperation(repo, commit); + op.setMainlineIndex(parentIndex); + Job job = new Job(MessageFormat.format( UIText.CherryPickHandler_JobName, Integer.valueOf(1))) { @Override @@ -102,13 +133,15 @@ public class CherryPickHandler extends SelectionHandler { CherryPickResult cherryPickResult = op.getResult(); RevCommit newHead = cherryPickResult.getNewHead(); if (newHead != null - && cherryPickResult.getCherryPickedRefs().isEmpty()) - showNotPerformedDialog(parent); + && cherryPickResult.getCherryPickedRefs() + .isEmpty()) { + showNotPerformedDialog(shell); + } if (newHead == null) { CherryPickStatus status = cherryPickResult.getStatus(); switch (status) { case CONFLICTING: - showConflictDialog(parent); + showConflictDialog(shell); break; case FAILED: showFailure(cherryPickResult); @@ -126,8 +159,9 @@ public class CherryPickHandler extends SelectionHandler { @Override public boolean belongsTo(Object family) { - if (JobFamilies.CHERRY_PICK.equals(family)) + if (JobFamilies.CHERRY_PICK.equals(family)) { return true; + } return super.belongsTo(family); } }; @@ -137,6 +171,17 @@ public class CherryPickHandler extends SelectionHandler { return null; } + private String getLaunchMessage(Repository repository) { + ILaunchConfiguration launch = LaunchFinder + .getRunningLaunchConfiguration( + Collections.singleton(repository), null); + if (launch != null) { + return MessageFormat.format( + UIText.LaunchFinder_RunningLaunchMessage, launch.getName()); + } + return null; + } + private boolean confirmCherryPick(final Shell shell, final Repository repository, final RevCommit commit) throws ExecutionException { @@ -151,12 +196,9 @@ public class CherryPickHandler extends SelectionHandler { "Exception obtaining current repository branch", e); //$NON-NLS-1$ } - ILaunchConfiguration launch = LaunchFinder - .getRunningLaunchConfiguration( - Collections.singleton(repository), null); - if (launch != null) { - message += "\n\n" + MessageFormat.format( //$NON-NLS-1$ - UIText.LaunchFinder_RunningLaunchMessage, launch.getName()); + String launchMessage = getLaunchMessage(repository); + if (launchMessage != null) { + message += "\n\n" + launchMessage; //$NON-NLS-1$ } final String question = message; shell.getDisplay().syncExec(new Runnable() { diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitSelectDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitSelectDialog.java index bed04c36e3..ab122d1ae0 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitSelectDialog.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitSelectDialog.java @@ -29,6 +29,7 @@ import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; @@ -40,6 +41,8 @@ import org.eclipse.swt.widgets.TableColumn; public class CommitSelectDialog extends TitleAreaDialog { private final List<RevCommit> commits = new ArrayList<>(); + private final String message; + private RevCommit selected; /** @@ -47,10 +50,26 @@ public class CommitSelectDialog extends TitleAreaDialog { * @param commits **/ public CommitSelectDialog(Shell parent, List<RevCommit> commits) { + this(parent, commits, null); + } + + /** + * Creates a new {@link CommitSelectDialog} instance. + * + * @param parent + * {@link Shell} to use as parent for the dialog + * @param commits + * to display + * @param message + * to display + */ + public CommitSelectDialog(Shell parent, List<RevCommit> commits, + String message) { super(parent); setShellStyle(getShellStyle() | SWT.SHELL_TRIM); this.commits.addAll(commits); setHelpAvailable(false); + this.message = message; } /** @@ -111,6 +130,11 @@ public class CommitSelectDialog extends TitleAreaDialog { okPressed(); } }); + if (message != null) { + Label label = new Label(main, SWT.LEFT | SWT.WRAP); + GridDataFactory.fillDefaults().grab(true, false).applyTo(label); + label.setText(message); + } return main; } 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 1c83f67f1a..6c6f3a20cc 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 @@ -291,6 +291,7 @@ CherryPickHandler_NoCherryPickPerformedTitle=No cherry-pick performed CherryPickHandler_CherryPickConflictsMessage=Cherry-pick could not be completed automatically because of conflicts. Please resolve and commit. CherryPickHandler_CherryPickConflictsTitle=Cherry-Pick Conflicts CherryPickHandler_CherryPickFailedMessage=Cherry-pick failed +CherryPickHandler_CherryPickMergeMessage=Cherry-picking merge commit {0} onto branch {1}. Select the parent commit to define which changes are to be cherry-picked. CherryPickHandler_CouldNotDeleteFile=Could not delete file CherryPickHandler_ErrorMsgTemplate={0} {1} CherryPickHandler_IndexDirty=Index is dirty @@ -1617,10 +1618,11 @@ CommitSearchResult_LabelSingle=''{0}'' - 1 commit match CommitSelectDialog_AuthoColumn=Author CommitSelectDialog_DateColumn=Date CommitSelectDialog_IdColumn=Id -CommitSelectDialog_Message=Please select a Commit +CommitSelectDialog_Message=Please select a commit CommitSelectDialog_MessageColumn=Message CommitSelectDialog_Title=Commit Selection CommitSelectDialog_WindowTitle=Commit Selection +CommitSelectDialog_ChooseParentTitle=Choose Parent Commit CommitSelectionDialog_BuildingCommitListMessage=Building commit list CommitSelectionDialog_DialogMessage=Please select a commit from the list CommitSelectionDialog_DialogTitle={0} commits in repository {1} |