Search in sources :

Example 16 with RebaseResult

use of org.eclipse.jgit.api.RebaseResult in project egit by eclipse.

the class FeatureRebaseOperationTest method testFeatureRebase.

@Test
public void testFeatureRebase() throws Exception {
    Repository repository = testRepository.getRepository();
    GitFlowRepository gfRepo = init("testFeatureRebase\n\nfirst commit\n");
    RevCommit initialCommit = gfRepo.findHead();
    new FeatureStartOperation(gfRepo, MY_FEATURE).execute(null);
    String branchCommitMessage = "adding first file on feature branch";
    addFileAndCommit("theFile.txt", branchCommitMessage);
    testRepository.checkoutBranch(gfRepo.getConfig().getDevelop());
    RevCommit developCommit = addFileAndCommit("theOtherFile.txt", "adding second file on develop branch");
    new FeatureCheckoutOperation(gfRepo, MY_FEATURE).execute(null);
    assertEquals(initialCommit, gfRepo.findHead().getParent(0));
    FeatureRebaseOperation featureRebaseOperation = new FeatureRebaseOperation(gfRepo);
    featureRebaseOperation.execute(null);
    RebaseResult res = featureRebaseOperation.getOperationResult();
    assertEquals(RebaseResult.Status.OK, res.getStatus());
    assertEquals(branchCommitMessage, gfRepo.findHead().getShortMessage());
    assertEquals(developCommit, parseCommit(repository, repository.resolve("HEAD^")));
}
Also used : GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) Repository(org.eclipse.jgit.lib.Repository) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) RebaseResult(org.eclipse.jgit.api.RebaseResult) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 17 with RebaseResult

use of org.eclipse.jgit.api.RebaseResult in project egit by eclipse.

