diff options
author | Max Hohenegger | 2015-08-28 21:44:57 +0000 |
---|---|---|
committer | Matthias Sohn | 2015-09-10 11:18:50 +0000 |
commit | 02c3e6afc1e9e0b3a90e78e37ee04c14db2159fb (patch) | |
tree | 7bcf811d502a52fd272b35c5599f1dd5194eab1c /org.eclipse.egit.ui.test | |
parent | 03f3f339162b5f2968ebba8e763a96a97d161728 (diff) | |
download | egit-02c3e6afc1e9e0b3a90e78e37ee04c14db2159fb.tar.gz egit-02c3e6afc1e9e0b3a90e78e37ee04c14db2159fb.tar.xz egit-02c3e6afc1e9e0b3a90e78e37ee04c14db2159fb.zip |
Fixed: Specifying non-existing master does not abort initialization
- abort init operation if master is missing
- added validator for missing master branch
- ask user to create master branch
- ask user to create initial commit if repository is empty
- added control decorations to hint at source of problem
- adjusted tests
Bug: 475788
Change-Id: Ief9b1a361a3dce83358e7b84034bb6a477ec92e4
Signed-off-by: Max Hohenegger <eclipse@hohenegger.eu>
Diffstat (limited to 'org.eclipse.egit.ui.test')
-rw-r--r-- | org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/InitHandlerTest.java | 136 |
1 files changed, 116 insertions, 20 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/InitHandlerTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/InitHandlerTest.java index cc16bef23f..07786071c4 100644 --- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/InitHandlerTest.java +++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/InitHandlerTest.java @@ -8,18 +8,34 @@ *******************************************************************************/ package org.eclipse.egit.ui.gitflow; +import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_developBranch; +import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_featureBranchPrefix; +import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_hotfixBranchPrefix; +import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_masterBranch; +import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_releaseBranchPrefix; +import static org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_versionTagPrefix; +import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellIsActive; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import java.io.File; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.egit.core.test.TestRepository; import org.eclipse.egit.gitflow.GitFlowConfig; import org.eclipse.egit.gitflow.GitFlowRepository; import org.eclipse.egit.gitflow.ui.Activator; import org.eclipse.egit.gitflow.ui.internal.JobFamilies; - -import static org.eclipse.egit.gitflow.ui.internal.UIText.*; - +import org.eclipse.egit.gitflow.ui.internal.UIText; import org.eclipse.egit.ui.test.ContextMenuHelper; import org.eclipse.egit.ui.test.TestUtil; +import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.Repository; import org.eclipse.swtbot.eclipse.finder.waits.Conditions; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton; @@ -35,7 +51,11 @@ import org.junit.runner.RunWith; @RunWith(SWTBotJunit4ClassRunner.class) public class InitHandlerTest extends AbstractGitflowHandlerTest { private static final String DEVELOP_BRANCH = "a"; - private static final String MASTER_BRANCH = "b"; + + private static final String MASTER_BRANCH_MISSING = "b"; + + private static final String MASTER_BRANCH = "master"; + private static final String FEATURE_BRANCH_PREFIX = "c"; private static final String RELEASE_BRANCH_PREFIX = "d"; private static final String HOTFIX_BRANCH_PREFIX = "e"; @@ -45,7 +65,12 @@ public class InitHandlerTest extends AbstractGitflowHandlerTest { @Test public void testInit() throws Exception { - init(); + selectProject(PROJ1); + clickInit(); + fillDialog(MASTER_BRANCH); + + bot.waitUntil(Conditions.waitForJobs(JobFamilies.GITFLOW_FAMILY, + "Git flow jobs")); GitFlowRepository gitFlowRepository = new GitFlowRepository(repository); GitFlowConfig config = gitFlowRepository.getConfig(); @@ -56,40 +81,111 @@ public class InitHandlerTest extends AbstractGitflowHandlerTest { assertEquals(RELEASE_BRANCH_PREFIX, config.getReleasePrefix()); assertEquals(HOTFIX_BRANCH_PREFIX, config.getHotfixPrefix()); assertEquals(VERSION_TAG_PREFIX, config.getVersionTagPrefix()); + } + + @Test + public void testInitMissingMaster() throws Exception { + selectProject(PROJ1); + clickInit(); + fillDialog(MASTER_BRANCH_MISSING); + + bot.waitUntil(shellIsActive(UIText.InitDialog_masterBranchIsMissing)); + bot.button("Yes").click(); + bot.waitUntil(Conditions.waitForJobs(JobFamilies.GITFLOW_FAMILY, + "Git flow jobs")); + + GitFlowRepository gitFlowRepository = new GitFlowRepository(repository); + GitFlowConfig config = gitFlowRepository.getConfig(); + + assertEquals(DEVELOP_BRANCH, repository.getBranch()); + assertEquals(MASTER_BRANCH_MISSING, config.getMaster()); + assertEquals(FEATURE_BRANCH_PREFIX, config.getFeaturePrefix()); + assertEquals(RELEASE_BRANCH_PREFIX, config.getReleasePrefix()); + assertEquals(HOTFIX_BRANCH_PREFIX, config.getHotfixPrefix()); + assertEquals(VERSION_TAG_PREFIX, config.getVersionTagPrefix()); + + assertNotNull(repository.getRef(Constants.R_HEADS + DEVELOP_BRANCH)); + } + + @Test + public void testInitEmptyRepoMissingMaster() throws Exception { + String projectName = "AnyProjectName"; + TestRepository testRepository = createAndShare(projectName); + + selectProject(projectName); + clickInit(); + bot.button("Yes").click(); + fillDialog(MASTER_BRANCH_MISSING); + bot.waitUntil(shellIsActive(UIText.InitDialog_masterBranchIsMissing)); + bot.button("Yes").click(); + bot.waitUntil(Conditions.waitForJobs(JobFamilies.GITFLOW_FAMILY, + "Git flow jobs")); + + Repository localRepository = testRepository.getRepository(); + GitFlowRepository gitFlowRepository = new GitFlowRepository(localRepository); + GitFlowConfig config = gitFlowRepository.getConfig(); + + assertEquals(DEVELOP_BRANCH, localRepository.getBranch()); + assertEquals(MASTER_BRANCH_MISSING, config.getMaster()); + assertEquals(FEATURE_BRANCH_PREFIX, config.getFeaturePrefix()); + assertEquals(RELEASE_BRANCH_PREFIX, config.getReleasePrefix()); + assertEquals(HOTFIX_BRANCH_PREFIX, config.getHotfixPrefix()); + assertEquals(VERSION_TAG_PREFIX, config.getVersionTagPrefix()); + assertNotNull(localRepository.getRef(Constants.R_HEADS + DEVELOP_BRANCH)); } - private void init() { + private void selectProject(String projectName) { final SWTBotTree projectExplorerTree = TestUtil.getExplorerTree(); - getProjectItem(projectExplorerTree, PROJ1).select(); - final String[] menuPath = new String[] { - util.getPluginLocalizedValue("TeamMenu.label"), - util.getPluginLocalizedValue("TeamGitFlowInit.name", false, Activator.getDefault().getBundle()) }; - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - @Override - public void run() { - ContextMenuHelper.clickContextMenuSync(projectExplorerTree, - menuPath); - } - }); + getProjectItem(projectExplorerTree, projectName).select(); + } + private void fillDialog(String masterBranch) { SWTBotText developText = bot.textWithLabel(InitDialog_developBranch); developText.selectAll(); developText.typeText(ILLEGAL_BRANCH_NAME); - SWTBotButton ok = bot.button("OK"); assertFalse(ok.isEnabled()); typeInto(InitDialog_developBranch, DEVELOP_BRANCH); - typeInto(InitDialog_masterBranch, MASTER_BRANCH); + typeInto(InitDialog_masterBranch, masterBranch); typeInto(InitDialog_featureBranchPrefix, FEATURE_BRANCH_PREFIX); typeInto(InitDialog_releaseBranchPrefix, RELEASE_BRANCH_PREFIX); typeInto(InitDialog_hotfixBranchPrefix, HOTFIX_BRANCH_PREFIX); typeInto(InitDialog_versionTagPrefix, VERSION_TAG_PREFIX); ok.click(); - bot.waitUntil(Conditions.waitForJobs(JobFamilies.GITFLOW_FAMILY, "Git flow jobs")); + } + + private void clickInit() { + final SWTBotTree projectExplorerTree = TestUtil.getExplorerTree(); + final String[] menuPath = new String[] { + util.getPluginLocalizedValue("TeamMenu.label"), + util.getPluginLocalizedValue("TeamGitFlowInit.name", false, Activator.getDefault().getBundle()) }; + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + ContextMenuHelper.clickContextMenuSync(projectExplorerTree, + menuPath); + } + }); + } + + private TestRepository createAndShare(String projectName) throws Exception { + IProgressMonitor progressMonitor = new NullProgressMonitor(); + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IProject project = root.getProject(projectName); + project.create(progressMonitor); + project.open(progressMonitor); + TestUtil.waitForJobs(50, 5000); + + File gitDir = new File(project.getProject().getLocationURI().getPath(), Constants.DOT_GIT); + TestRepository testRepository = new TestRepository(gitDir); + testRepository.connect(project.getProject()); + TestUtil.waitForJobs(50, 5000); + + return testRepository; } private void typeInto(String textLabel, String textInput) { |