mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 00:15:44 +01:00
Do not try to init non-git repos for git
The initialization to set the default branch in git repositories should not be executed for non-git repositories. Otherwise, this throws exceptions in SVN repositories all the time because the branch command is not supported. Committed-by: Konstantin Schaper <konstantin.schaper@cloudogu.com>
This commit is contained in:
2
gradle/changelog/git_initialization.yaml
Normal file
2
gradle/changelog/git_initialization.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
- type: fixed
|
||||
description: Exception in SVN repositories due to incorrect git initialization
|
||||
@@ -50,6 +50,7 @@ public class GitRepositoryConfigInitializer {
|
||||
|
||||
@Subscribe
|
||||
public void initConfig(PostReceiveRepositoryHookEvent event) {
|
||||
if (GitRepositoryHandler.TYPE_NAME.equals(event.getRepository().getType())) {
|
||||
ConfigurationStore<GitRepositoryConfig> store = storeProvider.get(event.getRepository());
|
||||
GitRepositoryConfig repositoryConfig = store.get();
|
||||
if (repositoryConfig == null || Strings.isNullOrEmpty(repositoryConfig.getDefaultBranch())) {
|
||||
@@ -61,6 +62,7 @@ public class GitRepositoryConfigInitializer {
|
||||
store.set(gitRepositoryConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String determineDefaultBranch(List<String> defaultBranchCandidates) {
|
||||
String globalConfigDefaultBranch = repoHandler.getConfig().getDefaultBranch();
|
||||
|
||||
@@ -65,10 +65,27 @@ class GitRepositoryConfigInitializerTest {
|
||||
@InjectMocks
|
||||
private GitRepositoryConfigInitializer initializer;
|
||||
|
||||
@Test
|
||||
void shouldSkipNonGitRepositories() {
|
||||
REPOSITORY.setType("svn");
|
||||
|
||||
initializer.initConfig(event);
|
||||
|
||||
verify(event, never()).getContext();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void initEvent() {
|
||||
when(event.getRepository()).thenReturn(REPOSITORY);
|
||||
}
|
||||
|
||||
@Nested
|
||||
class ForGitRepositories {
|
||||
|
||||
@BeforeEach
|
||||
void initMocks() {
|
||||
when(storeProvider.get(REPOSITORY)).thenReturn(configStore);
|
||||
when(event.getRepository()).thenReturn(REPOSITORY);
|
||||
REPOSITORY.setType("git");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -173,5 +190,5 @@ class GitRepositoryConfigInitializerTest {
|
||||
when(hookContext.getBranchProvider()).thenReturn(branchProvider);
|
||||
when(branchProvider.getCreatedOrModified()).thenReturn(branches);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user