From 6e728cf81224d2cd22768a3674abc2f4b9046553 Mon Sep 17 00:00:00 2001 From: Norwin Date: Tue, 14 Sep 2021 14:59:11 +0800 Subject: [PATCH] Accept more main branch names for login detection (#396) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also consider `main` and `trunk` as options to determine a login through its configured remote fixes #381 Co-authored-by: Norwin Reviewed-on: https://gitea.com/gitea/tea/pulls/396 Reviewed-by: Lunny Xiao Reviewed-by: Alexey 〒erentyev Co-authored-by: Norwin Co-committed-by: Norwin --- modules/context/context.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/context/context.go b/modules/context/context.go index efedd40..3c45911 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -166,10 +166,14 @@ func contextFromLocalRepo(repoPath, remoteValue string) (*git.TeaRepo, *config.L } if len(gitConfig.Remotes) > 1 { // if master branch is present, use it as the default remote - masterBranch, ok := gitConfig.Branches["master"] - if ok { - if len(masterBranch.Remote) > 0 { - remoteValue = masterBranch.Remote + mainBranches := []string{"main", "master", "trunk"} + for _, b := range mainBranches { + masterBranch, ok := gitConfig.Branches[b] + if ok { + if len(masterBranch.Remote) > 0 { + remoteValue = masterBranch.Remote + } + break } } }