diff --git a/src/main/java/org/nqm/command/GitCommand.java b/src/main/java/org/nqm/command/GitCommand.java index 5e67eb1..c9ac364 100644 --- a/src/main/java/org/nqm/command/GitCommand.java +++ b/src/main/java/org/nqm/command/GitCommand.java @@ -44,8 +44,12 @@ public class GitCommand { public static final String GIT_STATUS = "status"; + private static void printOutput(Stream output) { + output.filter(GisStringUtils::isNotBlank).forEach(StdOutUtils::println); + } + private static void printOutput(Collection output) { - output.stream().filter(GisStringUtils::isNotBlank).forEach(StdOutUtils::println); + printOutput(output.stream()); } @Command(name = "pull", aliases = "pu", description = "Fetch from and integrate with remote repositories") @@ -234,7 +238,16 @@ void listBranches( sArgs = Stream.concat(sArgs, Stream.of(GIS_NO_PRINT_MODULES_NAME_OPT)); } final var args = sArgs.toArray(String[]::new); - printOutput(forEachModuleDo(args)); + var resultWithDuplicatedBranches = forEachModuleDo(args); + if (noPrintModuleName) { + var result = resultWithDuplicatedBranches.stream() + .map(x -> x.split(GisStringUtils.NEWLINE)) + .flatMap(Stream::of) + .distinct(); + printOutput(result); + } else { + printOutput(resultWithDuplicatedBranches); + } } @Command(name = "init", description = "init .gis-modules for current directory") diff --git a/src/test/java/org/nqm/command/GitCommandIntTest.java b/src/test/java/org/nqm/command/GitCommandIntTest.java index cb4246e..ba02cab 100644 --- a/src/test/java/org/nqm/command/GitCommandIntTest.java +++ b/src/test/java/org/nqm/command/GitCommandIntTest.java @@ -161,8 +161,7 @@ void listBranches_withoutModuleNames_OK() throws IOException { gis.listBranches(true, false); // then: - assertThat(outCaptor.toString().trim().split(NEWLINE)).containsExactlyInAnyOrder( - "bb1", "master", "bb1", "master", "bb1", "master"); + assertThat(outCaptor.toString().trim().split(NEWLINE)).containsExactlyInAnyOrder("bb1", "master"); } @Test @@ -188,16 +187,6 @@ void listBranchesWithRemote_withoutModuleNames_OK() throws IOException { // then: assertThat(outCaptor.toString().trim().split(NEWLINE)) .containsExactlyInAnyOrder( - "bb1", - "bb2", - "master", - "origin/bb1", - "origin/bb2", - "bb1", - "bb2", - "master", - "origin/bb1", - "origin/bb2", "bb1", "bb2", "master",