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