Search in sources :

Example 1 with WrongGitFlowStateException

use of org.eclipse.egit.gitflow.WrongGitFlowStateException in project egit by eclipse.

the class FeatureFinishHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final GitFlowRepository gfRepo = GitFlowHandlerUtil.getRepository(event);
    if (gfRepo == null) {
        return error(UIText.Handlers_noGitflowRepositoryFound);
    }
    final String featureBranch;
    Repository repo = gfRepo.getRepository();
    try {
        featureBranch = repo.getBranch();
    } catch (IOException e) {
        return error(e.getMessage(), e);
    }
    Shell activeShell = HandlerUtil.getActiveShell(event);
    FinishFeatureDialog dialog = new FinishFeatureDialog(activeShell, featureBranch);
    if (dialog.open() != Window.OK) {
        return null;
    }
    final boolean squash = dialog.isSquash();
    boolean keepBranch = dialog.isKeepBranch();
    try {
        try {
            if (squash && !UIRepositoryUtils.handleUncommittedFiles(repo, activeShell))
                return null;
        } catch (GitAPIException e) {
            Activator.logError(e.getMessage(), e);
            return null;
        }
        final FeatureFinishOperation operation = new FeatureFinishOperation(gfRepo);
        operation.setSquash(squash);
        operation.setKeepBranch(keepBranch);
        JobUtil.scheduleUserWorkspaceJob(operation, UIText.FeatureFinishHandler_finishingFeature, JobFamilies.GITFLOW_FAMILY, new JobChangeAdapter() {

            @Override
            public void done(IJobChangeEvent jobChangeEvent) {
                if (jobChangeEvent.getResult().isOK()) {
                    postMerge(gfRepo, featureBranch, squash, operation.getMergeResult());
                }
            }
        });
    } catch (WrongGitFlowStateException | CoreException | IOException | OperationCanceledException e) {
        return error(e.getMessage(), e);
    }
    return null;
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) FinishFeatureDialog(org.eclipse.egit.gitflow.ui.internal.dialogs.FinishFeatureDialog) IOException(java.io.IOException) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) Repository(org.eclipse.jgit.lib.Repository) Shell(org.eclipse.swt.widgets.Shell) FeatureFinishOperation(org.eclipse.egit.gitflow.op.FeatureFinishOperation) CoreException(org.eclipse.core.runtime.CoreException) WrongGitFlowStateException(org.eclipse.egit.gitflow.WrongGitFlowStateException) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository)

Example 2 with WrongGitFlowStateException

use of org.eclipse.egit.gitflow.WrongGitFlowStateException in project egit by eclipse.

the class HotfixFinishHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final GitFlowRepository gfRepo = GitFlowHandlerUtil.getRepository(event);
    if (gfRepo == null) {
        return error(UIText.Handlers_noGitflowRepositoryFound);
    }
    HotfixFinishOperation hotfixFinishOperation;
    try {
        hotfixFinishOperation = new HotfixFinishOperation(gfRepo);
        String hotfixBranch = gfRepo.getRepository().getBranch();
        String develop = gfRepo.getConfig().getDevelop();
        JobUtil.scheduleUserWorkspaceJob(hotfixFinishOperation, UIText.HotfixFinishHandler_finishingHotfix, JobFamilies.GITFLOW_FAMILY);
        IJobManager jobMan = Job.getJobManager();
        jobMan.join(JobFamilies.GITFLOW_FAMILY, null);
        MergeResult mergeResult = hotfixFinishOperation.getMergeResult();
        MergeStatus mergeStatus = mergeResult.getMergeStatus();
        if (!MergeStatus.CONFLICTING.equals(mergeStatus)) {
            return null;
        }
        if (handleConflictsOnMaster(gfRepo)) {
            return null;
        }
        MultiStatus status = createMergeConflictInfo(develop, hotfixBranch, mergeResult);
        ErrorDialog.openError(null, UIText.HotfixFinishHandler_Conflicts, null, status);
    } catch (WrongGitFlowStateException | CoreException | IOException | OperationCanceledException | InterruptedException e) {
        return error(e.getMessage(), e);
    }
    return null;
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) MergeResult(org.eclipse.jgit.api.MergeResult) MultiStatus(org.eclipse.core.runtime.MultiStatus) IJobManager(org.eclipse.core.runtime.jobs.IJobManager) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) MergeStatus(org.eclipse.jgit.api.MergeResult.MergeStatus) WrongGitFlowStateException(org.eclipse.egit.gitflow.WrongGitFlowStateException) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) HotfixFinishOperation(org.eclipse.egit.gitflow.op.HotfixFinishOperation)

