use of org.eclipse.jgit.diff.DiffEntry in project curiostack by curioswitch.
the class CurioGenericCiPlugin method computeAffectedFiles.
private static Set<String> computeAffectedFiles(Git git, CanonicalTreeParser oldTreeParser, CanonicalTreeParser newTreeParser, Project rootProject) {
final List<DiffEntry> diffs;
try {
diffs = git.diff().setNewTree(newTreeParser).setOldTree(oldTreeParser).setShowNameAndStatusOnly(true).call();
} catch (GitAPIException e) {
throw new IllegalStateException(e);
}
Set<String> affectedRelativePaths = new HashSet<>();
for (DiffEntry diff : diffs) {
switch(diff.getChangeType()) {
case ADD:
case MODIFY:
case COPY:
affectedRelativePaths.add(diff.getNewPath());
break;
case DELETE:
affectedRelativePaths.add(diff.getOldPath());
break;
case RENAME:
affectedRelativePaths.add(diff.getNewPath());
affectedRelativePaths.add(diff.getOldPath());
break;
}
}
var filtered = affectedRelativePaths.stream().filter(path -> !IGNORED_ROOT_FILES.contains(path)).collect(toImmutableSet());
rootProject.getLogger().info("Found diffs: {}", filtered);
return filtered;
}
Aggregations