@ -184,7 +184,13 @@ func generateRepoCommit(ctx context.Context, repo, templateRepo, generateRepo *r
return fmt . Errorf ( "git remote add: %v" , err )
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 ) {
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 )
return fmt . Errorf ( "getRepositoryByID: %v" , err )
}
}
// 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
repo . DefaultBranch = templateRepo . DefaultBranch
}
gitRepo , err := git . OpenRepositoryCtx ( ctx , repo . RepoPath ( ) )
gitRepo , err := git . OpenRepositoryCtx ( ctx , repo . RepoPath ( ) )
if err != nil {
if err != nil {
return fmt . Errorf ( "openRepository: %v" , err )
return fmt . Errorf ( "openRepository: %v" , err )
@ -249,6 +259,7 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ
Name : opts . Name ,
Name : opts . Name ,
LowerName : strings . ToLower ( opts . Name ) ,
LowerName : strings . ToLower ( opts . Name ) ,
Description : opts . Description ,
Description : opts . Description ,
DefaultBranch : opts . DefaultBranch ,
IsPrivate : opts . Private ,
IsPrivate : opts . Private ,
IsEmpty : ! opts . GitContent || templateRepo . IsEmpty ,
IsEmpty : ! opts . GitContent || templateRepo . IsEmpty ,
IsFsckEnabled : templateRepo . IsFsckEnabled ,
IsFsckEnabled : templateRepo . IsFsckEnabled ,