use of org.eclipse.egit.core.op.CreateLocalBranchOperation in project egit by eclipse.
the class SynchronizeViewRemoteAwareChangeSetModelTest method createMockLogicalRepository.
protected void createMockLogicalRepository() throws Exception {
File gitDir = new File(new File(getTestDirectory(), MOCK_LOGICAL_PROJECT), Constants.DOT_GIT);
Repository repo = FileRepositoryBuilder.create(gitDir);
repo.create();
// we need to commit into master first
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(MOCK_LOGICAL_PROJECT);
if (project.exists()) {
project.delete(true, null);
TestUtil.waitForJobs(100, 5000);
}
IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(MOCK_LOGICAL_PROJECT);
desc.setLocation(new Path(new File(repo.getWorkTree(), MOCK_LOGICAL_PROJECT).getPath()));
project.create(desc, null);
project.open(null);
assertTrue("Project is not accessible: " + project, project.isAccessible());
TestUtil.waitForJobs(50, 5000);
try {
new ConnectProviderOperation(project, gitDir).execute(null);
} catch (Exception e) {
Activator.logError("Failed to connect project to repository", e);
}
assertConnected(project);
mockLogicalFile = project.getFile("index.mocklogical");
mockLogicalFile.create(new ByteArrayInputStream("file1.txt\nfile2.txt".getBytes(project.getDefaultCharset())), false, null);
IFile file1 = project.getFile("file1.txt");
file1.create(new ByteArrayInputStream("Content 1".getBytes(project.getDefaultCharset())), false, null);
IFile file2 = project.getFile("file2.txt");
file2.create(new ByteArrayInputStream("Content 2".getBytes(project.getDefaultCharset())), false, null);
IFile[] commitables = new IFile[] { mockLogicalFile, file1, file2 };
List<IFile> untracked = new ArrayList<>();
untracked.addAll(Arrays.asList(commitables));
CommitOperation op = new CommitOperation(commitables, untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Initial commit");
op.execute(null);
RevCommit firstCommit = op.getCommit();
CreateLocalBranchOperation createBranchOp = new CreateLocalBranchOperation(repo, "refs/heads/stable", firstCommit);
createBranchOp.execute(null);
// Delete file2.txt from logical model and add file3
mockLogicalFile = touch(MOCK_LOGICAL_PROJECT, "index.mocklogical", "file1.txt\nfile3.txt");
file2.delete(true, null);
touch(MOCK_LOGICAL_PROJECT, "file1.txt", "Content 1 modified");
IFile file3 = project.getFile("file3.txt");
file3.create(new ByteArrayInputStream("Content 3".getBytes(project.getDefaultCharset())), false, null);
commitables = new IFile[] { mockLogicalFile, file1, file2, file3 };
untracked = new ArrayList<>();
untracked.add(file3);
op = new CommitOperation(commitables, untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Second commit");
op.execute(null);
}
use of org.eclipse.egit.core.op.CreateLocalBranchOperation 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.CreateLocalBranchOperation in project egit by eclipse.
the class CreateBranchPage method createBranch.
/**
* @param newRefName
* @param checkoutNewBranch
* @param monitor
* @throws CoreException
* @throws IOException
*/
public void createBranch(String newRefName, boolean checkoutNewBranch, IProgressMonitor monitor) throws CoreException, IOException {
SubMonitor progress = SubMonitor.convert(monitor, checkoutNewBranch ? 2 : 1);
progress.setTaskName(UIText.CreateBranchPage_CreatingBranchMessage);
final CreateLocalBranchOperation cbop;
if (myBaseCommit != null && this.sourceRefName.equals(myBaseCommit.name()))
cbop = new CreateLocalBranchOperation(myRepository, newRefName, myBaseCommit);
else
cbop = new CreateLocalBranchOperation(myRepository, newRefName, myRepository.findRef(this.sourceRefName), upstreamConfig);
cbop.execute(progress.newChild(1));
if (checkoutNewBranch && !progress.isCanceled()) {
progress.setTaskName(UIText.CreateBranchPage_CheckingOutMessage);
BranchOperationUI.checkout(myRepository, Constants.R_HEADS + newRefName).run(progress.newChild(1));
}
}
use of org.eclipse.egit.core.op.CreateLocalBranchOperation in project egit by eclipse.
the class FetchGerritChangePage method createBranch.
private void createBranch(final String textForBranch, boolean doCheckout, RevCommit commit, IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, doCheckout ? 10 : 2);
progress.subTask(UIText.FetchGerritChangePage_CreatingBranchTaskName);
CreateLocalBranchOperation bop = new CreateLocalBranchOperation(repository, textForBranch, commit);
bop.execute(progress.newChild(2));
if (doCheckout) {
checkout(textForBranch, progress.newChild(8));
}
}
use of org.eclipse.egit.core.op.CreateLocalBranchOperation in project egit by eclipse.
the class PushBranchWizardTest 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);
}
Aggregations