From 8ada6f7964642ea8ce50c42eaa5ecc1e234e36f6 Mon Sep 17 00:00:00 2001 From: Stefan Lay Date: Thu, 20 May 2010 15:33:33 +0200 Subject: Add action to trigger (fast-forward) merge Add a new action to the team menu which opens a merge dialog where a branch can be selected. Currently jgit supports only fast-forward merges, therefore the action label is "Fast-forward merge..." In order to achieve better reuse the BranchSelectionDialog is refactored. Change-Id: I3a97d262fd4032d8cc045e94429608b49a937c0f Signed-off-by: Stefan Lay Signed-off-by: Chris Aniszczyk --- org.eclipse.egit.core/META-INF/MANIFEST.MF | 4 +- .../src/org/eclipse/egit/core/CoreText.java | 12 + .../src/org/eclipse/egit/core/coretext.properties | 4 + .../org/eclipse/egit/core/op/MergeOperation.java | 118 ++++++++ org.eclipse.egit.ui/icons/obj16/merge.gif | Bin 0 -> 149 bytes org.eclipse.egit.ui/plugin.properties | 3 + org.eclipse.egit.ui/plugin.xml | 7 + .../src/org/eclipse/egit/ui/UIText.java | 36 +++ .../egit/ui/internal/actions/BranchAction.java | 2 +- .../egit/ui/internal/actions/MergeAction.java | 109 +++++++ .../egit/ui/internal/actions/ResetAction.java | 4 +- .../ui/internal/dialogs/BranchSelectionDialog.java | 313 ++++++++++----------- .../dialogs/MergeTargetSelectionDialog.java | 54 ++++ .../dialogs/ResetTargetSelectionDialog.java | 112 ++++++++ .../src/org/eclipse/egit/ui/uitext.properties | 13 + 15 files changed, 616 insertions(+), 175 deletions(-) create mode 100644 org.eclipse.egit.core/src/org/eclipse/egit/core/op/MergeOperation.java create mode 100644 org.eclipse.egit.ui/icons/obj16/merge.gif create mode 100644 org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeAction.java create mode 100644 org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/MergeTargetSelectionDialog.java create mode 100644 org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/ResetTargetSelectionDialog.java diff --git a/org.eclipse.egit.core/META-INF/MANIFEST.MF b/org.eclipse.egit.core/META-INF/MANIFEST.MF index 9ae2fe9a20..c49bd687f6 100644 --- a/org.eclipse.egit.core/META-INF/MANIFEST.MF +++ b/org.eclipse.egit.core/META-INF/MANIFEST.MF @@ -17,9 +17,11 @@ Export-Package: org.eclipse.egit.core;version="0.8.0", org.eclipse.egit.core.project;version="0.8.0" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Import-Package: org.eclipse.jgit.dircache;version="[0.8.0,0.9.0)", +Import-Package: org.eclipse.jgit.api;version="[0.8.0,0.9.0)", + org.eclipse.jgit.dircache;version="[0.8.0,0.9.0)", org.eclipse.jgit.errors;version="[0.8.0,0.9.0)", org.eclipse.jgit.lib;version="[0.8.0,0.9.0)", + org.eclipse.jgit.merge;version="[0.8.0,0.9.0)", org.eclipse.jgit.revwalk;version="[0.8.0,0.9.0)", org.eclipse.jgit.transport;version="[0.8.0,0.9.0)", org.eclipse.jgit.treewalk;version="[0.8.0,0.9.0)", diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java index cfeb85fb2c..0911cc643b 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java @@ -187,6 +187,18 @@ public class CoreText extends NLS { /** */ public static String ResetOperation_writingIndex; + /** */ + public static String MergeOperation_InternalError; + + /** */ + public static String MergeOperation_MergeFailedNoHead; + + /** */ + public static String MergeOperation_MergeFailedRefUpdate; + + /** */ + public static String MergeOperation_ProgressMerge; + /** */ public static String MoveDeleteHook_cannotModifyFolder; diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties b/org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties index 4fde52460a..ecb23f4df0 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties @@ -73,6 +73,10 @@ ResetOperation_readingIndex=Reading index ResetOperation_updatingFailed=Updating {0} failed ResetOperation_writingIndex=Writing index +MergeOperation_InternalError=An internal error occured +MergeOperation_MergeFailedNoHead=Merge failed: Reference to HEAD does not exist +MergeOperation_MergeFailedRefUpdate=Merge failed: Another process is accessing the ref +MergeOperation_ProgressMerge=Merge {0} MoveDeleteHook_cannotModifyFolder=Folder contains an active Git repository.\n\ The folder cannot be moved, renamed or deleted until the team provider is disconnected. diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/MergeOperation.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/MergeOperation.java new file mode 100644 index 0000000000..8000675aff --- /dev/null +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/MergeOperation.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2010 SAP AG. + * 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: + * Stefan Lay (SAP AG) - initial implementation + *******************************************************************************/ +package org.eclipse.egit.core.op; + +import java.io.IOException; + +import org.eclipse.core.resources.IWorkspaceRunnable; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.core.runtime.jobs.ISchedulingRule; +import org.eclipse.egit.core.Activator; +import org.eclipse.egit.core.CoreText; +import org.eclipse.egit.core.internal.util.ProjectUtil; +import org.eclipse.jgit.api.CheckoutConflictException; +import org.eclipse.jgit.api.ConcurrentRefUpdateException; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.MergeCommand; +import org.eclipse.jgit.api.MergeResult; +import org.eclipse.jgit.api.NoHeadException; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.merge.MergeStrategy; +import org.eclipse.osgi.util.NLS; +import org.eclipse.team.core.TeamException; + +/** + * This class implements the merge of a ref with the current head + * + */ +public class MergeOperation implements IEGitOperation { + + private final Repository repository; + + private final String refName; + + private MergeStrategy mergeStrategy; + + private MergeResult mergeResult; + + /** + * @param repository + * @param refName name of a commit which should be merged + */ + public MergeOperation(Repository repository, String refName) { + this.repository = repository; + this.refName = refName; + } + + /** + * Create a MergeOperation object + * @param repository + * @param refName name of a commit which should be merged + * @param mergeStrategy the strategy to use for merge + */ + public MergeOperation(Repository repository, String refName, + String mergeStrategy) { + this.repository = repository; + this.refName = refName; + if (mergeStrategy != null) + this.mergeStrategy = MergeStrategy.get(mergeStrategy); + } + + public void execute(IProgressMonitor monitor) throws CoreException { + IWorkspaceRunnable action = new IWorkspaceRunnable() { + + public void run(IProgressMonitor mymonitor) throws CoreException { + mymonitor.beginTask(NLS.bind(CoreText.MergeOperation_ProgressMerge, refName), 3); + Git git = new Git(repository); + mymonitor.worked(1); + MergeCommand merge; + try { + merge = git.merge().include(repository.getRef(refName)); + } catch (IOException e) { + throw new TeamException(CoreText.MergeOperation_InternalError, e); + } + if (mergeStrategy != null) { + merge.setStrategy(mergeStrategy); + } + try { + mergeResult = merge.call(); + mymonitor.worked(1); + if (MergeResult.MergeStatus.FAILED.equals(mergeResult.getMergeStatus())) + throw new TeamException(mergeResult.toString()); + else if (MergeResult.MergeStatus.NOT_SUPPORTED.equals(mergeResult.getMergeStatus())) + throw new TeamException(new Status(IStatus.INFO, Activator.getPluginId(), mergeResult.toString())); + } catch (NoHeadException e) { + throw new TeamException(CoreText.MergeOperation_MergeFailedNoHead, e); + } catch (ConcurrentRefUpdateException e) { + throw new TeamException(CoreText.MergeOperation_MergeFailedRefUpdate, e); + } catch (CheckoutConflictException e) { + throw new TeamException(e.getLocalizedMessage(), e.getCause()); + } + ProjectUtil.refreshProjects(repository, new SubProgressMonitor( + mymonitor, 1)); + mymonitor.done(); + } + }; + // lock workspace to protect working tree changes + ResourcesPlugin.getWorkspace().run(action, monitor); + } + + public ISchedulingRule getSchedulingRule() { + return ResourcesPlugin.getWorkspace().getRoot(); + } + + +} diff --git a/org.eclipse.egit.ui/icons/obj16/merge.gif b/org.eclipse.egit.ui/icons/obj16/merge.gif new file mode 100644 index 0000000000..07d1028a7a Binary files /dev/null and b/org.eclipse.egit.ui/icons/obj16/merge.gif differ diff --git a/org.eclipse.egit.ui/plugin.properties b/org.eclipse.egit.ui/plugin.properties index f0ca16f23c..90e9e65e5b 100644 --- a/org.eclipse.egit.ui/plugin.properties +++ b/org.eclipse.egit.ui/plugin.properties @@ -66,6 +66,9 @@ ResetAction_tooltip=Reset the current branch to the same or another commit BranchAction_label=&Branch... BranchAction_tooltip=Switch to another branch +MergeAction_label=&Merge... +MergeAction_tooltip=Fast-forward Merge with another branch + TagAction_label=&Tag... TagAction_tooltip=Create or edit tag diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml index 5c0f65ce9a..4de8339283 100644 --- a/org.eclipse.egit.ui/plugin.xml +++ b/org.eclipse.egit.ui/plugin.xml @@ -69,6 +69,13 @@ label="%TagAction_label" menubarPath="team.main/group4" tooltip="%TagAction_tooltip"/> + localBranches; private final RepositoryTreeNode remoteBranches; @@ -91,12 +84,10 @@ public class BranchSelectionDialog extends Dialog { * Construct a dialog to select a branch to reset to or check out * @param parentShell * @param repo - * @param showReset true if the "reset" part should be shown */ - public BranchSelectionDialog(Shell parentShell, Repository repo, boolean showReset) { + public BranchSelectionDialog(Shell parentShell, Repository repo) { super(parentShell); this.repo = repo; - this.showResetType = showReset; localBranches = new RepositoryTreeNode(null, RepositoryTreeNodeType.LOCALBRANCHES, this.repo, this.repo); remoteBranches = new RepositoryTreeNode(null, @@ -109,7 +100,7 @@ public class BranchSelectionDialog extends Dialog { protected Composite createDialogArea(Composite base) { Composite parent = (Composite) super.createDialogArea(base); parent.setLayout(GridLayoutFactory.swtDefaults().create()); - new Label(parent, SWT.NONE).setText(UIText.BranchSelectionDialog_Refs); + new Label(parent, SWT.NONE).setText(getRefsLabel()); branchTree = new TreeViewer(parent, SWT.SINGLE | SWT.BORDER); new RepositoriesViewLabelProvider(branchTree); @@ -132,16 +123,19 @@ public class BranchSelectionDialog extends Dialog { .startsWith(Constants.R_REMOTES)); // we don't allow reset on tags, but checkout - if (showResetType) + if (!canConfirmOnTag()) confirmationBtn.setEnabled(branchSelected); else confirmationBtn.setEnabled(branchSelected || tagSelected); - if (!showResetType) { - // we don't support rename on tags - renameButton.setEnabled(branchSelected && !tagSelected); + // we don't support rename on tags + if (renameButton != null) { + renameButton.setEnabled(branchSelected && !tagSelected + && !tagSelected); + } - // new branch can not be based on a tag + // new branch can not be based on a tag + if (newButton != null) { newButton.setEnabled(branchSelected && !tagSelected); } } @@ -162,12 +156,10 @@ public class BranchSelectionDialog extends Dialog { } }); - if (showResetType) { - buildResetGroup(parent); - } + createCustomArea(parent); + + String rawTitle = getTitle(); - String rawTitle = showResetType ? UIText.BranchSelectionDialog_TitleReset - : UIText.BranchSelectionDialog_TitleCheckout; getShell().setText( NLS.bind(rawTitle, new Object[] { repo.getDirectory() })); @@ -230,38 +222,6 @@ public class BranchSelectionDialog extends Dialog { return true; } - private void buildResetGroup(Composite parent) { - Group g = new Group(parent, SWT.NONE); - g.setText(UIText.BranchSelectionDialog_ResetType); - g.setLayoutData(GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).create()); - g.setLayout(new RowLayout(SWT.VERTICAL)); - - Button soft = new Button(g, SWT.RADIO); - soft.setText(UIText.BranchSelectionDialog_ResetTypeSoft); - soft.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - resetType = ResetType.SOFT; - } - }); - - Button medium = new Button(g, SWT.RADIO); - medium.setSelection(true); - medium.setText(UIText.BranchSelectionDialog_ResetTypeMixed); - medium.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - resetType = ResetType.MIXED; - } - }); - - Button hard = new Button(g, SWT.RADIO); - hard.setText(UIText.BranchSelectionDialog_ResetTypeHard); - hard.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - resetType = ResetType.HARD; - } - }); - } - /** * @return the selected refName */ @@ -269,26 +229,9 @@ public class BranchSelectionDialog extends Dialog { return this.selectedBranch; } - /** - * @return Type of Reset - */ - public ResetType getResetType() { - return resetType; - } - @Override protected void okPressed() { this.selectedBranch = refNameFromDialog(); - if (showResetType) { - if (resetType == ResetType.HARD) { - if (!MessageDialog.openQuestion(getShell(), - UIText.BranchSelectionDialog_ReallyResetTitle, - UIText.BranchSelectionDialog_ReallyResetMessage)) { - return; - } - } - } - super.okPressed(); } @@ -317,125 +260,153 @@ public class BranchSelectionDialog extends Dialog { @Override protected void createButtonsForButtonBar(Composite parent) { - if (!showResetType) { - newButton = new Button(parent, SWT.PUSH); - newButton.setFont(JFaceResources.getDialogFont()); - newButton.setText(UIText.BranchSelectionDialog_NewBranch); - setButtonLayoutData(newButton); - ((GridLayout)parent.getLayout()).numColumns++; + newButton = new Button(parent, SWT.PUSH); + newButton.setFont(JFaceResources.getDialogFont()); + newButton.setText(UIText.BranchSelectionDialog_NewBranch); + setButtonLayoutData(newButton); + ((GridLayout)parent.getLayout()).numColumns++; - renameButton = new Button(parent, SWT.PUSH); - renameButton.setFont(JFaceResources.getDialogFont()); - renameButton.setText(UIText.BranchSelectionDialog_Rename); - setButtonLayoutData(renameButton); - ((GridLayout)parent.getLayout()).numColumns++; + renameButton = new Button(parent, SWT.PUSH); + renameButton.setFont(JFaceResources.getDialogFont()); + renameButton.setText(UIText.BranchSelectionDialog_Rename); + setButtonLayoutData(renameButton); + ((GridLayout)parent.getLayout()).numColumns++; - renameButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { + renameButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { - String refName = refNameFromDialog(); - String refPrefix; + String refName = refNameFromDialog(); + String refPrefix; + // the button should be disabled anyway, but we check again + if (refName.equals(Constants.HEAD)) + return; + + if (refName.startsWith(Constants.R_HEADS)) + refPrefix = Constants.R_HEADS; + else if (refName.startsWith(Constants.R_REMOTES)) + refPrefix = Constants.R_REMOTES; + else if (refName.startsWith(Constants.R_TAGS)) + refPrefix = Constants.R_TAGS; + else { // the button should be disabled anyway, but we check again - if (refName.equals(Constants.HEAD)) - return; - - if (refName.startsWith(Constants.R_HEADS)) - refPrefix = Constants.R_HEADS; - else if (refName.startsWith(Constants.R_REMOTES)) - refPrefix = Constants.R_REMOTES; - else if (refName.startsWith(Constants.R_TAGS)) - refPrefix = Constants.R_TAGS; - else { - // the button should be disabled anyway, but we check again - return; - } + return; + } - String branchName = refName.substring(refPrefix.length()); - - InputDialog labelDialog = getRefNameInputDialog(NLS - .bind( - UIText.BranchSelectionDialog_QuestionNewBranchNameMessage, - branchName, refPrefix), refPrefix); - if (labelDialog.open() == Window.OK) { - String newRefName = refPrefix + labelDialog.getValue(); - try { - RefRename renameRef = repo.renameRef(refName, newRefName); - if (renameRef.rename() != Result.RENAMED) { - reportError( - null, - UIText.BranchSelectionDialog_ErrorCouldNotRenameRef, - refName, newRefName, renameRef - .getResult()); - } - branchTree.refresh(); - markRef(newRefName); - } catch (Throwable e1) { + String branchName = refName.substring(refPrefix.length()); + + InputDialog labelDialog = getRefNameInputDialog(NLS + .bind( + UIText.BranchSelectionDialog_QuestionNewBranchNameMessage, + branchName, refPrefix), refPrefix); + if (labelDialog.open() == Window.OK) { + String newRefName = refPrefix + labelDialog.getValue(); + try { + RefRename renameRef = repo.renameRef(refName, newRefName); + if (renameRef.rename() != Result.RENAMED) { reportError( - e1, + null, UIText.BranchSelectionDialog_ErrorCouldNotRenameRef, - refName, newRefName, e1.getMessage()); + refName, newRefName, renameRef + .getResult()); } + branchTree.refresh(); + markRef(newRefName); + } catch (Throwable e1) { + reportError( + e1, + UIText.BranchSelectionDialog_ErrorCouldNotRenameRef, + refName, newRefName, e1.getMessage()); } } - }); - newButton.addSelectionListener(new SelectionAdapter() { + } + }); + newButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - // check what ref name the user selected, if any. - String refName = refNameFromDialog(); + public void widgetSelected(SelectionEvent e) { + // check what ref name the user selected, if any. + String refName = refNameFromDialog(); + // the button should be disabled anyway, but we check again + if (refName.equals(Constants.HEAD)) + return; + if (refName.startsWith(Constants.R_TAGS)) // the button should be disabled anyway, but we check again - if (refName.equals(Constants.HEAD)) - return; - if (refName.startsWith(Constants.R_TAGS)) - // the button should be disabled anyway, but we check again - return; - - InputDialog labelDialog = getRefNameInputDialog( - NLS - .bind( - UIText.BranchSelectionDialog_QuestionNewBranchMessage, - refName, Constants.R_HEADS), - Constants.R_HEADS); - - if (labelDialog.open() == Window.OK) { - String newRefName = Constants.R_HEADS + labelDialog.getValue(); - RefUpdate updateRef; - try { - updateRef = repo.updateRef(newRefName); - Ref startRef = repo.getRef(refName); - ObjectId startAt = repo.resolve(refName); - String startBranch; - if (startRef != null) - startBranch = refName; - else - startBranch = startAt.name(); - startBranch = repo.shortenRefName(startBranch); - updateRef.setNewObjectId(startAt); - updateRef.setRefLogMessage("branch: Created from " + startBranch, false); //$NON-NLS-1$ - updateRef.update(); - branchTree.refresh(); - markRef(newRefName); - } catch (Throwable e1) { - reportError( - e1, - UIText.BranchSelectionDialog_ErrorCouldNotCreateNewRef, - newRefName); - } + return; + + InputDialog labelDialog = getRefNameInputDialog( + NLS + .bind( + UIText.BranchSelectionDialog_QuestionNewBranchMessage, + refName, Constants.R_HEADS), + Constants.R_HEADS); + + if (labelDialog.open() == Window.OK) { + String newRefName = Constants.R_HEADS + labelDialog.getValue(); + RefUpdate updateRef; + try { + updateRef = repo.updateRef(newRefName); + Ref startRef = repo.getRef(refName); + ObjectId startAt = repo.resolve(refName); + String startBranch; + if (startRef != null) + startBranch = refName; + else + startBranch = startAt.name(); + startBranch = repo.shortenRefName(startBranch); + updateRef.setNewObjectId(startAt); + updateRef.setRefLogMessage("branch: Created from " + startBranch, false); //$NON-NLS-1$ + updateRef.update(); + branchTree.refresh(); + markRef(newRefName); + } catch (Throwable e1) { + reportError( + e1, + UIText.BranchSelectionDialog_ErrorCouldNotCreateNewRef, + newRefName); } } - }); - } + } + }); confirmationBtn = createButton(parent, IDialogConstants.OK_ID, - showResetType ? UIText.BranchSelectionDialog_OkReset - : UIText.BranchSelectionDialog_OkCheckout, true); + UIText.BranchSelectionDialog_OkCheckout, true); createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); // can't advance without a selection confirmationBtn.setEnabled(!branchTree.getSelection().isEmpty()); } + /** + * @return the label shown above the refs tree + */ + protected String getRefsLabel() { + return UIText.BranchSelectionDialog_Refs; + } + + /** + * Subclasses may add UI elements + * @param parent + */ + protected void createCustomArea(Composite parent) { + // do nothing + } + + /** + * Subclasses may change the title of the dialog + * @return the title of the dialog + */ + protected String getTitle() { + return UIText.BranchSelectionDialog_TitleCheckout; + } + + /** + * + * @return if the confirmation button is enabled when a tag is selected + */ + protected boolean canConfirmOnTag() { + return true; + } + @Override protected int getShellStyle() { return super.getShellStyle() | SWT.RESIZE; diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/MergeTargetSelectionDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/MergeTargetSelectionDialog.java new file mode 100644 index 0000000000..0c9fcd4d94 --- /dev/null +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/MergeTargetSelectionDialog.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2010 SAP AG. + * 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: + * Stefan Lay (SAP AG) - initial implementation + *******************************************************************************/ +package org.eclipse.egit.ui.internal.dialogs; + +import org.eclipse.egit.ui.UIText; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Shell; + +/** + * Dialog for selecting a merge target. + * + */ +public class MergeTargetSelectionDialog extends BranchSelectionDialog { + + /** + * Construct a dialog to select a branch to reset to or check out + * + * @param parentShell + * @param repo + */ + public MergeTargetSelectionDialog(Shell parentShell, Repository repo) { + super(parentShell, repo); + } + + @Override + protected void createButtonsForButtonBar(Composite parent) { + confirmationBtn = createButton(parent, IDialogConstants.OK_ID, + UIText.MergeTargetSelectionDialog_ButtonMerge, true); + createButton(parent, IDialogConstants.CANCEL_ID, + IDialogConstants.CANCEL_LABEL, false); + } + + @Override + protected String getRefsLabel() { + return UIText.MergeTargetSelectionDialog_SelectRef + + " " + UIText.MergeTargetSelectionDialog_OnlyFastForward; //$NON-NLS-1$ + } + + @Override + protected String getTitle() { + return UIText.MergeTargetSelectionDialog_TitleMerge; + } + +} diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/ResetTargetSelectionDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/ResetTargetSelectionDialog.java new file mode 100644 index 0000000000..f469daeeaa --- /dev/null +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/ResetTargetSelectionDialog.java @@ -0,0 +1,112 @@ +/******************************************************************************* + * Copyright (c) 2010 SAP AG. + * 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: + * Stefan Lay (SAP AG) - initial implementation + *******************************************************************************/ +package org.eclipse.egit.ui.internal.dialogs; + +import org.eclipse.egit.core.op.ResetOperation.ResetType; +import org.eclipse.egit.ui.UIText; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; + +/** + * Dialog for selecting a reset target. + */ +public class ResetTargetSelectionDialog extends BranchSelectionDialog { + + private ResetType resetType = ResetType.MIXED; + + /** + * Construct a dialog to select a branch to reset to + * @param parentShell + * @param repo + */ + public ResetTargetSelectionDialog(Shell parentShell, Repository repo) { + super(parentShell, repo); + } + + @Override + protected void createCustomArea(Composite parent) { + Group g = new Group(parent, SWT.NONE); + g.setText(UIText.BranchSelectionDialog_ResetType); + g.setLayoutData(GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).create()); + g.setLayout(new RowLayout(SWT.VERTICAL)); + + Button soft = new Button(g, SWT.RADIO); + soft.setText(UIText.BranchSelectionDialog_ResetTypeSoft); + soft.addListener(SWT.Selection, new Listener() { + public void handleEvent(Event event) { + resetType = ResetType.SOFT; + } + }); + + Button medium = new Button(g, SWT.RADIO); + medium.setSelection(true); + medium.setText(UIText.BranchSelectionDialog_ResetTypeMixed); + medium.addListener(SWT.Selection, new Listener() { + public void handleEvent(Event event) { + resetType = ResetType.MIXED; + } + }); + + Button hard = new Button(g, SWT.RADIO); + hard.setText(UIText.BranchSelectionDialog_ResetTypeHard); + hard.addListener(SWT.Selection, new Listener() { + public void handleEvent(Event event) { + resetType = ResetType.HARD; + } + }); + } + + @Override + protected void createButtonsForButtonBar(Composite parent) { + confirmationBtn = createButton(parent, IDialogConstants.OK_ID, + UIText.BranchSelectionDialog_OkReset, true); + createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); + } + + @Override + protected String getTitle() { + return UIText.BranchSelectionDialog_TitleReset; + } + + @Override + protected boolean canConfirmOnTag() { + return false; + } + + /** + * @return Type of Reset + */ + public ResetType getResetType() { + return resetType; + } + + @Override + protected void okPressed() { + if (resetType == ResetType.HARD) { + if (!MessageDialog.openQuestion(getShell(), + UIText.BranchSelectionDialog_ReallyResetTitle, + UIText.BranchSelectionDialog_ReallyResetMessage)) { + return; + } + } + super.okPressed(); + } +} \ No newline at end of file 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 852500d207..92a05ac153 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 @@ -503,6 +503,19 @@ BranchSelectionDialog_ResetTypeSoft=&Soft (Index and working directory unmodifie BranchSelectionDialog_Refs=Re&fs BranchSelectionDialog_Rename=&Rename +MergeAction_CannotMerge=Cannot merge now +MergeAction_ChangedFiles=There are changed files. Merging is currently not supported in this case. +MergeAction_ErrorMergeEnabling=Error during Action enabling +MergeAction_HeadIsNoBranch=HEAD is not pointing to a branch +MergeAction_JobNameMerge=Merging with {0} +MergeAction_ProblemMerge=Problem during merge +MergeAction_UnableMerge=Unable to merge. +MergeAction_WrongRepositoryState=The Repository State {0} does not allow to merge +MergeTargetSelectionDialog_ButtonMerge=&Merge +MergeTargetSelectionDialog_OnlyFastForward=Only fast-forward merges are currently possible. +MergeTargetSelectionDialog_SelectRef=Select a branch or a tag. +MergeTargetSelectionDialog_TitleMerge=Merge: {0} + DecoratorPreferencesPage_addVariablesTitle=Add Variables DecoratorPreferencesPage_addVariablesAction=Add &Variables... DecoratorPreferencesPage_recomputeAncestorDecorations=Re-decorate &ancestors when decorating changed resources -- cgit v1.2.1