Skip to content

Commit 38601af

Browse files
committed
Add user config git.preferRemotes to OpenInBrowser on specified remotes
1 parent 4a7cf60 commit 38601af

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

Diff for: docs/Config.md

+4
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,10 @@ git:
305305
- master
306306
- main
307307

308+
# Prefer to specified remote repositories, E.g. when `OpenInBrowser`
309+
preferRemotes:
310+
- origin
311+
308312
# Prefix to use when skipping hooks. E.g. if set to 'WIP', then pre-commit hooks will be skipped when the commit message starts with 'WIP'
309313
skipHookPrefix: WIP
310314

Diff for: pkg/config/user_config.go

+3
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ type GitConfig struct {
224224
Merging MergingConfig `yaml:"merging"`
225225
// list of branches that are considered 'main' branches, used when displaying commits
226226
MainBranches []string `yaml:"mainBranches" jsonschema:"uniqueItems=true"`
227+
// Prefer to specified remote repositories, E.g. when `OpenInBrowser`
228+
PreferRemotes []string `yaml:"preferRemotes" jsonschema:"uniqueItems=true"`
227229
// Prefix to use when skipping hooks. E.g. if set to 'WIP', then pre-commit hooks will be skipped when the commit message starts with 'WIP'
228230
SkipHookPrefix string `yaml:"skipHookPrefix"`
229231
// If true, periodically fetch from remote
@@ -765,6 +767,7 @@ func GetDefaultConfig() *UserConfig {
765767
ShowGraph: "always",
766768
ShowWholeGraph: false,
767769
},
770+
PreferRemotes: []string{"origin"},
768771
SkipHookPrefix: "WIP",
769772
MainBranches: []string{"master", "main"},
770773
AutoFetch: true,

Diff for: pkg/gui/controllers/helpers/host_helper.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,15 @@ func (self *HostHelper) GetCommitURL(commitHash string) (string, error) {
4242
// getting this on every request rather than storing it in state in case our remoteURL changes
4343
// from one invocation to the next.
4444
func (self *HostHelper) getHostingServiceMgr() (*hosting_service.HostingServiceMgr, error) {
45-
remoteUrl, err := self.c.Git().Remote.GetRemoteURL("origin")
46-
if err != nil {
47-
return nil, err
45+
remotes := self.c.UserConfig().Git.PreferRemotes
46+
var err error
47+
var remoteUrl string
48+
for _, remote := range remotes {
49+
remoteUrl, err = self.c.Git().Remote.GetRemoteURL(remote)
50+
if err == nil {
51+
configServices := self.c.UserConfig().Services
52+
return hosting_service.NewHostingServiceMgr(self.c.Log, self.c.Tr, remoteUrl, configServices), nil
53+
}
4854
}
49-
configServices := self.c.UserConfig().Services
50-
return hosting_service.NewHostingServiceMgr(self.c.Log, self.c.Tr, remoteUrl, configServices), nil
55+
return nil, err
5156
}

Diff for: schema/config.json

+11
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,17 @@
573573
"main"
574574
]
575575
},
576+
"preferRemotes": {
577+
"items": {
578+
"type": "string"
579+
},
580+
"type": "array",
581+
"uniqueItems": true,
582+
"description": "Prefer to specified remote repositories, E.g. when `OpenInBrowser`",
583+
"default": [
584+
"origin"
585+
]
586+
},
576587
"skipHookPrefix": {
577588
"type": "string",
578589
"description": "Prefix to use when skipping hooks. E.g. if set to 'WIP', then pre-commit hooks will be skipped when the commit message starts with 'WIP'",

0 commit comments

Comments
 (0)