Set HEAD to correct default branch (#1929)

Sets the HEAD for new Git repositories to the default branch (this is 'main' for the default configuration).
This change led to errors in unit tests, that depended on the 'master' branch.

Co-authored-by: Eduard Heimbuch <eduard.heimbuch@cloudogu.com>
This commit is contained in:
René Pfeuffer
2022-01-20 10:19:27 +01:00
committed by GitHub
parent 0f01bb82c6
commit 6e555a855a
8 changed files with 46 additions and 17 deletions

View File

@@ -24,8 +24,6 @@
package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -36,13 +34,12 @@ import sonia.scm.store.ConfigurationStoreFactory;
import java.io.File;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
//~--- JDK imports ------------------------------------------------------------
/**
* @author Sebastian Sdorra
*/
@@ -112,4 +109,21 @@ public class GitRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
File path = repositoryHandler.getDirectory(repository.getId());
assertEquals(repoPath.toString() + File.separator + RepositoryDirectoryHandler.REPOSITORIES_NATIVE_DIRECTORY, path.getAbsolutePath());
}
@Test
public void shouldSetHeadToDefaultRepository() {
GitRepositoryHandler repositoryHandler = new GitRepositoryHandler(factory,
scheduler, locationResolver, gitWorkingCopyFactory, null);
GitConfig config = new GitConfig();
config.setDefaultBranch("other");
repositoryHandler.setConfig(config);
File nativeRepoDirectory = initRepository();
repositoryHandler.create(repository);
assertThat(new File(nativeRepoDirectory, "HEAD")).hasContent("ref: refs/heads/other");
}
}

View File

@@ -295,7 +295,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
ChangesetPagingResult changesets = createCommand().getChangesets(new LogCommandRequest());
assertEquals("master", changesets.getBranchName());
assertEquals("main", changesets.getBranchName());
}
@Test