Search in sources :

Example 6 with FetchResult

use of org.eclipse.jgit.transport.FetchResult in project egit by eclipse.

the class FetchOperationUI method start.

/**
 * Starts the operation asynchronously showing a confirmation dialog after
 * completion
 */
public void start() {
    final Repository repo = repository;
    if (repo == null) {
        return;
    }
    Job job = new RepositoryJob(NLS.bind(UIText.FetchOperationUI_FetchJobName, sourceString), UIPreferences.SHOW_FETCH_POPUP_SUCCESS) {

        private FetchResult result;

        @Override
        public IStatus performJob(IProgressMonitor monitor) {
            try {
                result = execute(monitor);
            } catch (CoreException e) {
                return Activator.createErrorStatus(e.getStatus().getMessage(), e);
            }
            return Status.OK_STATUS;
        }

        @Override
        protected IAction getAction() {
            return new ShowResultAction(repo, result, sourceString);
        }

        @Override
        public boolean belongsTo(Object family) {
            if (JobFamilies.FETCH.equals(family)) {
                return true;
            }
            return super.belongsTo(family);
        }
    };
    job.setUser(true);
    job.schedule();
}
Also used : Repository(org.eclipse.jgit.lib.Repository) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FetchResult(org.eclipse.jgit.transport.FetchResult) CoreException(org.eclipse.core.runtime.CoreException) RepositoryJob(org.eclipse.egit.ui.internal.jobs.RepositoryJob) Job(org.eclipse.core.runtime.jobs.Job) RepositoryJob(org.eclipse.egit.ui.internal.jobs.RepositoryJob)

Example 7 with FetchResult

use of org.eclipse.jgit.transport.FetchResult in project egit by eclipse.

the class FeatureTrackOperationTest method testFeatureTrack.

@Test
public void testFeatureTrack() throws Exception {
    GitFlowRepository gfRepo1 = new GitFlowRepository(repository1.getRepository());
    GitFlowRepository gfRepo2 = new GitFlowRepository(repository2.getRepository());
    new FeatureStartOperation(gfRepo1, MY_FEATURE).execute(null);
    RevCommit branchCommit = repository1.createInitialCommit("testFeatureTrack");
    FeatureTrackOperation featureTrackOperation = new FeatureTrackOperation(gfRepo2, getFirstRemoteFeatureRef(gfRepo2), NO_TIMEOUT);
    featureTrackOperation.execute(null);
    FetchResult operationResult = featureTrackOperation.getOperationResult();
    assertNotNull(operationResult.getAdvertisedRef(gfRepo2.getConfig().getFullFeatureBranchName(MY_FEATURE)));
    assertEquals(gfRepo2.getConfig().getFeatureBranchName(MY_FEATURE), repository2.getRepository().getBranch());
    assertEquals(branchCommit, findHead(repository2.getRepository()));
    RevCommit localCommit = repository2.createInitialCommit("testFeatureTrack2");
    new CurrentBranchPublishOperation(gfRepo2, 0).execute(null);
    assertEquals(localCommit, findHead(repository2.getRepository()));
    // config updated?
    assertEquals(DEFAULT_REMOTE_NAME, getRemoteName(gfRepo2, MY_FEATURE));
    assertEquals(R_HEADS + gfRepo2.getConfig().getFeatureBranchName(MY_FEATURE), gfRepo2.getUpstreamBranchName(MY_FEATURE));
}
Also used : FetchResult(org.eclipse.jgit.transport.FetchResult) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 8 with FetchResult

use of org.eclipse.jgit.transport.FetchResult in project egit by eclipse.

the class PullResultDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite main = new Composite(parent, SWT.NONE);
    GridLayoutFactory.swtDefaults().applyTo(main);
    GridDataFactory.fillDefaults().indent(0, 0).grab(true, true).applyTo(main);
    Group fetchResultGroup = new Group(main, SWT.SHADOW_ETCHED_IN);
    fetchResultGroup.setText(UIText.PullResultDialog_FetchResultGroupHeader);
    GridLayoutFactory.fillDefaults().applyTo(fetchResultGroup);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(fetchResultGroup);
    FetchResult fRes = result.getFetchResult();
    if (hasFetchResults()) {
        GridLayoutFactory.fillDefaults().applyTo(fetchResultGroup);
        FetchResultDialog dlg = new FetchResultDialog(getParentShell(), repo, fRes, result.getFetchedFrom());
        Control fresult = dlg.createFetchResultTable(fetchResultGroup);
        Object layoutData = fresult.getLayoutData();
        if (layoutData instanceof GridData)
            GridDataFactory.createFrom((GridData) layoutData).hint(SWT.DEFAULT, 130).applyTo(fresult);
    } else {
        GridLayoutFactory.swtDefaults().applyTo(fetchResultGroup);
        Label noResult = new Label(fetchResultGroup, SWT.NONE);
        if (// $NON-NLS-1$
        result.getFetchedFrom().equals("."))
            noResult.setText(UIText.PullResultDialog_NothingToFetchFromLocal);
        else
            noResult.setText(NLS.bind(UIText.FetchResultDialog_labelEmptyResult, result.getFetchedFrom()));
    }
    Group mergeResultGroup = new Group(main, SWT.SHADOW_ETCHED_IN);
    mergeResultGroup.setText(UIText.PullResultDialog_MergeResultGroupHeader);
    if (hasMergeResults()) {
        GridDataFactory.fillDefaults().grab(true, true).applyTo(mergeResultGroup);
        GridLayoutFactory.fillDefaults().applyTo(mergeResultGroup);
        MergeResultDialog dlg = new MergeResultDialog(getParentShell(), repo, result.getMergeResult());
        dlg.createDialogArea(mergeResultGroup);
    } else if (hasRebaseResults()) {
        RebaseResultDialog.createFailedOrConflictsParts(mergeResultGroup, result.getRebaseResult());
        GridDataFactory.fillDefaults().grab(true, false).applyTo(mergeResultGroup);
    } else {
        GridDataFactory.fillDefaults().grab(true, false).applyTo(mergeResultGroup);
        GridLayoutFactory.swtDefaults().applyTo(mergeResultGroup);
        Label noResult = new Label(mergeResultGroup, SWT.NONE);
        noResult.setText(UIText.PullResultDialog_MergeAlreadyUpToDateMessage);
    }
    return main;
}
Also used : Group(org.eclipse.swt.widgets.Group) Control(org.eclipse.swt.widgets.Control) MergeResultDialog(org.eclipse.egit.ui.internal.merge.MergeResultDialog) Composite(org.eclipse.swt.widgets.Composite) FetchResult(org.eclipse.jgit.transport.FetchResult) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) FetchResultDialog(org.eclipse.egit.ui.internal.fetch.FetchResultDialog)

