Skip to content

Commit

Permalink
feat: Remove duplicate gis branches --no-module-name
Browse files Browse the repository at this point in the history
fix: #122
  • Loading branch information
minh committed Aug 7, 2024
1 parent ceb36f9 commit 58aee5f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
17 changes: 15 additions & 2 deletions src/main/java/org/nqm/command/GitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ public class GitCommand {

public static final String GIT_STATUS = "status";

private static void printOutput(Stream<String> output) {
output.filter(GisStringUtils::isNotBlank).forEach(StdOutUtils::println);
}

private static void printOutput(Collection<String> 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")
Expand Down Expand Up @@ -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")
Expand Down
13 changes: 1 addition & 12 deletions src/test/java/org/nqm/command/GitCommandIntTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down

0 comments on commit 58aee5f

Please sign in to comment.