Search in sources :

Example 11 with BranchOperation

use of org.eclipse.egit.core.op.BranchOperation in project egit by eclipse.

the class BranchOperationUI method run.

/**
 * Runs the operation synchronously.
 *
 * @param monitor
 * @throws CoreException
 */
public void run(IProgressMonitor monitor) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, 100);
    target = confirmTarget(progress.newChild(20));
    if (target == null) {
        return;
    }
    final boolean restore = Activator.getDefault().getPreferenceStore().getBoolean(UIPreferences.CHECKOUT_PROJECT_RESTORE);
    BranchOperation bop = new BranchOperation(repository, target, !restore);
    doCheckout(bop, restore, progress.newChild(80));
    show(bop.getResult());
}
Also used : BranchOperation(org.eclipse.egit.core.op.BranchOperation) SubMonitor(org.eclipse.core.runtime.SubMonitor)

Example 12 with BranchOperation

use of org.eclipse.egit.core.op.BranchOperation 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)

Example 13 with BranchOperation

use of org.eclipse.egit.core.op.BranchOperation in project egit by eclipse.

the class PushOperationTest method testPush.

/**
 * Push from repository1 "master" into "test" of repository2.
 *
 * @throws Exception
 */
@Test
public void testPush() throws Exception {
    // push from repository1 to repository2
    PushOperation pop = createPushOperation();
    pop.run(new NullProgressMonitor());
    assertEquals(Status.UP_TO_DATE, getStatus(pop.getOperationResult()));
    // let's add a new file to the project shared with repository1
    IProject proj = importProject(repository1, projectName);
    ArrayList<IFile> files = new ArrayList<IFile>();
    IFile newFile = testUtils.addFileToProject(proj, "folder2/file2.txt", "New file");
    files.add(newFile);
    IFile[] fileArr = files.toArray(new IFile[files.size()]);
    AddToIndexOperation trop = new AddToIndexOperation(files);
    trop.execute(null);
    CommitOperation cop = new CommitOperation(fileArr, files, TestUtils.AUTHOR, TestUtils.COMMITTER, "Added file");
    cop.execute(null);
    proj.delete(false, false, null);
    pop = createPushOperation();
    pop.run(null);
    assertEquals(Status.OK, getStatus(pop.getOperationResult()));
    try {
        // assert that we cannot run this again
        pop.run(null);
        fail("Expected Exception not thrown");
    } catch (IllegalStateException e) {
    // expected
    }
    pop = createPushOperation();
    pop.run(null);
    assertEquals(Status.UP_TO_DATE, getStatus(pop.getOperationResult()));
    String newFilePath = newFile.getFullPath().toOSString();
    File testFile = new File(workdir2, newFilePath);
    assertFalse(testFile.exists());
    testFile = new File(workdir, newFilePath);
    assertTrue(testFile.exists());
    // check out test and verify the file is there
    BranchOperation bop = new BranchOperation(repository2.getRepository(), "refs/heads/test");
    bop.execute(null);
    testFile = new File(workdir2, newFilePath);
    assertTrue(testFile.exists());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) BranchOperation(org.eclipse.egit.core.op.BranchOperation) ArrayList(java.util.ArrayList) PushOperation(org.eclipse.egit.core.op.PushOperation) IProject(org.eclipse.core.resources.IProject) AddToIndexOperation(org.eclipse.egit.core.op.AddToIndexOperation) CommitOperation(org.eclipse.egit.core.op.CommitOperation) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Test(org.junit.Test)

Example 14 with BranchOperation

use of org.eclipse.egit.core.op.BranchOperation in project egit by eclipse.

the class FeatureTrackOperation method execute.

