Example usage for org.eclipse.jgit.lib ConfigConstants CONFIG_KEY_REBASE

List of usage examples for org.eclipse.jgit.lib ConfigConstants CONFIG_KEY_REBASE

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib ConfigConstants CONFIG_KEY_REBASE.

Prototype

String CONFIG_KEY_REBASE

To view the source code for org.eclipse.jgit.lib ConfigConstants CONFIG_KEY_REBASE.

Click Source Link

Document

The "rebase" key

Usage

From source file:org.eclipse.egit.ui.internal.dialogs.BranchConfigurationDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite main = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(main);
    GridDataFactory.fillDefaults().grab(true, false).indent(5, 5).applyTo(main);
    Label branchLabel = new Label(main, SWT.NONE);
    branchLabel.setText(UIText.BranchConfigurationDialog_UpstreamBranchLabel);
    branchText = new Combo(main, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(branchText);

    try {//from w  w w  .  jav  a2  s .co  m
        for (Ref ref : myRepository.getRefDatabase().getRefs(Constants.R_HEADS).values())
            branchText.add(ref.getName());
        for (Ref ref : myRepository.getRefDatabase().getRefs(Constants.R_REMOTES).values())
            branchText.add(ref.getName());
    } catch (IOException e) {
        Activator.logError(UIText.BranchConfigurationDialog_ExceptionGettingRefs, e);
    }

    Label remoteLabel = new Label(main, SWT.NONE);
    remoteLabel.setText(UIText.BranchConfigurationDialog_RemoteLabel);
    remoteText = new Combo(main, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(remoteText);

    // TODO do we have a constant somewhere?
    remoteText.add("."); //$NON-NLS-1$
    for (String remote : myConfig.getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION))
        remoteText.add(remote);

    rebase = new Button(main, SWT.CHECK);
    GridDataFactory.fillDefaults().span(2, 1).applyTo(rebase);
    rebase.setText(UIText.BranchConfigurationDialog_RebaseLabel);

    String branch = myConfig.getString(ConfigConstants.CONFIG_BRANCH_SECTION, myBranchName,
            ConfigConstants.CONFIG_KEY_MERGE);
    if (branch == null)
        branch = ""; //$NON-NLS-1$
    branchText.setText(branch);

    String remote = myConfig.getString(ConfigConstants.CONFIG_BRANCH_SECTION, myBranchName,
            ConfigConstants.CONFIG_KEY_REMOTE);
    if (remote == null)
        remote = ""; //$NON-NLS-1$
    remoteText.setText(remote);

    boolean rebaseFlag = myConfig.getBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, myBranchName,
            ConfigConstants.CONFIG_KEY_REBASE, false);
    rebase.setSelection(rebaseFlag);

    applyDialogFont(main);
    // return result;
    return main;
}

From source file:org.eclipse.egit.ui.internal.dialogs.BranchConfigurationDialog.java

License:Open Source License

@Override
protected void okPressed() {
    try {//www  .  j a  v a  2  s  .co  m
        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);

        boolean rebaseFlag = rebase.getSelection();
        if (rebaseFlag)
            myConfig.setBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, myBranchName,
                    ConfigConstants.CONFIG_KEY_REBASE, true);
        else
            myConfig.unset(ConfigConstants.CONFIG_BRANCH_SECTION, myBranchName,
                    ConfigConstants.CONFIG_KEY_REBASE);
        try {
            myConfig.save();
            super.okPressed();
        } catch (IOException e) {
            Activator.handleError(UIText.BranchConfigurationDialog_SaveBranchConfigFailed, e, true);
        }
    } catch (RuntimeException e) {
        Activator.handleError(e.getMessage(), e, true);
    }
}

From source file:org.eclipse.egit.ui.internal.pull.PullWizard.java

License:Open Source License

private void configureUpstream() throws IOException {
    String fullBranch = this.repository.getFullBranch();
    if (fullBranch == null || !fullBranch.startsWith(Constants.R_HEADS)) {
        // Don't configure upstream for detached HEAD
        return;/*from  w  ww .  j  a v  a  2s.  c o  m*/
    }
    String remoteName = this.page.getRemoteConfig().getName();
    String fullRemoteBranchName = this.page.getFullRemoteReference();

    String localBranchName = this.repository.getBranch();
    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 = this.page.getUpstreamConfig();
    if (rebaseMode != null) {
        config.setEnum(ConfigConstants.CONFIG_BRANCH_SECTION, localBranchName,
                ConfigConstants.CONFIG_KEY_REBASE, rebaseMode);
    }

    config.save();
}

