Skip to content

Commit

Permalink
Add user config git.preferRemotes to OpenInBrowser on specified r…
Browse files Browse the repository at this point in the history
…emotes
  • Loading branch information
phanen committed Dec 22, 2024
1 parent 13e9e1d commit d4b1107
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
4 changes: 4 additions & 0 deletions docs/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ git:
- master
- main

# Prefer to specified remote repositories, E.g. when `OpenInBrowser`
preferRemotes:
- origin

# 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'
skipHookPrefix: WIP

Expand Down
3 changes: 3 additions & 0 deletions pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ type GitConfig struct {
Merging MergingConfig `yaml:"merging"`
// list of branches that are considered 'main' branches, used when displaying commits
MainBranches []string `yaml:"mainBranches" jsonschema:"uniqueItems=true"`
// Prefer to specified remote repositories, E.g. when `OpenInBrowser`
PreferRemotes []string `yaml:"preferRemotes" jsonschema:"uniqueItems=true"`
// 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'
SkipHookPrefix string `yaml:"skipHookPrefix"`
// If true, periodically fetch from remote
Expand Down Expand Up @@ -765,6 +767,7 @@ func GetDefaultConfig() *UserConfig {
ShowGraph: "always",
ShowWholeGraph: false,
},
PreferRemotes: []string{"origin"},
SkipHookPrefix: "WIP",
MainBranches: []string{"master", "main"},
AutoFetch: true,
Expand Down
15 changes: 10 additions & 5 deletions pkg/gui/controllers/helpers/host_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ func (self *HostHelper) GetCommitURL(commitHash string) (string, error) {
// getting this on every request rather than storing it in state in case our remoteURL changes
// from one invocation to the next.
func (self *HostHelper) getHostingServiceMgr() (*hosting_service.HostingServiceMgr, error) {
remoteUrl, err := self.c.Git().Remote.GetRemoteURL("origin")
if err != nil {
return nil, err
remotes := self.c.UserConfig().Git.PreferRemotes
var err error
var remoteUrl string
for _, remote := range remotes {
remoteUrl, err = self.c.Git().Remote.GetRemoteURL(remote)
if err == nil {
configServices := self.c.UserConfig().Services
return hosting_service.NewHostingServiceMgr(self.c.Log, self.c.Tr, remoteUrl, configServices), nil
}
}
configServices := self.c.UserConfig().Services
return hosting_service.NewHostingServiceMgr(self.c.Log, self.c.Tr, remoteUrl, configServices), nil
return nil, err
}
11 changes: 11 additions & 0 deletions schema/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,17 @@
"main"
]
},
"preferRemotes": {
"items": {
"type": "string"
},
"type": "array",
"uniqueItems": true,
"description": "Prefer to specified remote repositories, E.g. when `OpenInBrowser`",
"default": [
"origin"
]
},
"skipHookPrefix": {
"type": "string",
"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'",
Expand Down

0 comments on commit d4b1107

Please sign in to comment.