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