summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--models/repo_generate.go19
-rw-r--r--modules/repository/generate.go15
-rw-r--r--modules/structs/repo.go2
-rw-r--r--routers/api/v1/repo/repo.go19
-rw-r--r--templates/swagger/v1_json.tmpl5
5 files changed, 40 insertions, 20 deletions
diff --git a/models/repo_generate.go b/models/repo_generate.go
index fc749f1120..03b0908397 100644
--- a/models/repo_generate.go
+++ b/models/repo_generate.go
@@ -20,15 +20,16 @@ import (
// GenerateRepoOptions contains the template units to generate
type GenerateRepoOptions struct {
- Name string
- Description string
- Private bool
- GitContent bool
- Topics bool
- GitHooks bool
- Webhooks bool
- Avatar bool
- IssueLabels bool
+ Name string
+ DefaultBranch string
+ Description string
+ Private bool
+ GitContent bool
+ Topics bool
+ GitHooks bool
+ Webhooks bool
+ Avatar bool
+ IssueLabels bool
}
// IsValid checks whether at least one option is chosen for generation
diff --git a/modules/repository/generate.go b/modules/repository/generate.go
index d0b5fa0820..cf219f4c26 100644
--- a/modules/repository/generate.go
+++ b/modules/repository/generate.go
@@ -184,7 +184,13 @@ func generateRepoCommit(ctx context.Context, repo, templateRepo, generateRepo *r
return fmt.Errorf("git remote add: %v", err)
}
- return initRepoCommit(ctx, tmpDir, repo, repo.Owner, templateRepo.DefaultBranch)
+ // set default branch based on whether it's specified in the newly generated repo or not
+ defaultBranch := repo.DefaultBranch
+ if strings.TrimSpace(defaultBranch) == "" {
+ defaultBranch = templateRepo.DefaultBranch
+ }
+
+ return initRepoCommit(ctx, tmpDir, repo, repo.Owner, defaultBranch)
}
func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *repo_model.Repository) (err error) {
@@ -208,7 +214,11 @@ func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *r
return fmt.Errorf("getRepositoryByID: %v", err)
}
- repo.DefaultBranch = templateRepo.DefaultBranch
+ // if there was no default branch supplied when generating the repo, use the default one from the template
+ if strings.TrimSpace(repo.DefaultBranch) == "" {
+ repo.DefaultBranch = templateRepo.DefaultBranch
+ }
+
gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath())
if err != nil {
return fmt.Errorf("openRepository: %v", err)
@@ -249,6 +259,7 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ
Name: opts.Name,
LowerName: strings.ToLower(opts.Name),
Description: opts.Description,
+ DefaultBranch: opts.DefaultBranch,
IsPrivate: opts.Private,
IsEmpty: !opts.GitContent || templateRepo.IsEmpty,
IsFsckEnabled: templateRepo.IsFsckEnabled,
diff --git a/modules/structs/repo.go b/modules/structs/repo.go
index 27d0b4f3ba..c218796620 100644
--- a/modules/structs/repo.go
+++ b/modules/structs/repo.go
@@ -201,6 +201,8 @@ type GenerateRepoOption struct {
// required: true
// unique: true
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
+ // Default branch of the new repository
+ DefaultBranch string `json:"default_branch"`
// Description of the repository to create
Description string `json:"description" binding:"MaxSize(255)"`
// Whether the repository is private
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index d266b3f4f3..7e386d2e5b 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -359,15 +359,16 @@ func Generate(ctx *context.APIContext) {
}
opts := models.GenerateRepoOptions{
- Name: form.Name,
- Description: form.Description,
- Private: form.Private,
- GitContent: form.GitContent,
- Topics: form.Topics,
- GitHooks: form.GitHooks,
- Webhooks: form.Webhooks,
- Avatar: form.Avatar,
- IssueLabels: form.Labels,
+ Name: form.Name,
+ DefaultBranch: form.DefaultBranch,
+ Description: form.Description,
+ Private: form.Private,
+ GitContent: form.GitContent,
+ Topics: form.Topics,
+ GitHooks: form.GitHooks,
+ Webhooks: form.Webhooks,
+ Avatar: form.Avatar,
+ IssueLabels: form.Labels,
}
if !opts.IsValid() {
diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl
index 1aec9ec06f..284e1c71a0 100644
--- a/templates/swagger/v1_json.tmpl
+++ b/templates/swagger/v1_json.tmpl
@@ -15412,6 +15412,11 @@
"type": "boolean",
"x-go-name": "Avatar"
},
+ "default_branch": {
+ "description": "Default branch of the new repository",
+ "type": "string",
+ "x-go-name": "DefaultBranch"
+ },
"description": {
"description": "Description of the repository to create",
"type": "string",