the class MultiPullResultDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite main = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().applyTo(main);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(main);
    tv = new TableViewer(main, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
    tv.setContentProvider(ArrayContentProvider.getInstance());
    TableColumnLayout layout = new TableColumnLayout();
    main.setLayout(layout);
    tv.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            boolean enabled = false;
            for (Object obj : sel.toList()) {
                @SuppressWarnings("unchecked") Entry<Repository, Object> entry = (Entry<Repository, Object>) obj;
                enabled |= entry.getValue() instanceof PullResult;
            }
            getButton(DETAIL_BUTTON).setEnabled(enabled);
        }
    });
    tv.addOpenListener(new IOpenListener() {

        @Override
        public void open(OpenEvent event) {
            buttonPressed(DETAIL_BUTTON);
        }
    });
    Table table = tv.getTable();
    int linesToShow = Math.min(Math.max(results.size(), 5), 15);
    int heightHint = table.getItemHeight() * linesToShow;
    GridDataFactory.fillDefaults().grab(true, true).hint(800, heightHint).applyTo(table);
    // repository
    TableViewerColumn tc = new TableViewerColumn(tv, SWT.NONE);
    TableColumn col = tc.getColumn();
    tc.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            @SuppressWarnings("unchecked") Entry<Repository, Object> item = (Entry<Repository, Object>) element;
            return utils.getRepositoryName(item.getKey());
        }
    });
    col.setText(UIText.MultiPullResultDialog_RepositoryColumnHeader);
    layout.setColumnData(col, new ColumnWeightData(200, 200));
    createComparator(col, 0);
    // fetch status
    tc = new TableViewerColumn(tv, SWT.NONE);
    col = tc.getColumn();
    tc.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            @SuppressWarnings("unchecked") Entry<Repository, Object> item = (Entry<Repository, Object>) element;
            if (item.getValue() instanceof IStatus)
                return UIText.MultiPullResultDialog_UnknownStatus;
            PullResult pullRes = (PullResult) item.getValue();
            if (pullRes.getFetchResult() == null) {
                return UIText.MultiPullResultDialog_NothingFetchedStatus;
            } else if (pullRes.getFetchResult().getTrackingRefUpdates().isEmpty()) {
                return UIText.MultiPullResultDialog_NothingUpdatedStatus;
            } else {
                int updated = pullRes.getFetchResult().getTrackingRefUpdates().size();
                if (updated == 1) {
                    return UIText.MultiPullResultDialog_UpdatedOneMessage;
                }
                return NLS.bind(UIText.MultiPullResultDialog_UpdatedMessage, Integer.valueOf(updated));
            }
        }
    });
    col.setText(UIText.MultiPullResultDialog_FetchStatusColumnHeader);
    layout.setColumnData(col, new ColumnWeightData(200, 200));
    createComparator(col, 1);
    // update status
    tc = new TableViewerColumn(tv, SWT.NONE);
    col = tc.getColumn();
    tc.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            @SuppressWarnings("unchecked") Entry<Repository, Object> item = (Entry<Repository, Object>) element;
            if (item.getValue() instanceof IStatus) {
                return UIText.MultiPullResultDialog_UnknownStatus;
            }
            PullResult pullRes = (PullResult) item.getValue();
            if (pullRes.getMergeResult() != null) {
                return NLS.bind(UIText.MultiPullResultDialog_MergeResultMessage, MergeResultDialog.getStatusText(pullRes.getMergeResult().getMergeStatus()));
            } else if (pullRes.getRebaseResult() != null) {
                RebaseResult res = pullRes.getRebaseResult();
                return NLS.bind(UIText.MultiPullResultDialog_RebaseResultMessage, RebaseResultDialog.getStatusText(res.getStatus()));
            } else {
                return UIText.MultiPullResultDialog_NothingUpdatedStatus;
            }
        }
    });
    col.setText(UIText.MultiPullResultDialog_UpdateStatusColumnHeader);
    layout.setColumnData(col, new ColumnWeightData(200, 200));
    createComparator(col, 2);
    // overall status
    tc = new TableViewerColumn(tv, SWT.NONE);
    col = tc.getColumn();
    tc.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public Image getImage(Object element) {
            @SuppressWarnings("unchecked") Entry<Repository, Object> item = (Entry<Repository, Object>) element;
            Object resultOrError = item.getValue();
            if (resultOrError instanceof IStatus) {
                return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_STOP);
            }
            PullResult res = (PullResult) item.getValue();
            boolean success = res.isSuccessful();
            if (!success) {
                return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_STOP);
            }
            return null;
        }

        @Override
        public String getText(Object element) {
            @SuppressWarnings("unchecked") Entry<Repository, Object> item = (Entry<Repository, Object>) element;
            if (item.getValue() instanceof IStatus) {
                IStatus status = (IStatus) item.getValue();
                return status.getMessage();
            }
            PullResult res = (PullResult) item.getValue();
            if (res.isSuccessful()) {
                return UIText.MultiPullResultDialog_OkStatus;
            } else {
                return UIText.MultiPullResultDialog_FailedStatus;
            }
        }
    });
    col.setText(UIText.MultiPullResultDialog_OverallStatusColumnHeader);
    layout.setColumnData(col, new ColumnWeightData(200, 200));
    createComparator(col, 3);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    tv.setInput(results.entrySet());
    return main;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) IStatus(org.eclipse.core.runtime.IStatus) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) TableColumn(org.eclipse.swt.widgets.TableColumn) PullResult(org.eclipse.jgit.api.PullResult) Point(org.eclipse.swt.graphics.Point) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Entry(java.util.Map.Entry) Repository(org.eclipse.jgit.lib.Repository) IOpenListener(org.eclipse.jface.viewers.IOpenListener) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) TableViewer(org.eclipse.jface.viewers.TableViewer) RebaseResult(org.eclipse.jgit.api.RebaseResult) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) OpenEvent(org.eclipse.jface.viewers.OpenEvent)

Aggregations

RebaseResult (org.eclipse.jgit.api.RebaseResult)17 Test (org.junit.Test)10 File (java.io.File)9 PullResult (org.eclipse.jgit.api.PullResult)8 HashMap (java.util.HashMap)6 PullCommand (org.eclipse.jgit.api.PullCommand)6 RebaseCommand (org.eclipse.jgit.api.RebaseCommand)6 Git (org.eclipse.jgit.api.Git)5 RevCommit (org.eclipse.jgit.revwalk.RevCommit)5 Path (org.uberfire.java.nio.file.Path)5 JGitFileSystem (org.uberfire.java.nio.fs.jgit.JGitFileSystem)5 URI (java.net.URI)4 IFile (org.eclipse.core.resources.IFile)4 RebaseOperation (org.eclipse.egit.core.op.RebaseOperation)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Repository (org.eclipse.jgit.lib.Repository)3 CompilationResponse (org.kie.workbench.common.services.backend.compiler.CompilationResponse)3 IStatus (org.eclipse.core.runtime.IStatus)2 GitFlowRepository (org.eclipse.egit.gitflow.GitFlowRepository)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2