tests: Support creating a declarative repo without AutoInit

To be able to easily test cases where the repository does not have any
code, where the git repo itself is completely uninitialized, lets
support a case where the `AutoInit` property is false.

For the sake of backwards compatibility, if the option is not set either
way, it will default to `true`.

Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
This commit is contained in:
Gergely Nagy 2024-04-30 01:35:40 +02:00
parent 6f35a5ab90
commit f83ae0fad2
No known key found for this signature in database

View file

@ -660,6 +660,7 @@ type DeclarativeRepoOptions struct {
DisabledUnits optional.Option[[]unit_model.Type]
Files optional.Option[[]*files_service.ChangeRepoFile]
WikiBranch optional.Option[string]
AutoInit optional.Option[bool]
}
func CreateDeclarativeRepoWithOptions(t *testing.T, owner *user_model.User, opts DeclarativeRepoOptions) (*repo_model.Repository, string, func()) {
@ -674,11 +675,18 @@ func CreateDeclarativeRepoWithOptions(t *testing.T, owner *user_model.User, opts
repoName = gouuid.NewString()
}
var autoInit bool
if opts.AutoInit.Has() {
autoInit = opts.AutoInit.Value()
} else {
autoInit = true
}
// Create the repository
repo, err := repo_service.CreateRepository(db.DefaultContext, owner, owner, repo_service.CreateRepoOptions{
Name: repoName,
Description: "Temporary Repo",
AutoInit: true,
AutoInit: autoInit,
Gitignores: "",
License: "WTFPL",
Readme: "Default",
@ -710,6 +718,7 @@ func CreateDeclarativeRepoWithOptions(t *testing.T, owner *user_model.User, opts
// Add files, if any.
var sha string
if opts.Files.Has() {
assert.True(t, autoInit, "Files cannot be specified if AutoInit is disabled")
files := opts.Files.Value()
resp, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, owner, &files_service.ChangeRepoFilesOptions{