diff options
author | Max Hohenegger | 2015-05-16 17:39:39 +0000 |
---|---|---|
committer | Matthias Sohn | 2015-05-27 00:08:21 +0000 |
commit | ef057ecf899fecd1b66dc30ee3cb18b642c81354 (patch) | |
tree | dea611026838b35b38d48ff4dcfb9774cda67df3 /org.eclipse.egit.gitflow.ui | |
parent | 4a80fc193c1f9233862f4be8c7eefe6178e030d2 (diff) | |
download | egit-ef057ecf899fecd1b66dc30ee3cb18b642c81354.tar.gz egit-ef057ecf899fecd1b66dc30ee3cb18b642c81354.tar.xz egit-ef057ecf899fecd1b66dc30ee3cb18b642c81354.zip |
[gitflow] Fix broken "start release" from commit
Bug: 468134
Change-Id: Id3e23c5093c1afd9ad3117880fbdcb9d193cacba
Signed-off-by: Max Hohenegger <eclipse@hohenegger.eu>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.egit.gitflow.ui')
8 files changed, 198 insertions, 31 deletions
diff --git a/org.eclipse.egit.gitflow.ui/META-INF/MANIFEST.MF b/org.eclipse.egit.gitflow.ui/META-INF/MANIFEST.MF index 02b66ec5e4..fdda0f31ee 100644 --- a/org.eclipse.egit.gitflow.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.egit.gitflow.ui/META-INF/MANIFEST.MF @@ -18,6 +18,7 @@ Import-Package: org.eclipse.egit.core;version="[4.0.0,4.1.0)", org.eclipse.egit.ui;version="[4.0.0,4.1.0)", org.eclipse.egit.ui.internal;version="[4.0.0,4.1.0)", org.eclipse.egit.ui.internal.branch;version="[4.0.0,4.1.0)", + org.eclipse.egit.ui.internal.history;version="[4.0.0,4.1.0)", org.eclipse.egit.ui.internal.repository.tree;version="[4.0.0,4.1.0)", org.eclipse.egit.ui.internal.selection;version="[4.0.0,4.1.0)", org.eclipse.jgit.api;version="[4.0.0,4.1.0)", diff --git a/org.eclipse.egit.gitflow.ui/plugin.xml b/org.eclipse.egit.gitflow.ui/plugin.xml index e78a9159c3..4987603aed 100644 --- a/org.eclipse.egit.gitflow.ui/plugin.xml +++ b/org.eclipse.egit.gitflow.ui/plugin.xml @@ -127,18 +127,6 @@ </command> </menu> </menuContribution> - <menuContribution - allPopups="false" - locationURI="popup:org.eclipse.egit.ui.historyPageContributions?after=additions"> - <menu - label="%TeamGitFlowMenu.name"> - <command - commandId="org.eclipse.egit.gitflow.ui.command.releaseStart" - label="%TeamGitFlowReleaseStart.name" - style="push"> - </command> - </menu> - </menuContribution> </extension> <extension point="org.eclipse.ui.commands"> @@ -615,6 +603,13 @@ <adapter type="org.eclipse.jgit.lib.Repository"/> </factory> </extension> + <extension + point="org.eclipse.core.runtime.adapters"> + <factory adaptableType="org.eclipse.team.ui.history.IHistoryView" + class="org.eclipse.egit.gitflow.ui.internal.factories.GitFlowAdapterFactory"> + <adapter type="org.eclipse.jgit.lib.Repository"/> + </factory> + </extension> <extension @@ -740,4 +735,18 @@ </command> </menuContribution> </extension> + <extension + point="org.eclipse.ui.menus"> + <menuContribution + allPopups="false" + locationURI="popup:org.eclipse.egit.ui.historyPageContributions?after=additions"> + <menu + label="%TeamGitFlowMenu.name"> + <dynamic + class="org.eclipse.egit.gitflow.ui.internal.menu.DynamicHistoryMenu" + id="org.eclipse.egit.gitflow.menu.history"> + </dynamic> + </menu> + </menuContribution> + </extension> </plugin> diff --git a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIText.java b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIText.java index a43b81d763..f3ad366e56 100644 --- a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIText.java +++ b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIText.java @@ -28,6 +28,9 @@ public class UIText extends NLS { } /** */ + public static String DynamicHistoryMenu_startGitflowReleaseFrom; + + /** */ public static String FeatureFinishHandler_finishingFeature; /** */ diff --git a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/actions/ReleaseStartFromCommitHandler.java b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/actions/ReleaseStartFromCommitHandler.java new file mode 100644 index 0000000000..6c9a29b523 --- /dev/null +++ b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/actions/ReleaseStartFromCommitHandler.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (C) 2015, Max Hohenegger <eclipse@hohenegger.eu> + * + * 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.gitflow.ui.internal.actions; + +import org.eclipse.egit.gitflow.GitFlowRepository; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.widgets.Shell; + +/** + * Wrapper for ReleaseStartHandler + */ +public final class ReleaseStartFromCommitHandler extends SelectionAdapter { + private ReleaseStartHandler releaseStartHandler; + private GitFlowRepository gfRepo; + private String startCommitSha1; + private Shell activeShell; + + /** + * @param activeShell + * @param startCommitSha1 + * @param gfRepo + * + */ + public ReleaseStartFromCommitHandler(GitFlowRepository gfRepo, String startCommitSha1, Shell activeShell) { + this.gfRepo = gfRepo; + this.startCommitSha1 = startCommitSha1; + this.activeShell = activeShell; + releaseStartHandler = new ReleaseStartHandler(); + } + + public void widgetSelected(SelectionEvent e) { + releaseStartHandler.doExecute(gfRepo, startCommitSha1, activeShell); + } +}
\ No newline at end of file diff --git a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/actions/ReleaseStartHandler.java b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/actions/ReleaseStartHandler.java index 7c48aee1bc..4e9d201f37 100644 --- a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/actions/ReleaseStartHandler.java +++ b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/actions/ReleaseStartHandler.java @@ -26,6 +26,7 @@ import org.eclipse.jface.window.Window; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revplot.PlotCommit; import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.swt.widgets.Shell; import org.eclipse.team.ui.history.IHistoryView; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.handlers.HandlerUtil; @@ -40,14 +41,23 @@ public class ReleaseStartHandler extends AbstractHandler { final GitFlowRepository gfRepo = GitFlowHandlerUtil.getRepository(event); final String startCommitSha1 = getStartCommit(event); + Shell activeShell = HandlerUtil.getActiveShell(event); + + doExecute(gfRepo, startCommitSha1, activeShell); + + return null; + } + + void doExecute(GitFlowRepository gfRepo, + final String startCommitSha1, Shell activeShell) { InputDialog inputDialog = new InputDialog( - HandlerUtil.getActiveShell(event), + activeShell, UIText.ReleaseStartHandler_provideReleaseName, UIText.ReleaseStartHandler_provideANameForTheNewRelease, "", //$NON-NLS-1$ new ReleaseNameValidator(gfRepo)); if (inputDialog.open() != Window.OK) { - return null; + return; } final String releaseName = inputDialog.getValue(); @@ -57,8 +67,6 @@ public class ReleaseStartHandler extends AbstractHandler { JobUtil.scheduleUserWorkspaceJob(releaseStartOperation, UIText.ReleaseStartHandler_startingNewRelease, JobFamilies.GITFLOW_FAMILY); - - return null; } private String getStartCommit(ExecutionEvent event) diff --git a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/factories/GitFlowAdapterFactory.java b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/factories/GitFlowAdapterFactory.java index 1609d64e34..cbdd1f0110 100644 --- a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/factories/GitFlowAdapterFactory.java +++ b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/factories/GitFlowAdapterFactory.java @@ -10,28 +10,32 @@ package org.eclipse.egit.gitflow.ui.internal.factories; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IAdapterFactory; -import org.eclipse.core.runtime.PlatformObject; -import org.eclipse.egit.core.internal.Utils; -import org.eclipse.egit.core.project.RepositoryMapping; -import org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode; +import static org.eclipse.egit.core.project.RepositoryMapping.getMapping; +import org.eclipse.egit.ui.internal.repository.tree.RepositoryNode; import org.eclipse.jgit.lib.Repository; +import org.eclipse.team.ui.history.IHistoryPage; +import org.eclipse.team.ui.history.IHistoryView; /** * Get JGit repository for element selected in Git Flow UI. */ public class GitFlowAdapterFactory implements IAdapterFactory { - @SuppressWarnings("unchecked") @Override - public Object getAdapter(Object adaptableObject, Class adapterType) { + public Repository getAdapter(Object adaptableObject, Class adapterType) { Repository repository = null; if (adaptableObject instanceof IResource) { IResource resource = (IResource) adaptableObject; - RepositoryMapping repositoryMapping = RepositoryMapping - .getMapping(resource.getProject()); - repository = repositoryMapping.getRepository(); - } else if (adaptableObject instanceof PlatformObject) { - PlatformObject platformObject = (PlatformObject) adaptableObject; - repository = Utils.getAdapter(platformObject, Repository.class); + repository = getRepository(resource); + } else if (adaptableObject instanceof IHistoryView) { + IHistoryView historyView = (IHistoryView) adaptableObject; + IHistoryPage historyPage = historyView.getHistoryPage(); + Object input = historyPage.getInput(); + if (input instanceof RepositoryNode) { + RepositoryNode node = (RepositoryNode) input; + repository = node.getRepository(); + } else if (input instanceof IResource) { + repository = getRepository((IResource) input); + } } else { throw new IllegalStateException(); } @@ -39,10 +43,12 @@ public class GitFlowAdapterFactory implements IAdapterFactory { return repository; } - @SuppressWarnings("unchecked") + private Repository getRepository(IResource resource) { + return getMapping(resource.getProject()).getRepository(); + } + @Override public Class[] getAdapterList() { - return new Class[] { IResource.class, RepositoryTreeNode.class }; + return new Class[] { IResource.class, IHistoryView.class }; } - } diff --git a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/menu/DynamicHistoryMenu.java b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/menu/DynamicHistoryMenu.java new file mode 100644 index 0000000000..f73ed06df6 --- /dev/null +++ b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/menu/DynamicHistoryMenu.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (C) 2015, Max Hohenegger <eclipse@hohenegger.eu> + * + * 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.gitflow.ui.internal.menu; + +import java.io.IOException; + +import org.eclipse.egit.core.internal.Utils; +import org.eclipse.egit.gitflow.GitFlowRepository; +import org.eclipse.egit.gitflow.ui.Activator; +import org.eclipse.egit.gitflow.ui.internal.UIText; +import org.eclipse.egit.gitflow.ui.internal.actions.ReleaseStartFromCommitHandler; +import org.eclipse.jface.action.ContributionItem; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PlatformUI; + +/** + * Start GitFlow release from a specified commit + */ +public class DynamicHistoryMenu extends ContributionItem { + @Override + public void fill(Menu menu, int index) { + GitFlowRepository gfRepo = getRepository(); + try { + if (gfRepo == null || !gfRepo.isDevelop()) { + return; + } + } catch (IOException e) { + Activator.getDefault().getLog().log(Activator.error(e.getMessage())); + return; + } + + RevCommit selectedCommit = getSelectedCommit(); + if (selectedCommit == null) { + return; + } + String startCommitSha1 = selectedCommit.getName(); + Shell activeShell = getActiveShell(); + + ReleaseStartFromCommitHandler listener = new ReleaseStartFromCommitHandler( + gfRepo, startCommitSha1, activeShell); + MenuItem menuItem = new MenuItem(menu, SWT.PUSH, index); + menuItem.setText(NLS.bind( + UIText.DynamicHistoryMenu_startGitflowReleaseFrom, + abbreviate(selectedCommit))); + menuItem.addSelectionListener(listener); + } + + private String abbreviate(RevCommit selectedCommit) { + return selectedCommit.getId().abbreviate(7).name(); + } + + /** + * @return Selected commit + */ + private RevCommit getSelectedCommit() { + ISelection selection = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow().getActivePage().getActivePart() + .getSite().getSelectionProvider().getSelection(); + if (!(selection instanceof IStructuredSelection)) { + return null; + } + IStructuredSelection structSelection = (IStructuredSelection) selection; + Object firstElement = structSelection.getFirstElement(); + if (!(firstElement instanceof RevCommit)) { + return null; + } + return (RevCommit) firstElement; + } + + private Shell getActiveShell() { + return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + } + + private GitFlowRepository getRepository() { + IWorkbenchPart activePart = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow().getActivePage().getActivePart(); + Repository repository = Utils.getAdapter(activePart, Repository.class); + if (repository == null) { + return null; + } + return new GitFlowRepository(repository); + } +} diff --git a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/uitext.properties b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/uitext.properties index 340dc57bd6..65fdb52e8f 100644 --- a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/uitext.properties +++ b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/uitext.properties @@ -6,6 +6,7 @@ # which accompanies this distribution, and is available at # http://www.eclipse.org/legal/epl-v10.html ############################################################################### +DynamicHistoryMenu_startGitflowReleaseFrom=Start release from commit {0}... FeatureFinishHandler_finishingFeature=Finishing feature... FeatureRebaseHandler_conflicts=Conflicts FeatureRebaseHandler_rebaseFailed=Rebase failed. |