Search in sources :

Example 1 with BranchRebaseMode

use of org.eclipse.jgit.lib.BranchConfig.BranchRebaseMode in project egit by eclipse.

the class GitRepositoriesViewBranchHandlingTest method testBranchConfiguration.

@Test
public void testBranchConfiguration() throws Exception {
    Repository repo = lookupRepository(clonedRepositoryFile);
    try (Git git = new Git(repo)) {
        git.branchCreate().setName("configTest").setStartPoint("refs/remotes/origin/master").setUpstreamMode(SetupUpstreamMode.TRACK).call();
    }
    BranchRebaseMode rebase = repo.getConfig().getEnum(BranchRebaseMode.values(), ConfigConstants.CONFIG_BRANCH_SECTION, "configTest", ConfigConstants.CONFIG_KEY_REBASE, BranchRebaseMode.NONE);
    assertEquals(BranchRebaseMode.NONE, rebase);
    SWTBotView view = getOrOpenView();
    SWTBotTreeItem localItem = myRepoViewUtil.getLocalBranchesItem(view.bot().tree(), clonedRepositoryFile);
    TestUtil.expandAndWait(localItem).getNode("configTest").select();
    ContextMenuHelper.clickContextMenuSync(view.bot().tree(), myUtil.getPluginLocalizedValue("ShowIn"), "Properties");
    SWTBotView propsView = bot.viewById(IPageLayout.ID_PROP_SHEET);
    SWTBotTreeItem rootItem = propsView.bot().tree().getTreeItem(UIText.BranchPropertySource_UpstreamConfigurationCategory);
    SWTBotTreeItem rebaseItem = TestUtil.expandAndWait(rootItem).getNode(UIText.BranchPropertySource_RebaseDescriptor);
    assertEquals(UIText.BranchPropertySource_ValueNotSet, rebaseItem.cell(1));
    SWTBotTreeItem remoteItem = rootItem.getNode(UIText.BranchPropertySource_RemoteDescriptor);
    assertEquals("origin", remoteItem.cell(1));
    SWTBotTreeItem upstreamItem = rootItem.getNode(UIText.BranchPropertySource_UpstreamBranchDescriptor);
    assertEquals("refs/heads/master", upstreamItem.cell(1));
    view = getOrOpenView();
    localItem = myRepoViewUtil.getLocalBranchesItem(view.bot().tree(), clonedRepositoryFile);
    TestUtil.expandAndWait(localItem).getNode("configTest").select();
    ContextMenuHelper.clickContextMenu(view.bot().tree(), myUtil.getPluginLocalizedValue("ConfigurBranchCommand.label"));
    SWTBotShell configureBranchDialog = bot.shell(UIText.BranchConfigurationDialog_BranchConfigurationTitle);
    assertEquals(MessageFormat.format(UIText.BranchConfigurationDialog_EditBranchConfigMessage, "configTest"), configureBranchDialog.bot().text().getText());
    assertEquals("refs/heads/master", configureBranchDialog.bot().comboBoxWithLabel(UIText.BranchConfigurationDialog_UpstreamBranchLabel).getText());
    assertEquals("origin", configureBranchDialog.bot().comboBoxWithLabel(UIText.BranchConfigurationDialog_RemoteLabel).getText());
    assertEquals(UIText.BranchRebaseMode_None, configureBranchDialog.bot().comboBoxWithLabel(UIText.BranchRebaseModeCombo_RebaseModeLabel).getText());
    configureBranchDialog.bot().comboBoxWithLabel(UIText.BranchRebaseModeCombo_RebaseModeLabel).setSelection(0);
    // add a listener to wait for the configuration changed event
    final AtomicBoolean changed = new AtomicBoolean();
    ConfigChangedListener listener = new ConfigChangedListener() {

        @Override
        public void onConfigChanged(ConfigChangedEvent event) {
            changed.set(true);
        }
    };
    ListenerHandle handle = repo.getConfig().addChangeListener(listener);
    // only now click ok
    configureBranchDialog.bot().button("OK").click();
    // cleanup behind ourselves
    handle.remove();
    if (!changed.get())
        fail("We should have received a config change event");
    // Repo view updates itself after config change.
    refreshAndWait();
    rebase = repo.getConfig().getEnum(BranchRebaseMode.values(), ConfigConstants.CONFIG_BRANCH_SECTION, "configTest", ConfigConstants.CONFIG_KEY_REBASE, BranchRebaseMode.NONE);
    assertEquals(BranchRebaseMode.REBASE, rebase);
    localItem = myRepoViewUtil.getLocalBranchesItem(view.bot().tree(), clonedRepositoryFile);
    TestUtil.expandAndWait(localItem).getNode("configTest").select();
    ContextMenuHelper.clickContextMenu(view.bot().tree(), myUtil.getPluginLocalizedValue("ShowIn"), "Properties");
    propsView = bot.viewById(IPageLayout.ID_PROP_SHEET);
    rootItem = propsView.bot().tree().getTreeItem(UIText.BranchPropertySource_UpstreamConfigurationCategory);
    rebaseItem = TestUtil.expandAndWait(rootItem).getNode(UIText.BranchPropertySource_RebaseDescriptor);
    assertEquals("true", rebaseItem.cell(1));
}
Also used : BranchRebaseMode(org.eclipse.jgit.lib.BranchConfig.BranchRebaseMode) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConfigChangedListener(org.eclipse.jgit.events.ConfigChangedListener) Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) ListenerHandle(org.eclipse.jgit.events.ListenerHandle) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) SWTBotView(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) ConfigChangedEvent(org.eclipse.jgit.events.ConfigChangedEvent) Test(org.junit.Test)

