Search in sources :

Example 6 with CreateLocalBranchOperation

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

the class InitDialog method okPressed.

@Override
protected void okPressed() {
    String master = gitflowInitConfig.getMaster();
    Repository repository = gfRepo.getRepository();
    if (isMasterBranchAvailable(master, repository)) {
        super.okPressed();
        return;
    }
    boolean createBranch = openQuestion(getShell(), InitDialog_masterBranchIsMissing, NLS.bind(InitDialog_selectedMasterBranchDoesNotExistCreateNow, master));
    if (!createBranch) {
        return;
    }
    try {
        RevCommit head = gfRepo.findHead();
        new CreateLocalBranchOperation(repository, master, head).execute(null);
    } catch (CoreException | WrongGitFlowStateException e) {
        throw new RuntimeException(e);
    }
    super.okPressed();
}
Also used : InitDialog_initializeRepository(org.eclipse.egit.gitflow.ui.internal.UIText.InitDialog_initializeRepository) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) Repository(org.eclipse.jgit.lib.Repository) CoreException(org.eclipse.core.runtime.CoreException) WrongGitFlowStateException(org.eclipse.egit.gitflow.WrongGitFlowStateException) CreateLocalBranchOperation(org.eclipse.egit.core.op.CreateLocalBranchOperation) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 7 with CreateLocalBranchOperation

use of org.eclipse.egit.core.op.CreateLocalBranchOperation 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 8 with CreateLocalBranchOperation

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

Example 9 with CreateLocalBranchOperation

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

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