Example 3 with WrongGitFlowStateException

use of org.eclipse.egit.gitflow.WrongGitFlowStateException in project egit by eclipse.

the class AbstractVersionFinishOperation method safeCreateTag.

/**
 * Check if tag exists before trying to create it.
 *
 * @param monitor
 * @param tagName
 * @param tagMessage
 * @throws CoreException
 */
protected void safeCreateTag(IProgressMonitor monitor, String tagName, String tagMessage) throws CoreException {
    RevCommit head;
    try {
        head = repository.findHead();
    } catch (WrongGitFlowStateException e) {
        throw new CoreException(error(e));
    }
    RevCommit commitForTag;
    try {
        commitForTag = repository.findCommitForTag(versionName);
        if (commitForTag == null) {
            createTag(monitor, head, tagName, tagMessage);
        } else if (!head.equals(commitForTag)) {
            throw new CoreException(error(format(CoreText.AbstractVersionFinishOperation_tagNameExists, versionName)));
        }
    } catch (IOException e) {
        throw new CoreException(error(e));
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) WrongGitFlowStateException(org.eclipse.egit.gitflow.WrongGitFlowStateException) IOException(java.io.IOException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 4 with WrongGitFlowStateException

use of org.eclipse.egit.gitflow.WrongGitFlowStateException in project egit by eclipse.

the class FeatureRebaseOperation method execute.

@Override
public void execute(IProgressMonitor monitor) throws CoreException {
    try {
        if (!repository.isFeature()) {
            throw new WrongGitFlowStateException(CoreText.FeatureRebaseOperation_notOnAFeatureBranch);
        }
        Repository jgitRepo = repository.getRepository();
        Ref develop = jgitRepo.exactRef(repository.getConfig().getDevelopFull());
        RebaseOperation op = new RebaseOperation(jgitRepo, develop);
        op.execute(monitor);
        operationResult = op.getResult();
    } catch (WrongGitFlowStateException | IOException e) {
        throw new CoreException(error(e.getMessage(), e));
    }
}
Also used : RebaseOperation(org.eclipse.egit.core.op.RebaseOperation) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) CoreException(org.eclipse.core.runtime.CoreException) WrongGitFlowStateException(org.eclipse.egit.gitflow.WrongGitFlowStateException) IOException(java.io.IOException)

Example 5 with WrongGitFlowStateException

use of org.eclipse.egit.gitflow.WrongGitFlowStateException in project egit by eclipse.

the class ReleaseFinishOperationTest method testReleaseFinishFail.

@Test
public void testReleaseFinishFail() throws Exception {
    testRepository.createInitialCommit("testReleaseFinishFail\n\nfirst commit\n");
    Repository repository = testRepository.getRepository();
    new InitOperation(repository).execute(null);
    GitFlowRepository gfRepo = new GitFlowRepository(repository);
    new ReleaseStartOperation(gfRepo, MY_RELEASE).execute(null);
    new BranchOperation(repository, gfRepo.getConfig().getDevelop()).execute(null);
    try {
        new ReleaseFinishOperation(gfRepo).execute(null);
        fail();
    } catch (WrongGitFlowStateException e) {
    // success
    }
}
Also used : GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) Repository(org.eclipse.jgit.lib.Repository) BranchOperation(org.eclipse.egit.core.op.BranchOperation) WrongGitFlowStateException(org.eclipse.egit.gitflow.WrongGitFlowStateException) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) Test(org.junit.Test)

Aggregations

WrongGitFlowStateException (org.eclipse.egit.gitflow.WrongGitFlowStateException)9 CoreException (org.eclipse.core.runtime.CoreException)7 GitFlowRepository (org.eclipse.egit.gitflow.GitFlowRepository)7 IOException (java.io.IOException)6 Repository (org.eclipse.jgit.lib.Repository)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)3 MultiStatus (org.eclipse.core.runtime.MultiStatus)2 IJobManager (org.eclipse.core.runtime.jobs.IJobManager)2 BranchOperation (org.eclipse.egit.core.op.BranchOperation)2 CreateLocalBranchOperation (org.eclipse.egit.core.op.CreateLocalBranchOperation)2 MergeResult (org.eclipse.jgit.api.MergeResult)2 MergeStatus (org.eclipse.jgit.api.MergeResult.MergeStatus)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2 ExecutionException (org.eclipse.core.commands.ExecutionException)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1 CommitOperation (org.eclipse.egit.core.op.CommitOperation)1 RebaseOperation (org.eclipse.egit.core.op.RebaseOperation)1