From source file:org.eclipse.egit.ui.internal.push.PushBranchWizard.java

License:Open Source License

private void configureUpstream() throws IOException {
    if (this.ref == null) {
        // Don't configure upstream for detached HEAD
        return;//from   w w  w.j  a v a 2 s.c o  m
    }
    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();
}

From source file:org.eclipse.egit.ui.internal.push.PushBranchWizardTest.java

License:Open Source License

@Test
public void pushWithRemoteUpstreamConfiguration() throws Exception {
    checkoutNewLocalBranch("foo");
    // Existing configuration
    repository.getConfig().setString(ConfigConstants.CONFIG_BRANCH_SECTION, "foo",
            ConfigConstants.CONFIG_KEY_REMOTE, "fetch");
    repository.getConfig().setString(ConfigConstants.CONFIG_BRANCH_SECTION, "foo",
            ConfigConstants.CONFIG_KEY_MERGE, "refs/heads/foo-on-remote");
    repository.getConfig().setEnum(ConfigConstants.CONFIG_BRANCH_SECTION, "foo",
            ConfigConstants.CONFIG_KEY_REBASE, BranchRebaseMode.REBASE);
    // Make sure the repository does not have autosetuprebase set
    repository.getConfig().setBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, null,
            ConfigConstants.CONFIG_KEY_AUTOSETUPREBASE, false);

    PushBranchWizardTester wizard = PushBranchWizardTester.startWizard(selectProject(), "foo");
    wizard.selectRemote("fetch");
    wizard.assertBranchName("foo-on-remote");
    wizard.assertRebaseSelected();//from  w  w w  . j  a v  a2 s.  c  o m
    assertFalse(wizard.isUpstreamConfigOverwriteWarningShown());
    wizard.selectMerge();
    assertTrue(wizard.isUpstreamConfigOverwriteWarningShown());
    wizard.deselectConfigureUpstream();
    assertFalse(wizard.isUpstreamConfigOverwriteWarningShown());
    wizard.next();
    wizard.finish();

    ObjectId remoteId = remoteRepository.resolve("foo-on-remote");
    ObjectId localId = repository.resolve("foo");
    assertEquals(localId, remoteId);

    // Still configured
    assertBranchConfig("foo", "fetch", "refs/heads/foo-on-remote", "true");
}

From source file:org.eclipse.egit.ui.internal.push.PushBranchWizardTest.java

License:Open Source License

private void assertBranchConfig(String branchName, String remoteName, String mergeRef, String rebase) {
    StoredConfig config = repository.getConfig();
    assertEquals(remoteName, config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
            ConfigConstants.CONFIG_KEY_REMOTE));
    assertEquals(mergeRef, config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
            ConfigConstants.CONFIG_KEY_MERGE));
    assertEquals(rebase, config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
            ConfigConstants.CONFIG_KEY_REBASE));
}

From source file:org.eclipse.egit.ui.internal.repository.BranchPropertySource.java

License:Open Source License

public IPropertyDescriptor[] getPropertyDescriptors() {
    List<IPropertyDescriptor> resultList = new ArrayList<IPropertyDescriptor>();

    PropertyDescriptor desc = new PropertyDescriptor(ConfigConstants.CONFIG_KEY_MERGE,
            UIText.BranchPropertySource_UpstreamBranchDescriptor);
    desc.setCategory(UIText.BranchPropertySource_UpstreamConfigurationCategory);
    resultList.add(desc);//from w  w  w.  j  a  v  a2  s .  c o  m
    desc = new PropertyDescriptor(ConfigConstants.CONFIG_KEY_REMOTE,
            UIText.BranchPropertySource_RemoteDescriptor);
    desc.setCategory(UIText.BranchPropertySource_UpstreamConfigurationCategory);
    resultList.add(desc);
    desc = new PropertyDescriptor(ConfigConstants.CONFIG_KEY_REBASE,
            UIText.BranchPropertySource_RebaseDescriptor);
    desc.setCategory(UIText.BranchPropertySource_UpstreamConfigurationCategory);
    resultList.add(desc);

    return resultList.toArray(new IPropertyDescriptor[0]);
}

From source file:org.eclipse.oomph.gitbash.decorators.BranchDecorator.java

