Search in sources :

Example 1 with BranchConfigurations

use of com.oxygenxml.git.view.branches.BranchConfigurations in project oxygen-git-client-addon by oxygenxml.

the class CurrentBranchRemotesDialog method addRemoteBranches.

/**
 * Add remote branches for current repository.
 *
 * @param branchesToAdd List to add the branches.
 *
 * @return <code>true</code> if at least a branch is founded.
 *
 * @throws URISyntaxException
 * @throws NoRepositorySelected
 */
private boolean addRemoteBranches(final List<RemoteBranchItem> branchesToAdd) throws URISyntaxException, NoRepositorySelected {
    final StoredConfig config = GitAccess.getInstance().getRepository().getConfig();
    final BranchConfigurations branchConfig = new BranchConfigurations(config, currentBranch);
    final List<String> remotesNames = new ArrayList<>(GitAccess.getInstance().getRemotesFromConfig().keySet());
    boolean foundedBranchRemoteForCurrentLocalBranch = false;
    boolean existsRemotes = false;
    for (String remote : remotesNames) {
        existsRemotes = true;
        final URIish sourceURL = new URIish(config.getString(ConfigConstants.CONFIG_REMOTE_SECTION, remote, ConfigConstants.CONFIG_KEY_URL));
        final Collection<Ref> branchesConfig = GitAccess.getInstance().doListRemoteBranchesInternal(sourceURL, null);
        for (Ref branch : branchesConfig) {
            final String branchName = branch.getName();
            final String remoteC = branchConfig.getRemote();
            final String mergeC = branchConfig.getMerge();
            if (remoteC != null && remoteC.equals(remote) && mergeC != null && mergeC.equals(branchName)) {
                final RemoteBranchItem remoteItem = new RemoteBranchItem(remote, branchName);
                foundedBranchRemoteForCurrentLocalBranch = true;
                remoteItem.setFirstSelection(true);
                branchesToAdd.add(remoteItem);
            } else {
                branchesToAdd.add(new RemoteBranchItem(remote, branchName));
            }
        }
    }
    if (!foundedBranchRemoteForCurrentLocalBranch) {
        final RemoteBranchItem remoteItem = new RemoteBranchItem(null, null);
        remoteItem.setFirstSelection(true);
        remoteBranchItems.addItem(remoteItem);
        remoteBranchItems.setSelectedIndex(remoteBranchItems.getItemCount() - 1);
    }
    return existsRemotes;
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) URIish(org.eclipse.jgit.transport.URIish) Ref(org.eclipse.jgit.lib.Ref) BranchConfigurations(com.oxygenxml.git.view.branches.BranchConfigurations) ArrayList(java.util.ArrayList)

Example 2 with BranchConfigurations

use of com.oxygenxml.git.view.branches.BranchConfigurations in project oxygen-git-client-addon by oxygenxml.

the class CurrentBranchRemotesDialog method doOK.

@Override
protected void doOK() {
    RemoteBranchItem currentSelectedBranch = (RemoteBranchItem) remoteBranchItems.getSelectedItem();
    if (!currentSelectedBranch.isUndefined() && !currentSelectedBranch.isFirstSelection()) {
        try {
            BranchConfigurations branchConfig = new BranchConfigurations(GitAccess.getInstance().getRepository().getConfig(), currentBranch);
            branchConfig.setRemote(currentSelectedBranch.remote);
            branchConfig.setMerge(currentSelectedBranch.branch);
            GitAccess.getInstance().updateConfigFile();
        } catch (NoRepositorySelected e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
    super.doOK();
}
Also used : NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) BranchConfigurations(com.oxygenxml.git.view.branches.BranchConfigurations)

Aggregations

BranchConfigurations (com.oxygenxml.git.view.branches.BranchConfigurations)2 NoRepositorySelected (com.oxygenxml.git.service.NoRepositorySelected)1 ArrayList (java.util.ArrayList)1 Ref (org.eclipse.jgit.lib.Ref)1 StoredConfig (org.eclipse.jgit.lib.StoredConfig)1 URIish (org.eclipse.jgit.transport.URIish)1