Search in sources :

Example 1 with CreateLocalBranchOperation

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);
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) CreateLocalBranchOperation(org.eclipse.egit.core.op.CreateLocalBranchOperation) IProject(org.eclipse.core.resources.IProject) Repository(org.eclipse.jgit.lib.Repository) ByteArrayInputStream(java.io.ByteArrayInputStream) CommitOperation(org.eclipse.egit.core.op.CommitOperation) IProjectDescription(org.eclipse.core.resources.IProjectDescription) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IFile(org.eclipse.core.resources.IFile) File(java.io.File) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 2 with CreateLocalBranchOperation

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);
}
Also used : CreateLocalBranchOperation(org.eclipse.egit.core.op.CreateLocalBranchOperation) BranchOperation(org.eclipse.egit.core.op.BranchOperation) CreateLocalBranchOperation(org.eclipse.egit.core.op.CreateLocalBranchOperation)

Example 3 with CreateLocalBranchOperation

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));
    }
}
Also used : SubMonitor(org.eclipse.core.runtime.SubMonitor) CreateLocalBranchOperation(org.eclipse.egit.core.op.CreateLocalBranchOperation)

Example 4 with CreateLocalBranchOperation

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));
    }
}
Also used : SubMonitor(org.eclipse.core.runtime.SubMonitor) CreateLocalBranchOperation(org.eclipse.egit.core.op.CreateLocalBranchOperation)

Example 5 with CreateLocalBranchOperation

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);
}
Also used : CreateLocalBranchOperation(org.eclipse.egit.core.op.CreateLocalBranchOperation) BranchOperation(org.eclipse.egit.core.op.BranchOperation) CreateLocalBranchOperation(org.eclipse.egit.core.op.CreateLocalBranchOperation)

Aggregations

CreateLocalBranchOperation (org.eclipse.egit.core.op.CreateLocalBranchOperation)9 SubMonitor (org.eclipse.core.runtime.SubMonitor)5 BranchOperation (org.eclipse.egit.core.op.BranchOperation)5 CoreException (org.eclipse.core.runtime.CoreException)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 IOException (java.io.IOException)2 CommitOperation (org.eclipse.egit.core.op.CommitOperation)2 WrongGitFlowStateException (org.eclipse.egit.gitflow.WrongGitFlowStateException)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2 Repository (org.eclipse.jgit.lib.Repository)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IProjectDescription (org.eclipse.core.resources.IProjectDescription)1 Path (org.eclipse.core.runtime.Path)1 ConnectProviderOperation (org.eclipse.egit.core.op.ConnectProviderOperation)1