Add statistics for diffs (added, deleted, modified)

Extend the diff result from the diff command to include modified,
added and deleted file count and add DiffStats component to
ui-components.

Pushed-by: Rene Pfeuffer<rene.pfeuffer@cloudogu.com>
Pushed-by: Tarik Gürsoy<tarik.guersoy@cloudogu.com>
Co-authored-by: René Pfeuffer<rene.pfeuffer@cloudogu.com>
Co-authored-by: Tarik Gürsoy<tarik.guersoy@cloudogu.com>
This commit is contained in:
Tarik Gürsoy
2024-08-01 16:54:40 +02:00
parent 0708d1f2c5
commit 797bda4bbb
15 changed files with 200 additions and 38 deletions

View File

@@ -188,4 +188,26 @@ public class GitDiffResult implements DiffResult {
public IgnoreWhitespaceLevel getIgnoreWhitespace() {
return ignoreWhitespaceLevel;
}
@Override
public Optional<DiffStatistics> getStatistics() {
int addCounter = 0;
int modifiedCounter = 0;
int deletedCounter = 0;
for (DiffEntry diffEntry : diffEntries) {
switch (diffEntry.getChangeType()) {
case ADD:
++addCounter;
break;
case MODIFY:
++modifiedCounter;
break;
case DELETE:
++deletedCounter;
break;
}
}
DiffStatistics stats = new DiffStatistics(addCounter, modifiedCounter, deletedCounter);
return Optional.of(stats);
}
}

View File

@@ -181,6 +181,14 @@ public class GitDiffResultCommandTest extends AbstractGitCommandTestBase {
assertThat(hunks).isExhausted();
}
@Test
public void shouldComputeStatistics() throws IOException {
DiffResult diffResult = createDiffResult("3f76a12f08a6ba0dc988c68b7f0b2cd190efc3c4");
assertThat(diffResult.getStatistics()).get().extracting("deleted").isEqualTo(1);
assertThat(diffResult.getStatistics()).get().extracting("modified").isEqualTo(1);
assertThat(diffResult.getStatistics()).get().extracting("added").isEqualTo(0);
}
@Test
public void shouldNotIgnoreWhiteSpace() throws IOException {
GitDiffResultCommand gitDiffResultCommand = new GitDiffResultCommand(createContext());