mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-12-21 07:49:55 +01:00
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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user