Search in sources :

Example 21 with GitSynchronizeData

use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeData in project egit by eclipse.

the class GitSubscriberMergeContext method scanDeltaAndRefresh.

private void scanDeltaAndRefresh(RepositoryMapping mapping, IResourceDelta delta) {
    Repository repo = mapping.getRepository();
    GitResourceDeltaVisitor visitor = new GitResourceDeltaVisitor(repo);
    try {
        delta.accept(visitor);
        Collection<IFile> files = visitor.getFileResourcesToUpdate();
        if (files != null && files.isEmpty())
            return;
        for (GitSynchronizeData gsd : gsds) {
            if (repo.equals(gsd.getRepository()))
                refreshResources(files);
        }
    } catch (CoreException e) {
        Activator.logError(e.getMessage(), e);
    }
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) Repository(org.eclipse.jgit.lib.Repository) GitResourceDeltaVisitor(org.eclipse.egit.core.internal.indexdiff.GitResourceDeltaVisitor) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException)

Example 22 with GitSynchronizeData

use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeData in project egit by eclipse.

the class SynchronizeWithMenu method fill.

@Override
public void fill(final Menu menu, int index) {
    if (srv == null)
        return;
    final IResource selectedResource = getSelection();
    if (selectedResource == null || selectedResource.isLinked(IResource.CHECK_ANCESTORS))
        return;
    RepositoryMapping mapping = RepositoryMapping.getMapping(selectedResource.getProject());
    if (mapping == null)
        return;
    final Repository repo = mapping.getRepository();
    if (repo == null)
        return;
    List<Ref> refs = new LinkedList<>();
    RefDatabase refDatabase = repo.getRefDatabase();
    try {
        refs.addAll(refDatabase.getAdditionalRefs());
    } catch (IOException e) {
    // do nothing
    }
    try {
        refs.addAll(refDatabase.getRefs(RefDatabase.ALL).values());
    } catch (IOException e) {
    // do nothing
    }
    Collections.sort(refs, CommonUtils.REF_ASCENDING_COMPARATOR);
    String currentBranch;
    try {
        currentBranch = repo.getFullBranch();
    } catch (IOException e) {
        // $NON-NLS-1$
        currentBranch = "";
    }
    int count = 0;
    String oldName = null;
    int refsLength = R_REFS.length();
    int tagsLength = R_TAGS.substring(refsLength).length();
    for (Ref ref : refs) {
        final String name = ref.getName();
        if (name.equals(Constants.HEAD) || name.equals(currentBranch) || excludeTag(ref, repo))
            continue;
        if (name.startsWith(R_REFS) && oldName != null && !oldName.regionMatches(refsLength, name, refsLength, tagsLength))
            new MenuItem(menu, SWT.SEPARATOR);
        MenuItem item = new MenuItem(menu, SWT.PUSH);
        item.setText(name);
        if (name.startsWith(Constants.R_TAGS))
            item.setImage(tagImage);
        else if (name.startsWith(Constants.R_HEADS) || name.startsWith(Constants.R_REMOTES))
            item.setImage(branchImage);
        item.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent event) {
                GitSynchronizeData data;
                try {
                    data = new GitSynchronizeData(repo, HEAD, name, true);
                    if (!(selectedResource instanceof IProject)) {
                        HashSet<IResource> resources = new HashSet<>();
                        resources.add(selectedResource);
                        data.setIncludedResources(resources);
                    }
                    GitModelSynchronize.launch(data, new IResource[] { selectedResource });
                } catch (IOException e) {
                    Activator.logError(e.getMessage(), e);
                }
            }
        });
        if (++count == MAX_NUM_MENU_ENTRIES)
            break;
        oldName = name;
    }
    if (count > 1)
        new MenuItem(menu, SWT.SEPARATOR);
    MenuItem custom = new MenuItem(menu, SWT.PUSH);
    custom.setText(UIText.SynchronizeWithMenu_custom);
    custom.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            GitSynchronizeWizard gitWizard = new GitSynchronizeWizard();
            WizardDialog wizard = new WizardDialog(menu.getShell(), gitWizard);
            wizard.create();
            wizard.open();
        }
    });
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) GitSynchronizeWizard(org.eclipse.egit.ui.internal.synchronize.GitSynchronizeWizard) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) IOException(java.io.IOException) RefDatabase(org.eclipse.jgit.lib.RefDatabase) LinkedList(java.util.LinkedList) IProject(org.eclipse.core.resources.IProject) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) SelectionEvent(org.eclipse.swt.events.SelectionEvent) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

Example 23 with GitSynchronizeData

use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeData in project egit by eclipse.

the class GitResourceVariantComparatorTest method shouldReturnFalseWhenShortContentIsDifferent.

