From fb3e1f75e98405ac6caebf529084fa685f78d79b Mon Sep 17 00:00:00 2001 From: arkamar Date: Wed, 9 Mar 2022 09:35:51 +0800 Subject: [PATCH] Prefer origin if there are multiple remotes (#458) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Usually, `origin` is the name of a default remote, which corresponds with upstream. This change improves remote selection when non of `main`, `master` nor `trunk` local branches is present. Co-authored-by: Petr Vaněk Co-authored-by: Lunny Xiao Reviewed-on: https://gitea.com/gitea/tea/pulls/458 Reviewed-by: 6543 <6543@obermui.de> Reviewed-by: Lunny Xiao Co-authored-by: arkamar Co-committed-by: arkamar --- modules/context/context.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/context/context.go b/modules/context/context.go index e07ff9c..bfdaf64 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -164,6 +164,11 @@ func contextFromLocalRepo(repoPath, remoteValue string) (*git.TeaRepo, *config.L remoteValue = remote } if len(gitConfig.Remotes) > 1 { + // prefer origin if there is multiple remotes + _, ok := gitConfig.Remotes["origin"] + if ok { + remoteValue = "origin" + } // if master branch is present, use it as the default remote mainBranches := []string{"main", "master", "trunk"} for _, b := range mainBranches {