Example 9 with FetchResult

use of org.eclipse.jgit.transport.FetchResult in project statecharts by Yakindu.

the class GitRepositoryExampleService method isUpToDate.

@Override
public boolean isUpToDate(IProgressMonitor monitor) {
    java.nio.file.Path storageLocation = getStorageLocation();
    try {
        FetchCommand fetch = Git.open(storageLocation.toFile()).fetch();
        FetchResult result = fetch.setProgressMonitor(new EclipseGitProgressTransformer(monitor)).setDryRun(true).call();
        Collection<TrackingRefUpdate> trackingRefUpdates = result.getTrackingRefUpdates();
        return trackingRefUpdates.size() == 0;
    } catch (RepositoryNotFoundException ex) {
        // This is the case when the examples are imported manually
        return true;
    } catch (Exception ex) {
        ex.printStackTrace();
        return true;
    }
}
Also used : FetchResult(org.eclipse.jgit.transport.FetchResult) FetchCommand(org.eclipse.jgit.api.FetchCommand) TrackingRefUpdate(org.eclipse.jgit.transport.TrackingRefUpdate) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException)

Example 10 with FetchResult

use of org.eclipse.jgit.transport.FetchResult in project gerrit by GerritCodeReview.

the class GitUtil method cloneProject.

public static TestRepository<InMemoryRepository> cloneProject(Project.NameKey project, String uri) throws Exception {
    DfsRepositoryDescription desc = new DfsRepositoryDescription("clone of " + project.get());
    InMemoryRepository.Builder b = new InMemoryRepository.Builder().setRepositoryDescription(desc);
    if (uri.startsWith("ssh://")) {
        // SshTransport depends on a real FS to read ~/.ssh/config, but InMemoryRepository by default
        // uses a null FS.
        // Avoid leaking user state into our tests.
        b.setFS(FS.detect().setUserHome(null));
    }
    InMemoryRepository dest = b.build();
    Config cfg = dest.getConfig();
    cfg.setString("remote", "origin", "url", uri);
    cfg.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*");
    TestRepository<InMemoryRepository> testRepo = newTestRepository(dest);
    FetchResult result = testRepo.git().fetch().setRemote("origin").call();
    String originMaster = "refs/remotes/origin/master";
    if (result.getTrackingRefUpdate(originMaster) != null) {
        testRepo.reset(originMaster);
    }
    return testRepo;
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) FetchResult(org.eclipse.jgit.transport.FetchResult) Config(org.eclipse.jgit.lib.Config) DfsRepositoryDescription(org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription)

Aggregations

FetchResult (org.eclipse.jgit.transport.FetchResult)22 Ref (org.eclipse.jgit.lib.Ref)8 FetchCommand (org.eclipse.jgit.api.FetchCommand)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 Git (org.eclipse.jgit.api.Git)6 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)6 StoredConfig (org.eclipse.jgit.lib.StoredConfig)6 RefSpec (org.eclipse.jgit.transport.RefSpec)6 ObjectId (org.eclipse.jgit.lib.ObjectId)5 Repository (org.eclipse.jgit.lib.Repository)5 CheckoutCommand (org.eclipse.jgit.api.CheckoutCommand)3 NoRemoteRepositoryException (org.eclipse.jgit.errors.NoRemoteRepositoryException)3 Test (org.junit.Test)3 GeneralSecurityException (java.security.GeneralSecurityException)2 CoreException (org.eclipse.core.runtime.CoreException)2 CloneCommand (org.eclipse.jgit.api.CloneCommand)2 ListBranchCommand (org.eclipse.jgit.api.ListBranchCommand)2 MergeCommand (org.eclipse.jgit.api.MergeCommand)2 Status (org.eclipse.jgit.api.Status)2