mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-28 16:02:01 +03:00
Obtain remote URL by calling "ls-remote --get-url" instead of using git config
This has the advantage that it still works when the user has configured aliases using the insteadOf feature [1]. [1] https://git-scm.com/docs/git-config/2.42.0#Documentation/git-config.txt-urlltbasegtinsteadOf)
This commit is contained in:
@ -2,6 +2,7 @@ package git_commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
)
|
)
|
||||||
@ -74,3 +75,14 @@ func (self *RemoteCommands) CheckRemoteBranchExists(branchName string) bool {
|
|||||||
|
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resolve what might be a aliased URL into a full URL
|
||||||
|
// SEE: `man -P 'less +/--get-url +n' git-ls-remote`
|
||||||
|
func (self *RemoteCommands) GetRemoteURL(remoteName string) (string, error) {
|
||||||
|
cmdArgs := NewGitCmd("ls-remote").
|
||||||
|
Arg("--get-url", remoteName).
|
||||||
|
ToArgv()
|
||||||
|
|
||||||
|
url, err := self.cmd.New(cmdArgs).RunWithOutput()
|
||||||
|
return strings.TrimSpace(url), err
|
||||||
|
}
|
||||||
|
@ -24,18 +24,28 @@ func NewHostHelper(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *HostHelper) GetPullRequestURL(from string, to string) (string, error) {
|
func (self *HostHelper) GetPullRequestURL(from string, to string) (string, error) {
|
||||||
return self.getHostingServiceMgr().GetPullRequestURL(from, to)
|
mgr, err := self.getHostingServiceMgr()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return mgr.GetPullRequestURL(from, to)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *HostHelper) GetCommitURL(commitSha string) (string, error) {
|
func (self *HostHelper) GetCommitURL(commitSha string) (string, error) {
|
||||||
return self.getHostingServiceMgr().GetCommitURL(commitSha)
|
mgr, err := self.getHostingServiceMgr()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return mgr.GetCommitURL(commitSha)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getting this on every request rather than storing it in state in case our remoteURL changes
|
// getting this on every request rather than storing it in state in case our remoteURL changes
|
||||||
// from one invocation to the next. Note however that we're currently caching config
|
// from one invocation to the next.
|
||||||
// results so we might want to invalidate the cache here if it becomes a problem.
|
func (self *HostHelper) getHostingServiceMgr() (*hosting_service.HostingServiceMgr, error) {
|
||||||
func (self *HostHelper) getHostingServiceMgr() *hosting_service.HostingServiceMgr {
|
remoteUrl, err := self.c.Git().Remote.GetRemoteURL("origin")
|
||||||
remoteUrl := self.c.Git().Config.GetRemoteURL()
|
if err != nil {
|
||||||
configServices := self.c.UserConfig.Services
|
return nil, err
|
||||||
return hosting_service.NewHostingServiceMgr(self.c.Log, self.c.Tr, remoteUrl, configServices)
|
}
|
||||||
|
configServices := self.c.UserConfig.Services
|
||||||
|
return hosting_service.NewHostingServiceMgr(self.c.Log, self.c.Tr, remoteUrl, configServices), nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user