use of org.eclipse.egit.core.op.BranchOperation in project egit by eclipse.
the class GitRepositoriesViewBranchHandlingTest method testCheckoutRemote.
@Test
public void testCheckoutRemote() throws Exception {
Repository repo = lookupRepository(clonedRepositoryFile);
BranchOperation bop = new BranchOperation(repo, "refs/heads/master");
bop.execute(null);
assertEquals("master", repo.getBranch());
SWTBotTree tree = getOrOpenView().bot().tree();
SWTBotTreeItem item = myRepoViewUtil.getLocalBranchesItem(tree, clonedRepositoryFile).expand();
touchAndSubmit(null);
refreshAndWait();
item = TestUtil.expandAndWait(myRepoViewUtil.getRemoteBranchesItem(tree, clonedRepositoryFile));
List<String> children = item.getNodes();
assertEquals("Wrong number of remote children", 2, children.size());
item.getNode("origin/stable").select();
ContextMenuHelper.clickContextMenuSync(tree, myUtil.getPluginLocalizedValue("CheckoutCommand"));
TestUtil.joinJobs(JobFamilies.CHECKOUT);
refreshAndWait();
GitLightweightDecorator.refresh();
assertTrue("Branch should not be symbolic", ObjectId.isId(lookupRepository(clonedRepositoryFile).getBranch()));
// now let's try to create a local branch from the remote one
item = myRepoViewUtil.getRemoteBranchesItem(tree, clonedRepositoryFile);
TestUtil.expandAndWait(item).getNode("origin/stable").select();
ContextMenuHelper.clickContextMenu(tree, myUtil.getPluginLocalizedValue("CreateBranchCommand"));
SWTBotShell createPage = bot.shell(UIText.CreateBranchWizard_NewBranchTitle);
createPage.activate();
assertEquals("Wrong suggested branch name", "stable", createPage.bot().textWithId("BranchName").getText());
createPage.close();
// checkout master again
item = myRepoViewUtil.getLocalBranchesItem(tree, clonedRepositoryFile);
TestUtil.expandAndWait(item).getNode("master").select();
ContextMenuHelper.clickContextMenu(tree, myUtil.getPluginLocalizedValue("CheckoutCommand"));
TestUtil.joinJobs(JobFamilies.CHECKOUT);
refreshAndWait();
}
use of org.eclipse.egit.core.op.BranchOperation in project egit by eclipse.
the class BranchOperationTest method testBranchOperation.
@Test
public void testBranchOperation() throws Exception {
// create first commit containing a dummy file
testRepository.createInitialCommit("testBranchOperation\n\nfirst commit\n");
// create branch test and switch to branch test
testRepository.createBranch(MASTER, TEST);
new BranchOperation(repository, TEST).execute(null);
assertTrue(repository.getFullBranch().equals(TEST));
// add .project to version control and commit
String path = project.getProject().getLocation().append(".project").toOSString();
File file = new File(path);
testRepository.track(file);
testRepository.commit("Add .project file");
// switch back to master branch
// .project must disappear, related Eclipse project must be deleted
new BranchOperation(repository, MASTER).execute(null);
assertFalse(file.exists());
assertFalse(project.getProject().exists());
// switch back to master test
// .project must reappear
new BranchOperation(repository, TEST).execute(null);
assertTrue(file.exists());
}
use of org.eclipse.egit.core.op.BranchOperation in project egit by eclipse.
the class PushToUpstreamTest method checkoutNewLocalBranch.
private void checkoutNewLocalBranch(String branchName) throws Exception {
CreateLocalBranchOperation createBranch = new CreateLocalBranchOperation(repository, branchName, repository.findRef("master"), null);
createBranch.execute(null);
BranchOperation checkout = new BranchOperation(repository, branchName);
checkout.execute(null);
}
use of org.eclipse.egit.core.op.BranchOperation in project egit by eclipse.
the class GitFlowOperation method mergeTo.
/**
* @param monitor
* @param branchName
* @param targetBranchName
* @param squash
* @param fastForwardSingleCommit Has no effect if {@code squash} is true.
* @return result of merging back to targetBranchName
* @throws CoreException
* @since 4.1
*/
@NonNull
protected MergeResult mergeTo(IProgressMonitor monitor, String branchName, String targetBranchName, boolean squash, boolean fastForwardSingleCommit) throws CoreException {
try {
if (!repository.hasBranch(targetBranchName)) {
throw new RuntimeException(String.format(CoreText.GitFlowOperation_branchNotFound, targetBranchName));
}
SubMonitor progress = SubMonitor.convert(monitor, 2);
boolean dontCloseProjects = false;
BranchOperation branchOperation = new BranchOperation(repository.getRepository(), targetBranchName, dontCloseProjects);
branchOperation.execute(progress.newChild(1));
Status status = branchOperation.getResult().getStatus();
if (!CheckoutResult.Status.OK.equals(status)) {
throw new CoreException(error(format(CoreText.GitFlowOperation_unableToCheckout, branchName, status.toString())));
}
MergeOperation mergeOperation = new MergeOperation(repository.getRepository(), branchName);
mergeOperation.setSquash(squash);
if (squash) {
mergeOperation.setCommit(true);
}
if (!squash && (!fastForwardSingleCommit || hasMultipleCommits(branchName))) {
mergeOperation.setFastForwardMode(NO_FF);
}
mergeOperation.execute(progress.newChild(1));
MergeResult result = mergeOperation.getResult();
if (result == null) {
throw new CoreException(error(format(CoreText.GitFlowOperation_unableToMerge, branchName, targetBranchName)));
}
return result;
} catch (GitAPIException | IOException e) {
throw new RuntimeException(e);
}
}
use of org.eclipse.egit.core.op.BranchOperation in project egit by eclipse.
the class AbstractDualRepositoryTestCase method assertCommitArrivedAtRemote.
protected void assertCommitArrivedAtRemote(RevCommit branchCommit, Repository remote) throws CoreException {
GitFlowRepository gfRepo = new GitFlowRepository(remote);
BranchOperation checkoutOperation = new BranchOperation(remote, gfRepo.getConfig().getFullFeatureBranchName(MY_FEATURE));
checkoutOperation.execute(null);
RevCommit developHead = findHead(remote);
assertEquals(branchCommit, developHead);
}
Aggregations