Skip to content

Commit 85be939

Browse files
techknowlogickxenofem
andauthoredJul 8, 2020
properly set symbolic-ref HEAD when a repo is created with a non-master default branch (go-gitea#12135) (go-gitea#12182)
This fixes an issue I noticed with go-gitea#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 <45297511+xenofem@users.noreply.github.com>

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed
 

‎modules/repository/init.go

+7
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)
Please sign in to comment.