Skip to content

Commit 8e0548e

Browse files
authored
Ensure that HEAD is updated to match default branch in template generation (#13948)
Fix #13912 Signed-off-by: Andrew Thornton <[email protected]>
1 parent f2f99a7 commit 8e0548e

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

modules/repository/generate.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@ func generateGitContent(ctx models.DBContext, repo, templateRepo, generateRepo *
207207
}
208208

209209
repo.DefaultBranch = templateRepo.DefaultBranch
210+
gitRepo, err := git.OpenRepository(repo.RepoPath())
211+
if err != nil {
212+
return fmt.Errorf("openRepository: %v", err)
213+
}
214+
defer gitRepo.Close()
215+
if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil {
216+
return fmt.Errorf("setDefaultBranch: %v", err)
217+
}
210218
if err = models.UpdateRepositoryCtx(ctx, repo, false); err != nil {
211219
return fmt.Errorf("updateRepository: %v", err)
212220
}

modules/repository/init.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ func initRepository(ctx models.DBContext, repoPath string, u *models.User, repo
323323
if err != nil {
324324
return fmt.Errorf("openRepository: %v", err)
325325
}
326+
defer gitRepo.Close()
326327
if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil {
327328
return fmt.Errorf("setDefaultBranch: %v", err)
328329
}

0 commit comments

Comments
 (0)