Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Lay2010-05-20 13:33:33 +0000
committerChris Aniszczyk2010-05-24 13:45:36 +0000
commit8ada6f7964642ea8ce50c42eaa5ecc1e234e36f6 (patch)
tree0190f23b5afd8592d7e2b8f0097130f36c9445c3
parent6a8ab1f3a134fae58bd0ead134bbf967efa2fd5c (diff)
downloadegit-8ada6f7964642ea8ce50c42eaa5ecc1e234e36f6.tar.gz
egit-8ada6f7964642ea8ce50c42eaa5ecc1e234e36f6.tar.xz
egit-8ada6f7964642ea8ce50c42eaa5ecc1e234e36f6.zip
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 <stefan.lay@sap.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.egit.core/META-INF/MANIFEST.MF4
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java12
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties4
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/op/MergeOperation.java118
-rw-r--r--org.eclipse.egit.ui/icons/obj16/merge.gifbin0 -> 149 bytes
-rw-r--r--org.eclipse.egit.ui/plugin.properties3
-rw-r--r--org.eclipse.egit.ui/plugin.xml7
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java36
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/BranchAction.java2
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeAction.java109
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetAction.java4
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/BranchSelectionDialog.java313
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/MergeTargetSelectionDialog.java54
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/ResetTargetSelectionDialog.java112
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties13
15 files changed, 616 insertions, 175 deletions
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
@@ -188,6 +188,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
--- /dev/null
+++ b/org.eclipse.egit.ui/icons/obj16/merge.gif
Binary files 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
@@ -70,6 +70,13 @@
menubarPath="team.main/group4"
tooltip="%TagAction_tooltip"/>
<action
+ class="org.eclipse.egit.ui.internal.actions.MergeAction"
+ icon="$nl$/icons/obj16/merge.gif"
+ id="org.eclipse.egit.ui.internal.actions.MergeAction"
+ label="%MergeAction_label"
+ menubarPath="team.main/group4"
+ tooltip="%MergeAction_tooltip"/>
+ <action
class="org.eclipse.egit.ui.internal.actions.BranchAction"
icon="$nl$/icons/obj16/branch_obj.gif"
id="org.eclipse.egit.ui.internal.actions.BranchAction"
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
index 0f2c47eafd..572989811c 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
@@ -1854,6 +1854,42 @@ public class UIText extends NLS {
/** */
public static String GitShareProjectsPage_RepositoryLabel;
+ /** */
+ public static String MergeAction_CannotMerge;
+
+ /** */
+ public static String MergeAction_ChangedFiles;
+
+ /** */
+ public static String MergeAction_ErrorMergeEnabling;
+
+ /** */
+ public static String MergeAction_HeadIsNoBranch;
+
+ /** */
+ public static String MergeAction_JobNameMerge;
+
+ /** */
+ public static String MergeAction_ProblemMerge;
+
+ /** */
+ public static String MergeAction_UnableMerge;
+
+ /** */
+ public static String MergeAction_WrongRepositoryState;
+
+ /** */
+ public static String MergeTargetSelectionDialog_ButtonMerge;
+
+ /** */
+ public static String MergeTargetSelectionDialog_OnlyFastForward;
+
+ /** */
+ public static String MergeTargetSelectionDialog_SelectRef;
+
+ /** */
+ public static String MergeTargetSelectionDialog_TitleMerge;
+
/** */
public static String MixedResetToRevisionAction_mixedReset;
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/BranchAction.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/BranchAction.java
index 6e603d13c0..9c78831f57 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/BranchAction.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/BranchAction.java
@@ -48,7 +48,7 @@ public class BranchAction extends RepositoryAction {
return;
}
- BranchSelectionDialog dialog = new BranchSelectionDialog(getShell(), repository, false);
+ BranchSelectionDialog dialog = new BranchSelectionDialog(getShell(), repository);
if (dialog.open() != Window.OK) {
return;
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeAction.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeAction.java
new file mode 100644
index 0000000000..9a90c125eb
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeAction.java
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * 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.actions;
+
+import java.io.IOException;
+
+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.jobs.Job;
+import org.eclipse.egit.core.op.MergeOperation;
+import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.UIText;
+import org.eclipse.egit.ui.internal.dialogs.MergeTargetSelectionDialog;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.RepositoryState;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.team.internal.ui.Utils;
+
+/**
+ * Action for selecting a commit and merging it with the current branch.
+ */
+public class MergeAction extends RepositoryAction {
+
+ @Override
+ public void execute(IAction action) {
+ final Repository repository = getRepository(true);
+ if (repository == null)
+ return;
+
+ if (!canMerge(repository))
+ return;
+
+ MergeTargetSelectionDialog mergeTargetSelectionDialog = new MergeTargetSelectionDialog(
+ getShell(), repository);
+ if (mergeTargetSelectionDialog.open() == IDialogConstants.OK_ID) {
+
+ final String refName = mergeTargetSelectionDialog.getRefName();
+
+ String jobname = NLS.bind(UIText.MergeAction_JobNameMerge, refName);
+ Job job = new Job(jobname) {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ new MergeOperation(repository, refName).execute(monitor);
+ } catch (final CoreException e) {
+ getShell().getDisplay().asyncExec(new Runnable(){
+ public void run() {
+ Utils.handleError(getShell(), e, "Merge impossible", "Unsupported Operation"); //$NON-NLS-1$ //$NON-NLS-2$
+ }});
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ job.setUser(true);
+ job.schedule();
+
+ }
+
+ }
+
+ private boolean canMerge(final Repository repository) {
+ String message = null;
+ try {
+ Ref head = repository.getRef(Constants.HEAD);
+ if (head == null || !head.isSymbolic())
+ message = UIText.MergeAction_HeadIsNoBranch;
+ else if (!repository.getRepositoryState().equals(
+ RepositoryState.SAFE))
+ message = NLS.bind(
+ UIText.MergeAction_WrongRepositoryState,
+ repository.getRepositoryState());
+ } catch (IOException e) {
+ Activator.logError(e.getMessage(), e);
+ message = e.getMessage();
+ }
+
+ if (message != null) {
+ MessageDialog.openError(getShell(),
+ UIText.MergeAction_CannotMerge, message);
+ }
+ return (message == null);
+ }
+
+ @Override
+ public boolean isEnabled() {
+ boolean enabled = true;
+ Repository repository = getRepository(false);
+ if (repository == null)
+ enabled = false;
+ return enabled;
+ }
+
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetAction.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetAction.java
index be5955ea94..809e670f13 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetAction.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetAction.java
@@ -20,7 +20,7 @@ import org.eclipse.egit.core.op.ResetOperation.ResetType;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.internal.decorators.GitLightweightDecorator;
-import org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog;
+import org.eclipse.egit.ui.internal.dialogs.ResetTargetSelectionDialog;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
@@ -44,7 +44,7 @@ public class ResetAction extends RepositoryAction {
NLS.bind(UIText.ResetAction_repositoryState, repository.getRepositoryState().getDescription()));
return;
}
- BranchSelectionDialog branchSelectionDialog = new BranchSelectionDialog(getShell(), repository, true);
+ ResetTargetSelectionDialog branchSelectionDialog = new ResetTargetSelectionDialog(getShell(), repository);
if (branchSelectionDialog.open() == IDialogConstants.OK_ID) {
final String refName = branchSelectionDialog.getRefName();
final ResetType type = branchSelectionDialog.getResetType();
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/BranchSelectionDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/BranchSelectionDialog.java
index a987115527..032cc3b707 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/BranchSelectionDialog.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/BranchSelectionDialog.java
@@ -15,18 +15,16 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.egit.core.op.ResetOperation.ResetType;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIText;
+import org.eclipse.egit.ui.internal.ValidationUtils;
import org.eclipse.egit.ui.internal.repository.RepositoriesViewContentProvider;
import org.eclipse.egit.ui.internal.repository.RepositoriesViewLabelProvider;
import org.eclipse.egit.ui.internal.repository.RepositoryTreeNode;
import org.eclipse.egit.ui.internal.repository.RepositoryTreeNode.RepositoryTreeNodeType;
-import org.eclipse.egit.ui.internal.ValidationUtils;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.InputDialog;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.resource.JFaceResources;
@@ -50,13 +48,9 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridLayout;
-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.Label;
-import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
/**
@@ -67,11 +61,12 @@ public class BranchSelectionDialog extends Dialog {
private final Repository repo;
- private final boolean showResetType;
-
private TreeViewer branchTree;
- private Button confirmationBtn;
+ /**
+ * button which finally triggers the action
+ */
+ protected Button confirmationBtn;
private Button renameButton;
@@ -79,8 +74,6 @@ public class BranchSelectionDialog extends Dialog {
private String selectedBranch;
- private ResetType resetType = ResetType.MIXED;
-
private final RepositoryTreeNode<Repository> localBranches;
private final RepositoryTreeNode<Repository> 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<Repository>(null,
RepositoryTreeNodeType.LOCALBRANCHES, this.repo, this.repo);
remoteBranches = new RepositoryTreeNode<Repository>(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

Back to the top