From 8e0548ed4a97470e1f4c6b61e398522fd1adb860 Mon Sep 17 00:00:00 2001 From: zeripath Date: Fri, 11 Dec 2020 21:41:59 +0000 Subject: [PATCH] Ensure that HEAD is updated to match default branch in template generation (#13948) Fix #13912 Signed-off-by: Andrew Thornton --- modules/repository/generate.go | 8 ++++++++ modules/repository/init.go | 1 + 2 files changed, 9 insertions(+) diff --git a/modules/repository/generate.go b/modules/repository/generate.go index 0142d689d160..1ba457fb3a55 100644 --- a/modules/repository/generate.go +++ b/modules/repository/generate.go @@ -207,6 +207,14 @@ func generateGitContent(ctx models.DBContext, repo, templateRepo, generateRepo * } repo.DefaultBranch = templateRepo.DefaultBranch + gitRepo, err := git.OpenRepository(repo.RepoPath()) + if err != nil { + return fmt.Errorf("openRepository: %v", err) + } + defer gitRepo.Close() + if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil { + return fmt.Errorf("setDefaultBranch: %v", err) + } if err = models.UpdateRepositoryCtx(ctx, repo, false); err != nil { return fmt.Errorf("updateRepository: %v", err) } diff --git a/modules/repository/init.go b/modules/repository/init.go index c94b44514da4..16012864b11d 100644 --- a/modules/repository/init.go +++ b/modules/repository/init.go @@ -323,6 +323,7 @@ func initRepository(ctx models.DBContext, repoPath string, u *models.User, repo if err != nil { return fmt.Errorf("openRepository: %v", err) } + defer gitRepo.Close() if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil { return fmt.Errorf("setDefaultBranch: %v", err) }