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

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

Introduction

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

Prototype

String CONFIG_BRANCH_SECTION

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

Click Source Link

Document

The "branch" section

Usage

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

License:Open Source License

/**
 * Add a warning about this remote being used by other branches
 *
 * @param parent/*w ww.  j  a  v a  2  s  .c om*/
 */
private void addDefaultOriginWarning(Composite parent) {
    List<String> otherBranches = new ArrayList<>();
    String currentBranch;
    try {
        currentBranch = getRepository().getBranch();
    } catch (IOException e) {
        // just don't show this warning
        return;
    }
    String currentRemote = getConfig().getName();
    Config repositoryConfig = getRepository().getConfig();
    Set<String> branches = repositoryConfig.getSubsections(ConfigConstants.CONFIG_BRANCH_SECTION);
    for (String branch : branches) {
        if (branch.equals(currentBranch)) {
            continue;
        }
        String remote = repositoryConfig.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branch,
                ConfigConstants.CONFIG_KEY_REMOTE);
        if ((remote == null && currentRemote.equals(Constants.DEFAULT_REMOTE_NAME))
                || (remote != null && remote.equals(currentRemote))) {
            otherBranches.add(branch);
        }
    }
    if (otherBranches.isEmpty()) {
        return;
    }
    Composite warningAboutOrigin = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(warningAboutOrigin);
    Label warningLabel = new Label(warningAboutOrigin, SWT.NONE);
    warningLabel
            .setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK));
    Text warningText = new Text(warningAboutOrigin, SWT.READ_ONLY);
    warningText.setText(NLS.bind(UIText.AbstractConfigureRemoteDialog_ReusedRemoteWarning,
            getConfig().getName(), Integer.valueOf(otherBranches.size())));
    warningText.setToolTipText(otherBranches.toString());
    GridDataFactory.fillDefaults().grab(true, false).applyTo(warningLabel);
}

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 a  2s. c  o 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 {//from ww  w .  java2  s  .  c o  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.fetch.SimpleConfigureFetchDialog.java

License:Open Source License

/**
 * @param repository//  www.  j  a v a2  s. c o  m
 * @return the configured remote for the current branch, or the default
 *         remote; <code>null</code> if a local branch is checked out that
 *         points to "." as remote
 */
public static RemoteConfig getConfiguredRemote(Repository repository) {
    String branch;
    try {
        branch = repository.getBranch();
    } catch (IOException e) {
        Activator.handleError(e.getMessage(), e, true);
        return null;
    }
    if (branch == null)
        return null;

    String remoteName;
    if (ObjectId.isId(branch))
        remoteName = Constants.DEFAULT_REMOTE_NAME;
    else
        remoteName = repository.getConfig().getString(ConfigConstants.CONFIG_BRANCH_SECTION, branch,
                ConfigConstants.CONFIG_REMOTE_SECTION);

    // check if we find the configured and default Remotes
    List<RemoteConfig> allRemotes;
    try {
        allRemotes = RemoteConfig.getAllRemoteConfigs(repository.getConfig());
    } catch (URISyntaxException e) {
        allRemotes = new ArrayList<RemoteConfig>();
    }

    RemoteConfig defaultConfig = null;
    RemoteConfig configuredConfig = null;
    for (RemoteConfig config : allRemotes) {
        if (config.getName().equals(Constants.DEFAULT_REMOTE_NAME))
            defaultConfig = config;
        if (remoteName != null && config.getName().equals(remoteName))
            configuredConfig = config;
    }

    RemoteConfig configToUse = configuredConfig != null ? configuredConfig : defaultConfig;
    return configToUse;
}

From source file:org.eclipse.egit.ui.internal.fetch.SimpleConfigureFetchDialog.java

License:Open Source License

/**
 * Add a warning about this remote being used by other branches
 *
 * @param parent/*from w  w w  .  j a v a  2  s  .  c o  m*/
 */
private void addDefaultOriginWarningIfNeeded(Composite parent) {
    if (!showBranchInfo)
        return;
    List<String> otherBranches = new ArrayList<String>();
    String currentBranch;
    try {
        currentBranch = repository.getBranch();
    } catch (IOException e) {
        // just don't show this warning
        return;
    }
    String currentRemote = config.getName();
    Config repositoryConfig = repository.getConfig();
    Set<String> branches = repositoryConfig.getSubsections(ConfigConstants.CONFIG_BRANCH_SECTION);
    for (String branch : branches) {
        if (branch.equals(currentBranch))
            continue;
        String remote = repositoryConfig.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branch,
                ConfigConstants.CONFIG_KEY_REMOTE);
        if ((remote == null && currentRemote.equals(Constants.DEFAULT_REMOTE_NAME))
                || (remote != null && remote.equals(currentRemote)))
            otherBranches.add(branch);
    }
    if (otherBranches.isEmpty())
        return;

    Composite warningAboutOrigin = new Composite(parent, SWT.NONE);
    warningAboutOrigin.setLayout(new GridLayout(2, false));
    Label warningLabel = new Label(warningAboutOrigin, SWT.NONE);
    warningLabel
            .setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK));
    Text warningText = new Text(warningAboutOrigin, SWT.READ_ONLY);
    warningText.setText(NLS.bind(UIText.SimpleConfigureFetchDialog_ReusedRemoteWarning, config.getName(),
            Integer.valueOf(otherBranches.size())));
    warningText.setToolTipText(otherBranches.toString());
    GridDataFactory.fillDefaults().grab(true, false).applyTo(warningLabel);
}

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  w  w. 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  ww w . j  a v  a2 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();//w  ww .j a v a2s.com
    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

@Test
public void pushWithLocalUpstreamConfiguration() throws Exception {
    checkoutNewLocalBranch("foo");
    // Existing configuration
    repository.getConfig().setString(ConfigConstants.CONFIG_BRANCH_SECTION, "foo",
            ConfigConstants.CONFIG_KEY_REMOTE, ".");
    repository.getConfig().setString(ConfigConstants.CONFIG_BRANCH_SECTION, "foo",
            ConfigConstants.CONFIG_KEY_MERGE, "refs/heads/master");

    PushBranchWizardTester wizard = PushBranchWizardTester.startWizard(selectProject(), "foo");
    wizard.selectRemote("fetch");
    wizard.assertBranchName("foo");
    wizard.assertMergeSelected();/*  w w  w. j av  a  2 s .c o  m*/
    assertTrue(wizard.isUpstreamConfigOverwriteWarningShown());
    wizard.deselectConfigureUpstream();
    assertFalse(wizard.isUpstreamConfigOverwriteWarningShown());
    wizard.selectMerge();
    wizard.next();
    wizard.finish();

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

    // Newly configured
    assertBranchConfig("foo", "fetch", "refs/heads/foo", "false");
}

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));
}