/**
 * Comparing two files that have same content length but having small
 * difference inside content should return false.
 *
 * @throws Exception
 */
@Test
@SuppressWarnings("boxing")
public void shouldReturnFalseWhenShortContentIsDifferent() throws Exception {
    // when
    byte[] localContent = "very long long content".getBytes("UTF-8");
    // this typo should be here
    byte[] remoteContent = "very long lonk content".getBytes("UTF-8");
    GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, true);
    GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
    GitResourceVariantComparator grvc = new GitResourceVariantComparator(dataSet);
    // given
    IFile local = mock(IFile.class);
    when(local.exists()).thenReturn(true);
    when(local.getProject()).thenReturn(project.getProject());
    when(local.getContents()).thenReturn(new ByteArrayInputStream(localContent));
    IStorage storage = mock(IStorage.class);
    when(storage.getContents()).thenReturn(new ByteArrayInputStream(remoteContent));
    IResourceVariant remote = mock(IResourceVariant.class);
    when(remote.isContainer()).thenReturn(false);
    when(remote.getStorage(any(IProgressMonitor.class))).thenReturn(storage);
    // then
    assertFalse(grvc.compare(local, remote));
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) ByteArrayInputStream(java.io.ByteArrayInputStream) IStorage(org.eclipse.core.resources.IStorage) IResourceVariant(org.eclipse.team.core.variants.IResourceVariant) Test(org.junit.Test)

Example 24 with GitSynchronizeData

use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeData in project egit by eclipse.

the class GitResourceVariantComparatorTest method shouldReturnTrueWhenShortContentIsDifferent.

/**
 * Comparing two files that have the same content and content length should
 * return true
 *
 * @throws Exception
 */
@Test
@SuppressWarnings("boxing")
public void shouldReturnTrueWhenShortContentIsDifferent() throws Exception {
    // when
    byte[] localContent = "very long long content".getBytes("UTF-8");
    byte[] remoteContent = "very long long content".getBytes("UTF-8");
    GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, true);
    GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
    GitResourceVariantComparator grvc = new GitResourceVariantComparator(dataSet);
    // given
    IFile local = mock(IFile.class);
    when(local.exists()).thenReturn(true);
    when(local.getProject()).thenReturn(project.getProject());
    when(local.getContents()).thenReturn(new ByteArrayInputStream(localContent));
    IStorage storage = mock(IStorage.class);
    when(storage.getContents()).thenReturn(new ByteArrayInputStream(remoteContent));
    IResourceVariant remote = mock(IResourceVariant.class);
    when(remote.isContainer()).thenReturn(false);
    when(remote.getStorage(any(IProgressMonitor.class))).thenReturn(storage);
    // then
    assertTrue(grvc.compare(local, remote));
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) ByteArrayInputStream(java.io.ByteArrayInputStream) IStorage(org.eclipse.core.resources.IStorage) IResourceVariant(org.eclipse.team.core.variants.IResourceVariant) Test(org.junit.Test)

Example 25 with GitSynchronizeData

use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeData in project egit by eclipse.

the class GitResourceVariantTreeTest method shoulReturnSameResourceVariant.

/**
 * Check if getResourceVariant() does return the same resource that was
 * committed. Passes only when it is run as a single test, not as a part of
 * largest test suite
 *
 * @throws Exception
 */
@Test
public void shoulReturnSameResourceVariant() throws Exception {
    // when
    String fileName = "Main.java";
    File file = testRepo.createFile(iProject, fileName);
    testRepo.appendContentAndCommit(iProject, file, "class Main {}", "initial commit");
    IFile mainJava = testRepo.getIFile(iProject, file);
    GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, MASTER, false);
    GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
    GitSyncCache cache = GitSyncCache.getAllData(dataSet, new NullProgressMonitor());
    // given
    GitResourceVariantTree grvt = new GitRemoteResourceVariantTree(cache, dataSet);
    // then
    // null variant indicates that resource wasn't changed
    assertNull(grvt.getResourceVariant(mainJava));
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Test(org.junit.Test)

Aggregations

GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)42 GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)26 Test (org.junit.Test)15 Repository (org.eclipse.jgit.lib.Repository)14 IResource (org.eclipse.core.resources.IResource)13 IFile (org.eclipse.core.resources.IFile)10 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)9 IResourceVariant (org.eclipse.team.core.variants.IResourceVariant)9 IOException (java.io.IOException)8 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 HashSet (java.util.HashSet)7 IProject (org.eclipse.core.resources.IProject)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 IStorage (org.eclipse.core.resources.IStorage)6 ResourceMapping (org.eclipse.core.resources.mapping.ResourceMapping)5 RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 GitResourceVariantTreeSubscriber (org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber)3 GitSubscriberResourceMappingContext (org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext)3