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);
}
}
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();
}
});
}
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));
}
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));
}
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));
}
Aggregations