Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: include remotes in gis branches #94

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/main/java/org/nqm/command/GitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,13 @@ void stash(@Option(names = "-pp", description = "pop first stashed changes") boo

@Command(name = "branches")
void listBranches(
@Option(names = "-nn", description = "do not print module name") boolean noPrintModuleName)
@Option(names = "-nn", description = "do not print module name") boolean noPrintModuleName,
@Option(names = "--include-remotes", description = "include remote branches") boolean includeRemotes)
throws IOException {
var sArgs = Stream.of("for-each-ref", "--format=%(refname:short)", "refs/heads/");
var sArgs = Stream.of("for-each-ref", "--format=%(refname:short)", "refs/heads");
if (includeRemotes) {
sArgs = Stream.concat(sArgs, Stream.of("refs/remotes"));
}
if (noPrintModuleName) {
sArgs = Stream.concat(sArgs, Stream.of("--gis-no-print-modules-name"));
}
Expand Down
46 changes: 43 additions & 3 deletions src/test/java/org/nqm/command/GitCommandIntTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void listBranches_withEmptyModifiedFiles_OK() throws IOException {
gis.init();

// when:
gis.listBranches(false);
gis.listBranches(false, false);

// then:
assertThat(stripColors.apply(outCaptor.toString()))
Expand All @@ -105,7 +105,7 @@ void listBranches_withModuleNames_OK() throws IOException {
resetOutputStreamTest();

// when:
gis.listBranches(false);
gis.listBranches(false, false);

// then:
assertThat(stripColors.apply(outCaptor.toString()))
Expand Down Expand Up @@ -133,13 +133,53 @@ void listBranches_withoutModuleNames_OK() throws IOException {
resetOutputStreamTest();

// when:
gis.listBranches(true);
gis.listBranches(true, false);

// then:
assertThat(outCaptor.toString().split("%n".formatted())).containsExactlyInAnyOrder(
"bb1", "master", "bb1", "master", "bb1", "master");
}

@Test
void listBranchesWithRemote_withoutModuleNames_OK() throws IOException {
// given:
var repos = create_clone_gitRepositories("opu_7_i", "opu_8_ii", "opu_9_iii");
commitFile(repos);
gis.init();
gis.checkoutNewBranch("bb1");
commitFile(repos);
System.setIn(new ByteArrayInputStream("y".getBytes()));
gis.push("bb1", true, true);

gis.checkoutNewBranch("bb2");
commitFile(repos);
System.setIn(new ByteArrayInputStream("ye".getBytes()));
gis.push("bb2", true, true);
resetOutputStreamTest();

// when:
gis.listBranches(true, true);

// then:
assertThat(outCaptor.toString().split("%n".formatted()))
.containsExactlyInAnyOrder(
"bb1",
"bb2",
"master",
"origin/bb1",
"origin/bb2",
"bb1",
"bb2",
"master",
"origin/bb1",
"origin/bb2",
"bb1",
"bb2",
"master",
"origin/bb1",
"origin/bb2");
}

@Test
void listFilesChanged_OK() throws IOException {
// given:
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/nqm/command/GitCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void listBranches_withModuleName_OK() throws IOException {
ExecutorsMock.mockVirtualThreadRunnable(exe);

// when:
gis.listBranches(false);
gis.listBranches(false, false);

// then:
verify(exe, times(2)).submit((Callable<?>) any());
Expand All @@ -167,7 +167,7 @@ void listBranches_withoutModuleName_OK() throws IOException {
ExecutorsMock.mockVirtualThreadRunnable(exe);

// when:
gis.listBranches(true);
gis.listBranches(true, false);

// then:
verify(exe, times(2)).submit((Callable<?>) any());
Expand Down
Loading