Skip to content

Commit 01f08ae

Browse files
committed
fix: set default branch on main
1 parent 76276f6 commit 01f08ae

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

testcontainers-gitserver/src/main/java/com/github/sparsick/testcontainers/gitserver/plain/GitServerContainer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
public class GitServerContainer extends GenericContainer<GitServerContainer> {
1818

1919
private static final String GIT_PASSWORD_KEY = "GIT_PASSWORD";
20-
private static DockerImageName DEFAULT_DOCKER_IMAGE_NAME = DockerImageName.parse("rockstorm/git-server");
20+
private static final DockerImageName DEFAULT_DOCKER_IMAGE_NAME = DockerImageName.parse("rockstorm/git-server");
2121
private String gitRepoName = "testRepo";
2222
private String pathToExistingRepo;
2323
private SshIdentity sshClientIdentity;
@@ -153,6 +153,7 @@ private void configureGitRepository() {
153153
execInContainer("git", "init", "--bare", gitRepoPath);
154154
execInContainer("chown", "-R", "git:git", "/srv");
155155
}
156+
execInContainer("git", "symbolic-ref", "HEAD", "refs/heads/main");
156157
} catch (IOException | InterruptedException e) {
157158
throw new RuntimeException("Configure Git repository failed",e);
158159
}

testcontainers-gitserver/src/test/java/com/github/sparsick/testcontainers/gitserver/plain/GitServerContainerTest.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.util.List;
3232
import java.util.Map;
3333
import java.util.stream.Stream;
34-
import java.util.stream.StreamSupport;
3534

3635
import static org.assertj.core.api.Assertions.assertThatNoException;
3736
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -126,7 +125,6 @@ void copyExistingGitRepo(@TempDir File sampleRepo) throws GitAPIException, IOExc
126125
Git.cloneRepository()
127126
.setURI(gitRepoURI.toString())
128127
.setDirectory(tempDir)
129-
.setBranch("main")
130128
.setTransportConfigCallback(GitServerContainerTest::configureWithPasswordAndNoHostKeyChecking)
131129
.call()
132130
);
@@ -149,7 +147,6 @@ void copyExistingGitRepoWithCustomRepoName(@TempDir File sampleRepo) throws IOEx
149147
Git.cloneRepository()
150148
.setURI(gitRepoURI.toString())
151149
.setDirectory(tempDir)
152-
.setBranch("main")
153150
.setTransportConfigCallback(GitServerContainerTest::configureWithPasswordAndNoHostKeyChecking)
154151
.call()
155152
);
@@ -170,7 +167,6 @@ void setupGitRepo(GitServerVersions gitServer) {
170167
Git.cloneRepository()
171168
.setURI(gitRepoURI.toString())
172169
.setDirectory(tempDir)
173-
.setBranch("main")
174170
.setTransportConfigCallback(GitServerContainerTest::configureWithPasswordAndNoHostKeyChecking)
175171
.call()
176172
);
@@ -189,7 +185,6 @@ void pubKeyAuth(GitServerVersions gitServer) {
189185
Git.cloneRepository()
190186
.setURI(gitRepoURI.toString())
191187
.setDirectory(tempDir)
192-
.setBranch("main")
193188
.setTransportConfigCallback(configureWithSshIdentityAndNoHostVerification(containerUnderTest.getSshClientIdentity()))
194189
.call()
195190
);
@@ -210,12 +205,30 @@ void strictHostKeyVerifivation(GitServerVersions gitServer) {
210205
Git.cloneRepository()
211206
.setURI(gitRepoURI.toString())
212207
.setDirectory(tempDir)
213-
.setBranch("main")
214208
.setTransportConfigCallback(configureWithSshIdentityAndHostKey(containerUnderTest.getSshClientIdentity(), containerUnderTest.getHostKey()))
215209
.call()
216210
);
217211
}
218212

213+
@ParameterizedTest
214+
@EnumSource(GitServerVersions.class)
215+
void defaultBranch(GitServerVersions gitServer) throws GitAPIException, IOException {
216+
var containerUnderTest = new GitServerContainer(gitServer.getDockerImageName());
217+
218+
containerUnderTest.start();
219+
220+
URI gitRepoURI = containerUnderTest.getGitRepoURIAsSSH();
221+
222+
Git repo = Git.cloneRepository()
223+
.setURI(gitRepoURI.toString())
224+
.setDirectory(tempDir)
225+
.setTransportConfigCallback(GitServerContainerTest::configureWithPasswordAndNoHostKeyChecking)
226+
.call();
227+
228+
String currentBranch = repo.getRepository().getBranch();
229+
assertThat(currentBranch).isEqualTo("main");
230+
}
231+
219232
@NotNull
220233
private TransportConfigCallback configureWithSshIdentityAndHostKey(SshIdentity sshIdentity, SshHostKey hostKey) {
221234
return transport -> {

0 commit comments

Comments
 (0)