@Override
public void execute(IProgressMonitor monitor) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, 3);
    try {
        String newLocalBranch = repository.getConfig().getFeatureBranchName(featureName);
        operationResult = fetch(progress.newChild(1), timeout);
        if (repository.hasBranch(newLocalBranch)) {
            String errorMessage = String.format(CoreText.FeatureTrackOperation_localBranchExists, newLocalBranch);
            throw new CoreException(error(errorMessage));
        }
        CreateLocalBranchOperation createLocalBranchOperation = new CreateLocalBranchOperation(repository.getRepository(), newLocalBranch, remoteFeature, BranchRebaseMode.NONE);
        createLocalBranchOperation.execute(progress.newChild(1));
        BranchOperation branchOperation = new BranchOperation(repository.getRepository(), newLocalBranch);
        branchOperation.execute(progress.newChild(1));
        CheckoutResult result = branchOperation.getResult();
        if (!Status.OK.equals(result.getStatus())) {
            String errorMessage = String.format(CoreText.FeatureTrackOperation_checkoutReturned, newLocalBranch, result.getStatus().name());
            throw new CoreException(error(errorMessage));
        }
        try {
            repository.setRemote(newLocalBranch, DEFAULT_REMOTE_NAME);
            repository.setUpstreamBranchName(newLocalBranch, repository.getConfig().getFullFeatureBranchName(featureName));
        } catch (IOException e) {
            throw new CoreException(error(CoreText.FeatureTrackOperation_unableToStoreGitConfig, e));
        }
    } catch (URISyntaxException e) {
        throw new CoreException(error(e.getMessage(), e));
    } catch (InvocationTargetException e) {
        Throwable targetException = e.getTargetException();
        throw new CoreException(error(targetException.getMessage(), targetException));
    } catch (GitAPIException e) {
        throw new CoreException(error(e.getMessage(), e));
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) CoreException(org.eclipse.core.runtime.CoreException) CreateLocalBranchOperation(org.eclipse.egit.core.op.CreateLocalBranchOperation) BranchOperation(org.eclipse.egit.core.op.BranchOperation) SubMonitor(org.eclipse.core.runtime.SubMonitor) CheckoutResult(org.eclipse.jgit.api.CheckoutResult) CreateLocalBranchOperation(org.eclipse.egit.core.op.CreateLocalBranchOperation) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 15 with BranchOperation

use of org.eclipse.egit.core.op.BranchOperation in project egit by eclipse.

the class GitFlowOperation method start.

/**
 * git flow * start
 *
 * @param monitor
 * @param branchName
 * @param sourceCommit
 * @throws CoreException
 */
protected void start(IProgressMonitor monitor, String branchName, RevCommit sourceCommit) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, 2);
    CreateLocalBranchOperation branchOperation = createBranchFromHead(branchName, sourceCommit);
    branchOperation.execute(progress.newChild(1));
    BranchOperation checkoutOperation = new BranchOperation(repository.getRepository(), branchName);
    checkoutOperation.execute(progress.newChild(1));
}
Also used : CreateLocalBranchOperation(org.eclipse.egit.core.op.CreateLocalBranchOperation) DeleteBranchOperation(org.eclipse.egit.core.op.DeleteBranchOperation) BranchOperation(org.eclipse.egit.core.op.BranchOperation) SubMonitor(org.eclipse.core.runtime.SubMonitor) CreateLocalBranchOperation(org.eclipse.egit.core.op.CreateLocalBranchOperation)

Aggregations

BranchOperation (org.eclipse.egit.core.op.BranchOperation)19 Test (org.junit.Test)8 CreateLocalBranchOperation (org.eclipse.egit.core.op.CreateLocalBranchOperation)7 GitFlowRepository (org.eclipse.egit.gitflow.GitFlowRepository)7 Repository (org.eclipse.jgit.lib.Repository)7 SubMonitor (org.eclipse.core.runtime.SubMonitor)5 File (java.io.File)3 IOException (java.io.IOException)3 CoreException (org.eclipse.core.runtime.CoreException)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 IFile (org.eclipse.core.resources.IFile)2 CommitOperation (org.eclipse.egit.core.op.CommitOperation)2 DeleteBranchOperation (org.eclipse.egit.core.op.DeleteBranchOperation)2 WrongGitFlowStateException (org.eclipse.egit.gitflow.WrongGitFlowStateException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 IProject (org.eclipse.core.resources.IProject)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1