Skip to content

Commit 85be939

Browse files
properly set symbolic-ref HEAD when a repo is created with a non-master default branch (#12135) (#12182)
This fixes an issue I noticed with #10803: when you create a repo with a non-master default branch, gitea doesn't change the remote ref HEAD, so it still points at refs/heads/master. As a result, cloning my repos gives me error messages and doesn't check out the desired default branch, so I need to manually check it out after cloning. Co-authored-by: xenofem <[email protected]>
1 parent a680c91 commit 85be939

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

modules/repository/init.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ func initRepository(ctx models.DBContext, repoPath string, u *models.User, repo
214214
repo.DefaultBranch = "master"
215215
if len(opts.DefaultBranch) > 0 {
216216
repo.DefaultBranch = opts.DefaultBranch
217+
gitRepo, err := git.OpenRepository(repo.RepoPath())
218+
if err != nil {
219+
return fmt.Errorf("openRepository: %v", err)
220+
}
221+
if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil {
222+
return fmt.Errorf("setDefaultBranch: %v", err)
223+
}
217224
}
218225

219226
if err = models.UpdateRepositoryCtx(ctx, repo, false); err != nil {

0 commit comments

Comments
 (0)