Search in sources :

Example 16 with BranchOperation

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

the class InitOperation method execute.

@Override
public void execute(IProgressMonitor monitor) throws CoreException {
    try {
        setPrefixes(feature, release, hotfix, versionTag);
        setBranches(develop, master);
        repository.getRepository().getConfig().save();
    } catch (IOException e) {
        throw new CoreException(error(e.getMessage(), e));
    }
    SubMonitor progress = SubMonitor.convert(monitor, 3);
    if (!repository.hasBranches()) {
        new CommitOperation(repository.getRepository(), repository.getConfig().getUser(), repository.getConfig().getUser(), CoreText.InitOperation_initialCommit).execute(progress.newChild(1));
    }
    try {
        if (!isMasterBranchAvailable()) {
            throw new CoreException(error(NLS.bind(CoreText.InitOperation_localMasterDoesNotExist, master)));
        }
        RevCommit head = repository.findHead();
        if (!repository.hasBranch(develop)) {
            CreateLocalBranchOperation branchFromHead = createBranchFromHead(develop, head);
            branchFromHead.execute(progress.newChild(1));
            BranchOperation checkoutOperation = new BranchOperation(repository.getRepository(), develop);
            checkoutOperation.execute(progress.newChild(1));
        }
    } catch (WrongGitFlowStateException e) {
        throw new CoreException(error(e));
    } 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) CommitOperation(org.eclipse.egit.core.op.CommitOperation) CreateLocalBranchOperation(org.eclipse.egit.core.op.CreateLocalBranchOperation) BranchOperation(org.eclipse.egit.core.op.BranchOperation) SubMonitor(org.eclipse.core.runtime.SubMonitor) WrongGitFlowStateException(org.eclipse.egit.gitflow.WrongGitFlowStateException) IOException(java.io.IOException) CreateLocalBranchOperation(org.eclipse.egit.core.op.CreateLocalBranchOperation) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 17 with BranchOperation

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

the class FeatureCheckoutOperationTest method testFeatureCheckoutConflicts.

@Test
public void testFeatureCheckoutConflicts() throws Exception {
    Repository repository = testRepository.getRepository();
    GitFlowRepository gfRepo = init("testFeatureCheckoutConflicts\n\nfirst commit\n");
    // setup something we can modify later
    IFile file = testUtils.addFileToProject(project.getProject(), "folder1/file1.txt", "Hello world");
    testRepository.connect(project.getProject());
    testRepository.trackAllFiles(project.getProject());
    testRepository.commit("Initial commit");
    new FeatureStartOperation(gfRepo, MY_FEATURE).execute(null);
    // modify on first branch
    testUtils.changeContentOfFile(project.getProject(), file, "Hello Feature");
    testRepository.addToIndex(file);
    testRepository.commit("Feature commit");
    new BranchOperation(repository, gfRepo.getConfig().getDevelop()).execute(null);
    assertEquals(gfRepo.getConfig().getDevelopFull(), repository.getFullBranch());
    // modify on second branch
    testUtils.changeContentOfFile(project.getProject(), file, "Hello Develop");
    testRepository.addToIndex(file);
    FeatureCheckoutOperation featureCheckoutOperation = new FeatureCheckoutOperation(gfRepo, MY_FEATURE);
    featureCheckoutOperation.execute(null);
    assertEquals(Status.CONFLICTS, featureCheckoutOperation.getResult().getStatus());
    assertEquals(gfRepo.getConfig().getDevelopFull(), repository.getFullBranch());
}
Also used : GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) Repository(org.eclipse.jgit.lib.Repository) IFile(org.eclipse.core.resources.IFile) BranchOperation(org.eclipse.egit.core.op.BranchOperation) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) Test(org.junit.Test)

Example 18 with BranchOperation

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

the class FeatureStartOperationTest method testFeatureStartOnMaster.

public void testFeatureStartOnMaster() throws Exception {
    Repository repository = testRepository.getRepository();
    GitFlowRepository gfRepo = init("testFeatureStartOnMaster\n\nfirst commit\n");
    BranchOperation branchOperation = new BranchOperation(repository, MY_MASTER);
    branchOperation.execute(null);
    new FeatureStartOperation(gfRepo, MY_FEATURE).execute(null);
}
Also used : GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) Repository(org.eclipse.jgit.lib.Repository) BranchOperation(org.eclipse.egit.core.op.BranchOperation) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository)

Example 19 with BranchOperation

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

the class FeatureCheckoutOperation method execute.

@Override
public void execute(IProgressMonitor monitor) throws CoreException {
    String branchName = repository.getConfig().getFeatureBranchName(featureName);
    boolean dontCloseProjects = false;
    BranchOperation branchOperation = new BranchOperation(repository.getRepository(), branchName, dontCloseProjects);
    branchOperation.execute(monitor);
    result = branchOperation.getResult();
}
Also used : BranchOperation(org.eclipse.egit.core.op.BranchOperation)

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