Example 2 with BranchRebaseMode

use of org.eclipse.jgit.lib.BranchConfig.BranchRebaseMode in project egit by eclipse.

the class BranchConfigurationDialog method okPressed.

@Override
protected void okPressed() {
    try {
        String merge = branchText.getText();
        if (merge.length() > 0) {
            myConfig.setString(ConfigConstants.CONFIG_BRANCH_SECTION, myBranchName, ConfigConstants.CONFIG_KEY_MERGE, merge);
        } else {
            myConfig.unset(ConfigConstants.CONFIG_BRANCH_SECTION, myBranchName, ConfigConstants.CONFIG_KEY_MERGE);
        }
        String remote = remoteText.getText();
        if (remote.length() > 0) {
            myConfig.setString(ConfigConstants.CONFIG_BRANCH_SECTION, myBranchName, ConfigConstants.CONFIG_KEY_REMOTE, remote);
        } else {
            myConfig.unset(ConfigConstants.CONFIG_BRANCH_SECTION, myBranchName, ConfigConstants.CONFIG_KEY_REMOTE);
        }
        BranchRebaseMode rebaseMode = rebase.getRebaseMode();
        if (rebaseMode == null) {
            myConfig.unset(ConfigConstants.CONFIG_BRANCH_SECTION, myBranchName, ConfigConstants.CONFIG_KEY_REBASE);
        } else {
            myConfig.setEnum(ConfigConstants.CONFIG_BRANCH_SECTION, myBranchName, ConfigConstants.CONFIG_KEY_REBASE, rebaseMode);
        }
        try {
            myConfig.save();
            super.okPressed();
        } catch (IOException e) {
            Activator.handleError(UIText.BranchConfigurationDialog_SaveBranchConfigFailed, e, true);
        }
    } catch (RuntimeException e) {
        Activator.handleError(e.getMessage(), e, true);
    }
}
Also used : BranchRebaseMode(org.eclipse.jgit.lib.BranchConfig.BranchRebaseMode) IOException(java.io.IOException)

Example 3 with BranchRebaseMode

use of org.eclipse.jgit.lib.BranchConfig.BranchRebaseMode in project egit by eclipse.

the class RebaseCurrentRefCommand method setRef.

