Skip to content

Add user config git.preferRemotes to OpenInBrowser on specified remotes #4113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 6 additions & 1 deletion pkg/commands/git_commands/remote.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package git_commands

import (
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -85,5 +86,9 @@ func (self *RemoteCommands) GetRemoteURL(remoteName string) (string, error) {
ToArgv()

url, err := self.cmd.New(cmdArgs).RunWithOutput()
return strings.TrimSpace(url), err
url = strings.TrimSpace(url)
if url == remoteName {
return "", errors.New("Remote not found")
}
return url, err
}
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