@@ -660,13 +660,6 @@ func RepoAssignment(ctx *Context) context.CancelFunc {
660660 return cancel
661661 }
662662
663- tags , err := repo_model .GetTagNamesByRepoID (ctx , ctx .Repo .Repository .ID )
664- if err != nil {
665- ctx .ServerError ("GetTagNamesByRepoID" , err )
666- return cancel
667- }
668- ctx .Data ["Tags" ] = tags
669-
670663 branchOpts := git_model.FindBranchOptions {
671664 RepoID : ctx .Repo .Repository .ID ,
672665 IsDeletedBranch : util .OptionalBoolFalse ,
@@ -680,7 +673,7 @@ func RepoAssignment(ctx *Context) context.CancelFunc {
680673 return cancel
681674 }
682675
683- // non empty repo should have at least 1 branch, so this repository's branches haven't been synced yet
676+ // non- empty repo should have at least 1 branch, so this repository's branches haven't been synced yet
684677 if branchesTotal == 0 { // fallback to do a sync immediately
685678 branchesTotal , err = repo_module .SyncRepoBranches (ctx , ctx .Repo .Repository .ID , 0 )
686679 if err != nil {
@@ -689,24 +682,19 @@ func RepoAssignment(ctx *Context) context.CancelFunc {
689682 }
690683 }
691684
692- // FIXME: use paganation and async loading
693- branchOpts .ExcludeBranchNames = []string {ctx .Repo .Repository .DefaultBranch }
694- brs , err := git_model .FindBranchNames (ctx , branchOpts )
695- if err != nil {
696- ctx .ServerError ("GetBranches" , err )
697- return cancel
698- }
699- // always put default branch on the top
700- ctx .Data ["Branches" ] = append (branchOpts .ExcludeBranchNames , brs ... )
701685 ctx .Data ["BranchesCount" ] = branchesTotal
702686
703- // If not branch selected, try default one.
704- // If default branch doesn't exist, fall back to some other branch.
687+ // If no branch is set in the request URL, try to guess a default one.
705688 if len (ctx .Repo .BranchName ) == 0 {
706689 if len (ctx .Repo .Repository .DefaultBranch ) > 0 && gitRepo .IsBranchExist (ctx .Repo .Repository .DefaultBranch ) {
707690 ctx .Repo .BranchName = ctx .Repo .Repository .DefaultBranch
708- } else if len (brs ) > 0 {
709- ctx .Repo .BranchName = brs [0 ]
691+ } else {
692+ ctx .Repo .BranchName , _ = gitRepo .GetDefaultBranch ()
693+ if ctx .Repo .BranchName == "" {
694+ // If it still can't get a default branch, fall back to default branch from setting.
695+ // Something might be wrong. Either site admin should fix the repo sync or Gitea should fix a potential bug.
696+ ctx .Repo .BranchName = setting .Repository .DefaultBranch
697+ }
710698 }
711699 ctx .Repo .RefName = ctx .Repo .BranchName
712700 }
0 commit comments