use of org.eclipse.egit.core.internal.indexdiff.IndexDiffData in project egit by eclipse.
the class IndexDiffCacheTest method testModifyFileInIgnoredDir.
@Test
public void testModifyFileInIgnoredDir() throws Exception {
testRepository.connect(project.project);
project.createFile(".gitignore", "ignore\n".getBytes("UTF-8"));
project.createFolder("sub");
project.createFile("sub/ignore", new byte[] {});
testRepository.addToIndex(project.project);
testRepository.createInitialCommit("testRemoveIgnoredFile\n\nfirst commit\n");
prepareCacheEntry();
IndexDiffData data1 = waitForListenerCalled();
assertThat(data1.getIgnoredNotInIndex(), hasItem("Project-1/sub/ignore"));
IFile file = project.getProject().getFile("sub/ignore");
FileOutputStream str = new FileOutputStream(file.getLocation().toFile());
try {
str.write("other contents".getBytes("UTF-8"));
} finally {
str.close();
}
// no job should be triggered for that change.
waitForListenerNotCalled();
}
use of org.eclipse.egit.core.internal.indexdiff.IndexDiffData in project egit by eclipse.
the class StashCreateHandler method isEnabled.
static boolean isEnabled(Repository repository) {
if (repository == null)
return false;
if (!repository.getRepositoryState().canCommit())
return false;
IndexDiffCacheEntry entry = Activator.getDefault().getIndexDiffCache().getIndexDiffCacheEntry(repository);
if (entry == null)
return false;
IndexDiffData diff = entry.getIndexDiff();
if (diff == null)
return false;
if (diff.getAdded().isEmpty() && diff.getChanged().isEmpty() && diff.getRemoved().isEmpty() && diff.getUntracked().isEmpty() && diff.getModified().isEmpty() && diff.getMissing().isEmpty())
return false;
return true;
}
use of org.eclipse.egit.core.internal.indexdiff.IndexDiffData in project egit by eclipse.
the class CommitActionHandler method getIndexDiffData.
private IndexDiffData getIndexDiffData(@NonNull final Repository repository, @NonNull final Collection<IProject> projects) {
IndexDiffCacheEntry diffCacheEntry = org.eclipse.egit.core.Activator.getDefault().getIndexDiffCache().getIndexDiffCacheEntry(repository);
IndexDiffData diff = null;
if (diffCacheEntry != null) {
diff = diffCacheEntry.getIndexDiff();
}
if (diff != null) {
return diff;
}
final IndexDiffData[] result = { null };
try {
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
result[0] = new IndexDiffData(CommitUI.getIndexDiff(repository, projects.toArray(new IProject[projects.size()]), monitor));
} catch (IOException e) {
throw new InvocationTargetException(e);
}
}
});
} catch (InvocationTargetException e) {
Activator.handleError(UIText.CommitAction_errorComputingDiffs, e.getCause(), true);
return null;
} catch (InterruptedException e) {
return null;
}
return result[0];
}
use of org.eclipse.egit.core.internal.indexdiff.IndexDiffData in project egit by eclipse.
the class CommitActionHandler method autoStage.
private void autoStage(@NonNull final Repository repository, boolean includeUntracked, IResource[] resourcesInScope) {
if (resourcesInScope == null || resourcesInScope.length == 0) {
return;
}
final Set<IProject> projects = new HashSet<>();
for (IResource rsc : resourcesInScope) {
projects.add(rsc.getProject());
}
IndexDiffData diff = getIndexDiffData(repository, projects);
if (diff == null) {
return;
}
Set<String> mayBeCommitted = new HashSet<>();
mayBeCommitted.addAll(diff.getAdded());
mayBeCommitted.addAll(diff.getChanged());
mayBeCommitted.addAll(diff.getRemoved());
mayBeCommitted.addAll(diff.getModified());
mayBeCommitted.addAll(diff.getMissing());
if (!includeUntracked) {
mayBeCommitted.removeAll(diff.getUntracked());
} else {
mayBeCommitted.addAll(diff.getUntracked());
}
mayBeCommitted.removeAll(diff.getAssumeUnchanged());
final Set<String> toBeStaged = CommitUI.getSelectedFiles(repository, mayBeCommitted, resourcesInScope);
if (toBeStaged.isEmpty()) {
return;
}
Job job = new Job(UIText.AddToIndexAction_addingFiles) {
@Override
protected IStatus run(IProgressMonitor monitor) {
SubMonitor progress = SubMonitor.convert(monitor, toBeStaged.size() + 1);
try (Git git = new Git(repository)) {
AddCommand add = git.add();
for (String toStage : toBeStaged) {
add.addFilepattern(toStage);
if (progress.isCanceled()) {
return Status.CANCEL_STATUS;
}
progress.worked(1);
}
add.call();
progress.worked(1);
} catch (GitAPIException e) {
return Activator.createErrorStatus(CoreText.AddToIndexOperation_failed, e);
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
@Override
public boolean belongsTo(Object family) {
return JobFamilies.ADD_TO_INDEX.equals(family) || super.belongsTo(family);
}
};
job.setUser(true);
job.setRule(RuleUtil.getRule(repository));
job.schedule();
}
use of org.eclipse.egit.core.internal.indexdiff.IndexDiffData in project egit by eclipse.
the class IndexDiffCacheTest method testAddFileFromUntrackedFolder.
@Test
public void testAddFileFromUntrackedFolder() throws Exception {
testRepository.connect(project.project);
testRepository.addToIndex(project.project);
testRepository.createInitialCommit("testAddFileFromUntrackedFolder\n\nfirst commit\n");
prepareCacheEntry();
project.createFolder("folder");
project.createFolder("folder/a");
project.createFolder("folder/b");
IFile fileA = project.createFile("folder/a/file", new byte[] {});
project.createFile("folder/b/file", new byte[] {});
IndexDiffData data1 = waitForListenerCalled();
assertThat(data1.getUntrackedFolders(), hasItem("Project-1/folder/"));
testRepository.track(fileA.getLocation().toFile());
IndexDiffData data2 = waitForListenerCalled();
assertThat(data2.getAdded(), hasItem("Project-1/folder/a/file"));
assertThat(data2.getUntrackedFolders(), not(hasItem("Project-1/folder/")));
assertThat(data2.getUntrackedFolders(), not(hasItem("Project-1/folder/a")));
assertThat(data2.getUntrackedFolders(), hasItem("Project-1/folder/b/"));
}
Aggregations