private void setRef(ExecutionEvent event) throws ExecutionException {
    ISelection currentSelection = getCurrentSelectionChecked(event);
    if (currentSelection instanceof IStructuredSelection) {
        IStructuredSelection selection = (IStructuredSelection) currentSelection;
        Object selected = selection.getFirstElement();
        ref = getRef(selected);
    } else
        ref = null;
    Object context = event.getApplicationContext();
    if (!(context instanceof IEvaluationContext))
        return;
    final Repository repository = SelectionUtils.getRepository((IEvaluationContext) context);
    if (repository == null)
        return;
    BasicConfigurationDialog.show(repository);
    String currentFullBranch = getFullBranch(repository);
    if (ref != null && ref.getName().equals(currentFullBranch))
        ref = null;
    if (ref == null) {
        RebaseTargetSelectionDialog rebaseTargetSelectionDialog = new RebaseTargetSelectionDialog(getShell(event), repository);
        if (rebaseTargetSelectionDialog.open() == IDialogConstants.OK_ID) {
            String refName = rebaseTargetSelectionDialog.getRefName();
            try {
                ref = repository.findRef(refName);
            } catch (IOException e) {
                throw new ExecutionException(e.getMessage(), e);
            }
            interactive = rebaseTargetSelectionDialog.isInteractive();
            preserveMerges = rebaseTargetSelectionDialog.isPreserveMerges();
        } else {
            return;
        }
    } else {
        String branchName = Repository.shortenRefName(currentFullBranch);
        Config cfg = repository.getConfig();
        BranchRebaseMode rebase = cfg.getEnum(BranchRebaseMode.values(), ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REBASE, BranchRebaseMode.NONE);
        preserveMerges = rebase == BranchRebaseMode.PRESERVE;
        interactive = rebase == BranchRebaseMode.INTERACTIVE;
    }
    jobname = NLS.bind(UIText.RebaseCurrentRefCommand_RebasingCurrentJobName, Repository.shortenRefName(currentFullBranch), ref.getName());
}
Also used : RebaseTargetSelectionDialog(org.eclipse.egit.ui.internal.dialogs.RebaseTargetSelectionDialog) BranchRebaseMode(org.eclipse.jgit.lib.BranchConfig.BranchRebaseMode) Repository(org.eclipse.jgit.lib.Repository) Config(org.eclipse.jgit.lib.Config) ISelection(org.eclipse.jface.viewers.ISelection) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 4 with BranchRebaseMode

use of org.eclipse.jgit.lib.BranchConfig.BranchRebaseMode in project egit by eclipse.

the class PushBranchPage method setDefaultUpstreamConfig.

private void setDefaultUpstreamConfig() {
    if (this.ref != null) {
        String branchName = Repository.shortenRefName(ref.getName());
        BranchConfig branchConfig = new BranchConfig(repository.getConfig(), branchName);
        boolean alreadyConfigured = branchConfig.getMerge() != null;
        BranchRebaseMode config;
        if (alreadyConfigured) {
            config = PullCommand.getRebaseMode(branchName, repository.getConfig());
        } else {
            config = CreateLocalBranchOperation.getDefaultUpstreamConfig(repository, Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + // $NON-NLS-1$
            branchName);
        }
        this.upstreamConfig = config;
        this.upstreamConfigComponent.setUpstreamConfig(this.upstreamConfig);
    }
}
Also used : BranchRebaseMode(org.eclipse.jgit.lib.BranchConfig.BranchRebaseMode) BranchConfig(org.eclipse.jgit.lib.BranchConfig)

Example 5 with BranchRebaseMode

use of org.eclipse.jgit.lib.BranchConfig.BranchRebaseMode in project egit by eclipse.

the class PushBranchWizard method configureUpstream.

private void configureUpstream() throws IOException {
    if (this.ref == null) {
        // Don't configure upstream for detached HEAD
        return;
    }
    String remoteName = getRemoteName();
    String fullRemoteBranchName = pushBranchPage.getFullRemoteReference();
    String localBranchName = Repository.shortenRefName(this.ref.getName());
    StoredConfig config = repository.getConfig();
    config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, localBranchName, ConfigConstants.CONFIG_KEY_REMOTE, remoteName);
    config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, localBranchName, ConfigConstants.CONFIG_KEY_MERGE, fullRemoteBranchName);
    BranchRebaseMode rebaseMode = pushBranchPage.getUpstreamConfig();
    if (rebaseMode != null) {
        config.setEnum(ConfigConstants.CONFIG_BRANCH_SECTION, localBranchName, ConfigConstants.CONFIG_KEY_REBASE, rebaseMode);
    }
    config.save();
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) BranchRebaseMode(org.eclipse.jgit.lib.BranchConfig.BranchRebaseMode)

Aggregations

BranchRebaseMode (org.eclipse.jgit.lib.BranchConfig.BranchRebaseMode)10 IOException (java.io.IOException)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 BranchConfig (org.eclipse.jgit.lib.BranchConfig)2 Config (org.eclipse.jgit.lib.Config)2 Repository (org.eclipse.jgit.lib.Repository)2 StoredConfig (org.eclipse.jgit.lib.StoredConfig)2 Button (org.eclipse.swt.widgets.Button)2 Composite (org.eclipse.swt.widgets.Composite)2 Label (org.eclipse.swt.widgets.Label)2 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)1 UIText (org.eclipse.egit.ui.internal.UIText)1 AsynchronousRefProposalProvider (org.eclipse.egit.ui.internal.components.AsynchronousRefProposalProvider)1 BranchNameNormalizer (org.eclipse.egit.ui.internal.components.BranchNameNormalizer)1