@@ -184,7 +184,13 @@ func generateRepoCommit(ctx context.Context, repo, templateRepo, generateRepo *r
184184 return fmt .Errorf ("git remote add: %v" , err )
185185 }
186186
187- return initRepoCommit (ctx , tmpDir , repo , repo .Owner , templateRepo .DefaultBranch )
187+ // set default branch based on whether it's specified in the newly generated repo or not
188+ defaultBranch := repo .DefaultBranch
189+ if strings .TrimSpace (defaultBranch ) == "" {
190+ defaultBranch = templateRepo .DefaultBranch
191+ }
192+
193+ return initRepoCommit (ctx , tmpDir , repo , repo .Owner , defaultBranch )
188194}
189195
190196func 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
208214 return fmt .Errorf ("getRepositoryByID: %v" , err )
209215 }
210216
211- repo .DefaultBranch = templateRepo .DefaultBranch
217+ // if there was no default branch supplied when generating the repo, use the default one from the template
218+ if strings .TrimSpace (repo .DefaultBranch ) == "" {
219+ repo .DefaultBranch = templateRepo .DefaultBranch
220+ }
221+
212222 gitRepo , err := git .OpenRepositoryCtx (ctx , repo .RepoPath ())
213223 if err != nil {
214224 return fmt .Errorf ("openRepository: %v" , err )
@@ -249,6 +259,7 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ
249259 Name : opts .Name ,
250260 LowerName : strings .ToLower (opts .Name ),
251261 Description : opts .Description ,
262+ DefaultBranch : opts .DefaultBranch ,
252263 IsPrivate : opts .Private ,
253264 IsEmpty : ! opts .GitContent || templateRepo .IsEmpty ,
254265 IsFsckEnabled : templateRepo .IsFsckEnabled ,
0 commit comments