summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorTomasz Zarna2012-08-26 17:00:29 (EDT)
committer Matthias Sohn2012-08-26 17:00:29 (EDT)
commitc7f1074f7d252626ec958be6b3f92acd582fc904 (patch)
tree2bb0a83949dddd2a132b6146f8d494142648f6f2
parente65101e7eeb28cd9cdb4bc1c7702fe91a59c534f (diff)
downloadegit-c7f1074f7d252626ec958be6b3f92acd582fc904.zip
egit-c7f1074f7d252626ec958be6b3f92acd582fc904.tar.gz
egit-c7f1074f7d252626ec958be6b3f92acd582fc904.tar.bz2
Squash merge commits in Merge wizardrefs/changes/08/7208/4
Bug: 382720 Change-Id: Ib8670fbe849ece2b5436255dc408b7dfa5ebdeaa Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/op/MergeOperation.java13
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/FetchAndMergeActionTest.java76
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java9
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeActionHandler.java1
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/MergeTargetSelectionDialog.java49
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties3
6 files changed, 151 insertions, 0 deletions
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
index 236686d..a8cfe3b 100644
--- 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
@@ -1,5 +1,7 @@
/*******************************************************************************
* Copyright (c) 2010 SAP AG.
+ * Copyright (C) 2012, Tomasz Zarna <Tomasz.Zarna@pl.ibm.com>
+ *
* 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
@@ -7,6 +9,7 @@
*
* Contributors:
* Stefan Lay (SAP AG) - initial implementation
+ * Tomasz Zarna (IBM) - merge squash, bug 382720
*******************************************************************************/
package org.eclipse.egit.core.op;
@@ -52,6 +55,8 @@ public class MergeOperation implements IEGitOperation {
private MergeStrategy mergeStrategy;
+ private boolean squash;
+
private MergeResult mergeResult;
/**
@@ -77,6 +82,13 @@ public class MergeOperation implements IEGitOperation {
this.mergeStrategy = MergeStrategy.get(mergeStrategy);
}
+ /**
+ * @param squash true to squash merge commits
+ */
+ public void setSquash(boolean squash) {
+ this.squash = squash;
+ }
+
public void execute(IProgressMonitor m) throws CoreException {
if (mergeResult != null)
throw new CoreException(new Status(IStatus.ERROR, Activator
@@ -103,6 +115,7 @@ public class MergeOperation implements IEGitOperation {
} catch (IOException e) {
throw new TeamException(CoreText.MergeOperation_InternalError, e);
}
+ merge.setSquash(squash);
if (mergeStrategy != null) {
merge.setStrategy(mergeStrategy);
}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/FetchAndMergeActionTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/FetchAndMergeActionTest.java
index 224cb98..823152b 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/FetchAndMergeActionTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/FetchAndMergeActionTest.java
@@ -19,14 +19,17 @@ import java.io.File;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
import org.eclipse.egit.ui.internal.repository.RepositoriesViewLabelProvider;
+import org.eclipse.egit.ui.internal.repository.tree.LocalNode;
import org.eclipse.egit.ui.internal.repository.tree.RemoteTrackingNode;
import org.eclipse.egit.ui.internal.repository.tree.RepositoryNode;
import org.eclipse.egit.ui.test.ContextMenuHelper;
import org.eclipse.egit.ui.view.repositories.GitRepositoriesViewTestUtils;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jgit.lib.ConfigConstants;
+import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotPerspective;
@@ -51,6 +54,8 @@ public class FetchAndMergeActionTest extends LocalRepositoryTestCase {
private static String REMOTE_BRANCHES;
+ private static String LOCAL_BRANCHES;
+
@BeforeClass
public static void setup() throws Exception {
repositoryFile = createProjectAndCommitToRepository();
@@ -62,6 +67,8 @@ public class FetchAndMergeActionTest extends LocalRepositoryTestCase {
Repository repo = lookupRepository(childRepositoryFile);
REMOTE_BRANCHES = provider.getText(new RemoteTrackingNode(
new RepositoryNode(null, repo), repo));
+ LOCAL_BRANCHES = provider.getText(new LocalNode(new RepositoryNode(
+ null, repo), repo));
}
@AfterClass
@@ -130,6 +137,49 @@ public class FetchAndMergeActionTest extends LocalRepositoryTestCase {
assertFalse(oldContent.equals(newContent));
}
+ @Test
+ public void testMergeSquash() throws Exception {
+ prepare();
+ String oldContent = getTestFileContent();
+ RevCommit oldCommit = getCommitForHead();
+ createNewBranch("newBranch", true);
+ touchAndSubmit("branch commit #1");
+ touchAndSubmit("branch commit #2");
+ String branchContent = getTestFileContent();
+ checkoutBranch(Constants.MASTER);
+ assertEquals(oldContent, getTestFileContent());
+
+ mergeBranch("newBranch", true);
+
+ assertEquals(oldCommit, getCommitForHead());
+ assertEquals(branchContent, getTestFileContent());
+ }
+
+ private RevCommit getCommitForHead() throws Exception {
+ Repository repo = lookupRepository(repositoryFile);
+ RevWalk rw = new RevWalk(repo);
+ ObjectId id = repo.resolve(repo.getFullBranch());
+ return rw.parseCommit(id);
+ }
+
+ private void mergeBranch(String branchToMerge, boolean squash) throws Exception {
+ SWTBotShell mergeDialog = openMergeDialog();
+ mergeDialog.bot().tree().getTreeItem(LOCAL_BRANCHES).expand().getNode(branchToMerge).select();
+ if (squash)
+ mergeDialog.bot().radio(UIText.MergeTargetSelectionDialog_MergeTypeSquashButton).click();
+ mergeDialog.bot().button(UIText.MergeTargetSelectionDialog_ButtonMerge).click();
+ bot.shell(UIText.MergeAction_MergeResultTitle).close();
+ }
+
+ private void createNewBranch(String newBranch, boolean checkout) {
+ SWTBotShell newBranchDialog = openCreateBranchDialog();
+ newBranchDialog.bot().comboBoxWithId("BaseBranch").setSelection(0);
+ newBranchDialog.bot().textWithId("BranchName").setText(newBranch);
+ if (!checkout)
+ newBranchDialog.bot().checkBox(UIText.CreateBranchPage_CheckoutButton).deselect();
+ newBranchDialog.bot().button(IDialogConstants.FINISH_LABEL).click();
+ }
+
private SWTBotShell openFetchDialog() throws Exception {
SWTBotTree projectExplorerTree = bot.viewById(
"org.eclipse.jdt.ui.PackageExplorer").bot().tree();
@@ -156,4 +206,30 @@ public class FetchAndMergeActionTest extends LocalRepositoryTestCase {
repo.getBranch()));
return dialog;
}
+
+ private SWTBotShell openCreateBranchDialog() {
+ SWTBotTree projectExplorerTree = bot
+ .viewById("org.eclipse.jdt.ui.PackageExplorer").bot().tree();
+ getProjectItem(projectExplorerTree, PROJ1).select();
+ String[] menuPath = new String[] {
+ util.getPluginLocalizedValue("TeamMenu.label"),
+ util.getPluginLocalizedValue("SwitchToMenu.label"),
+ UIText.SwitchToMenu_NewBranchMenuLabel };
+ ContextMenuHelper.clickContextMenu(projectExplorerTree, menuPath);
+ SWTBotShell dialog = bot
+ .shell(UIText.CreateBranchWizard_NewBranchTitle);
+ return dialog;
+ }
+
+ private void checkoutBranch(String branchToCheckout) {
+ SWTBotTree projectExplorerTree = bot
+ .viewById("org.eclipse.jdt.ui.PackageExplorer").bot().tree();
+ getProjectItem(projectExplorerTree, PROJ1).select();
+ String[] menuPath = new String[] {
+ util.getPluginLocalizedValue("TeamMenu.label"),
+ util.getPluginLocalizedValue("SwitchToMenu.label"),
+ branchToCheckout };
+ ContextMenuHelper.clickContextMenu(projectExplorerTree, menuPath);
+ waitForWorkspaceRefresh();
+ }
}
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 f2424e8..44e2f4a 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
@@ -3399,6 +3399,15 @@ public class UIText extends NLS {
public static String MergeTargetSelectionDialog_TitleMergeWithBranch;
/** */
+ public static String MergeTargetSelectionDialog_MergeTypeGroup;
+
+ /** */
+ public static String MergeTargetSelectionDialog_MergeTypeCommitButton;
+
+ /** */
+ public static String MergeTargetSelectionDialog_MergeTypeSquashButton;
+
+ /** */
public static String MixedResetToRevisionAction_mixedReset;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeActionHandler.java
index d867e32..ee5abe6 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeActionHandler.java
@@ -56,6 +56,7 @@ public class MergeActionHandler extends RepositoryActionHandler {
String jobname = NLS.bind(UIText.MergeAction_JobNameMerge, refName);
final MergeOperation op = new MergeOperation(repository, refName);
+ op.setSquash(mergeTargetSelectionDialog.isMergeSquash());
Job job = new Job(jobname) {
@Override
protected IStatus run(IProgressMonitor monitor) {
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
index 38ec3d5..a0247e5 100644
--- 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
@@ -1,5 +1,7 @@
/*******************************************************************************
* Copyright (c) 2010 SAP AG.
+ * Copyright (C) 2012, Tomasz Zarna <Tomasz.Zarna@pl.ibm.com>
+ *
* 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
@@ -8,6 +10,7 @@
* Contributors:
* Stefan Lay (SAP AG) - initial implementation
* Mathias Kinzler (SAP AG) - use the abstract super class
+ * Tomasz Zarna (IBM) - merge squash, bug 382720
*******************************************************************************/
package org.eclipse.egit.ui.internal.dialogs;
@@ -15,10 +18,17 @@ import java.io.IOException;
import java.text.MessageFormat;
import org.eclipse.egit.ui.UIText;
+import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.window.Window;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+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;
/**
@@ -27,6 +37,8 @@ import org.eclipse.swt.widgets.Shell;
*/
public class MergeTargetSelectionDialog extends AbstractBranchSelectionDialog {
+ private boolean mergeSquash = false;
+
/**
* @param parentShell
* @param repo
@@ -86,4 +98,41 @@ public class MergeTargetSelectionDialog extends AbstractBranchSelectionDialog {
getButton(Window.OK).setEnabled(
!currentSelected && (branchSelected || tagSelected));
}
+
+ @Override
+ protected void createCustomArea(Composite parent) {
+ Composite main = new Composite(parent, SWT.NONE);
+ main.setLayout(new GridLayout(1, false));
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(main);
+ Group g = new Group(main, SWT.NONE);
+ g.setText(UIText.MergeTargetSelectionDialog_MergeTypeGroup);
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(g);
+ g.setLayout(new GridLayout(1, false));
+
+ Button commit = new Button(g, SWT.RADIO);
+ commit.setSelection(true);
+ commit.setText(UIText.MergeTargetSelectionDialog_MergeTypeCommitButton);
+ commit.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ if (((Button) event.widget).getSelection())
+ mergeSquash = false;
+ }
+ });
+
+ Button squash = new Button(g, SWT.RADIO);
+ squash.setText(UIText.MergeTargetSelectionDialog_MergeTypeSquashButton);
+ squash.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ if (((Button) event.widget).getSelection())
+ mergeSquash = true;
+ }
+ });
+ }
+
+ /**
+ * @return whether the merge is to be squashed
+ */
+ public boolean isMergeSquash() {
+ return mergeSquash;
+ }
}
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 ec97c8a..98cc58c 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
@@ -964,6 +964,9 @@ MergeTargetSelectionDialog_SelectRef=Select a branch or tag to merge into the cu
MergeTargetSelectionDialog_SelectRefWithBranch=Select a branch or tag to merge into the ''{0}'' branch
MergeTargetSelectionDialog_TitleMerge=Merge Branch
MergeTargetSelectionDialog_TitleMergeWithBranch=Merge ''{0}''
+MergeTargetSelectionDialog_MergeTypeGroup=Merge options
+MergeTargetSelectionDialog_MergeTypeCommitButton=&Commit (commit the result)
+MergeTargetSelectionDialog_MergeTypeSquashButton=&Squash (do not make a commit)
DecoratorPreferencesPage_addVariablesTitle=Add Variables
DecoratorPreferencesPage_addVariablesAction=Add &Variables...