License:Open Source License

private String getDecoration(org.eclipse.egit.ui.internal.repository.tree.RefNode node) {
    String branchName = Repository.shortenRefName(node.getObject().getName());
    Repository repository = node.getRepository();
    StoredConfig config = repository.getConfig();

    String branch = config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
            ConfigConstants.CONFIG_KEY_MERGE);

    if (branch != null) {
        String remote = config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
                ConfigConstants.CONFIG_KEY_REMOTE);

        boolean rebaseFlag = config.getBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
                ConfigConstants.CONFIG_KEY_REBASE, false);

        if (branch.startsWith(DEFAULT_PATH)) {
            branch = branch.substring(DEFAULT_PATH.length());
        }/*w  ww  . j a  v a2 s .  c  om*/

        String prefix = ".".equals(remote) ? "" : remote + "/";
        String result = (rebaseFlag ? "REBASE" : "MERGE") + ": " + prefix + branch;

        try {
            BranchTrackingStatus trackingStatus = BranchTrackingStatus.of(repository, branchName);
            if (trackingStatus != null
                    && (trackingStatus.getAheadCount() != 0 || trackingStatus.getBehindCount() != 0)) {
                result += " " + formatBranchTrackingStatus(trackingStatus);
            }
        } catch (Throwable t) {
            //$FALL-THROUGH$
        }

        return result;
    }

    return null;
}

From source file:org.eclipse.oomph.setup.git.impl.GitCloneTaskImpl.java

License:Open Source License

private static void createBranch(SetupTaskContext context, Git git, String checkoutBranch, String remoteName)
        throws Exception {
    context.log("Creating local branch " + checkoutBranch);

    CreateBranchCommand command = git.branchCreate();
    command.setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM);
    command.setName(checkoutBranch);/*  w ww  .j  a v a2 s .  c  o  m*/
    command.setStartPoint("refs/remotes/" + remoteName + "/" + checkoutBranch);
    command.call();

    StoredConfig config = git.getRepository().getConfig();
    config.setBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, checkoutBranch, ConfigConstants.CONFIG_KEY_REBASE,
            true);
    config.save();
}

From source file:org.flowerplatform.web.git.GitService.java

License:Open Source License

@RemoteInvocation
public ConfigBranchPageDto getConfigBranchData(ServiceInvocationContext context, List<PathFragment> path) {
    try {/*from www . j  av  a 2s.  c  om*/
        RefNode node = (RefNode) GenericTreeStatefulService.getNodeByPathFor(path, null);
        Repository repository = node.getRepository();

        StoredConfig config = repository.getConfig();

        ConfigBranchPageDto dto = new ConfigBranchPageDto();

        Ref branch = (Ref) node.getRef();
        dto.setRef(new GitRef(branch.getName(), Repository.shortenRefName(branch.getName())));

        List<RemoteConfig> remotes = getAllRemotes(context, path);

        String branchName = branch.getName().substring(Constants.R_HEADS.length());
        String branchConfig = config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
                ConfigConstants.CONFIG_KEY_MERGE);

        String remoteConfig = config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
                ConfigConstants.CONFIG_KEY_REMOTE);
        if (remoteConfig == null) {
            remoteConfig = "";
        }
        if (remotes != null) {
            dto.setRemotes(remotes);

            for (RemoteConfig remote : remotes) {
                if (remote.getName().equals(remoteConfig)) {
                    List<Object> branches = getBranches(context, remote.getUri());
                    if (branches != null) {
                        @SuppressWarnings("unchecked")
                        List<GitRef> refs = (List<GitRef>) branches.get(0);
                        for (GitRef ref : refs) {
                            if (ref.getName().equals(branchConfig)) {
                                dto.setSelectedRef(ref);
                                break;
                            }
                        }
                        dto.setRefs(refs);
                    }
                    dto.setSelectedRemote(remote);
                    break;
                }
            }
        }

        boolean rebaseFlag = config.getBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
                ConfigConstants.CONFIG_KEY_REBASE, false);
        dto.setRebase(rebaseFlag);

        return dto;
    } catch (Exception e) {
        logger.debug(CommonPlugin.getInstance().getMessage("error"), path, e);
        context.getCommunicationChannel().appendOrSendCommand(
                new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"),
                        e.getMessage(), DisplaySimpleMessageClientCommand.ICON_ERROR));
        return null;
    }
}