Skip to content

Commit a229fb5

Browse files
authored
Merge pull request #123 from nqminhuit/deduplicate-gis-branches
feat: Remove duplicate gis branches --no-module-name
2 parents ceb36f9 + 58aee5f commit a229fb5

2 files changed

Lines changed: 16 additions & 14 deletions

File tree

src/main/java/org/nqm/command/GitCommand.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ public class GitCommand {
4444

4545
public static final String GIT_STATUS = "status";
4646

47+
private static void printOutput(Stream<String> output) {
48+
output.filter(GisStringUtils::isNotBlank).forEach(StdOutUtils::println);
49+
}
50+
4751
private static void printOutput(Collection<String> output) {
48-
output.stream().filter(GisStringUtils::isNotBlank).forEach(StdOutUtils::println);
52+
printOutput(output.stream());
4953
}
5054

5155
@Command(name = "pull", aliases = "pu", description = "Fetch from and integrate with remote repositories")
@@ -234,7 +238,16 @@ void listBranches(
234238
sArgs = Stream.concat(sArgs, Stream.of(GIS_NO_PRINT_MODULES_NAME_OPT));
235239
}
236240
final var args = sArgs.toArray(String[]::new);
237-
printOutput(forEachModuleDo(args));
241+
var resultWithDuplicatedBranches = forEachModuleDo(args);
242+
if (noPrintModuleName) {
243+
var result = resultWithDuplicatedBranches.stream()
244+
.map(x -> x.split(GisStringUtils.NEWLINE))
245+
.flatMap(Stream::of)
246+
.distinct();
247+
printOutput(result);
248+
} else {
249+
printOutput(resultWithDuplicatedBranches);
250+
}
238251
}
239252

240253
@Command(name = "init", description = "init .gis-modules for current directory")

src/test/java/org/nqm/command/GitCommandIntTest.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ void listBranches_withoutModuleNames_OK() throws IOException {
161161
gis.listBranches(true, false);
162162

163163
// then:
164-
assertThat(outCaptor.toString().trim().split(NEWLINE)).containsExactlyInAnyOrder(
165-
"bb1", "master", "bb1", "master", "bb1", "master");
164+
assertThat(outCaptor.toString().trim().split(NEWLINE)).containsExactlyInAnyOrder("bb1", "master");
166165
}
167166

168167
@Test
@@ -188,16 +187,6 @@ void listBranchesWithRemote_withoutModuleNames_OK() throws IOException {
188187
// then:
189188
assertThat(outCaptor.toString().trim().split(NEWLINE))
190189
.containsExactlyInAnyOrder(
191-
"bb1",
192-
"bb2",
193-
"master",
194-
"origin/bb1",
195-
"origin/bb2",
196-
"bb1",
197-
"bb2",
198-
"master",
199-
"origin/bb1",
200-
"origin/bb2",
201190
"bb1",
202191
"bb2",
203192
"master",

0 commit comments

Comments
 (0)