mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 07:36:27 -04:00
Merge 003af24167 into 8924bca76f
This commit is contained in:
commit
d05d17f2c8
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/context/traits"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
|
|
@ -239,7 +240,7 @@ func (self *BasicCommitsController) copyCommitHashToClipboard(commit *models.Com
|
|||
}
|
||||
|
||||
func (self *BasicCommitsController) copyCommitURLToClipboard(commit *models.Commit) error {
|
||||
url, err := self.c.Helpers().Host.GetCommitURL(commit.Hash())
|
||||
url, err := self.getCommitURL(commit)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -338,7 +339,7 @@ func (self *BasicCommitsController) copyCommitTagsToClipboard(commit *models.Com
|
|||
}
|
||||
|
||||
func (self *BasicCommitsController) openInBrowser(commit *models.Commit) error {
|
||||
url, err := self.c.Helpers().Host.GetCommitURL(commit.Hash())
|
||||
url, err := self.getCommitURL(commit)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -429,3 +430,21 @@ func (self *BasicCommitsController) selectCommitsOfCurrentBranch() error {
|
|||
self.context.HandleFocus(types.OnFocusOpts{})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *BasicCommitsController) getCommitURL(commit *models.Commit) (string, error) {
|
||||
remoteName := self.remoteNameFromContext()
|
||||
return self.c.Helpers().Host.GetCommitURLForRemote(commit.Hash(), remoteName)
|
||||
}
|
||||
|
||||
// When viewing commits under a specific remote branch, return that remote's
|
||||
// name so we build the URL from the right remote. Falls back to "origin".
|
||||
func (self *BasicCommitsController) remoteNameFromContext() string {
|
||||
if subCommitsCtx, ok := self.context.(*context.SubCommitsContext); ok {
|
||||
if ref := subCommitsCtx.GetRef(); ref != nil {
|
||||
if remoteBranch, ok := ref.(*models.RemoteBranch); ok {
|
||||
return remoteBranch.RemoteName
|
||||
}
|
||||
}
|
||||
}
|
||||
return "origin"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,11 @@ func (self *HostHelper) GetPullRequestURL(from string, to string) (string, error
|
|||
}
|
||||
|
||||
func (self *HostHelper) GetCommitURL(commitHash string) (string, error) {
|
||||
mgr, err := self.getHostingServiceMgr()
|
||||
return self.GetCommitURLForRemote(commitHash, "origin")
|
||||
}
|
||||
|
||||
func (self *HostHelper) GetCommitURLForRemote(commitHash string, remoteName string) (string, error) {
|
||||
mgr, err := self.getHostingServiceMgrForRemote(remoteName)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
@ -37,7 +41,11 @@ 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")
|
||||
return self.getHostingServiceMgrForRemote("origin")
|
||||
}
|
||||
|
||||
func (self *HostHelper) getHostingServiceMgrForRemote(remoteName string) (*hosting_service.HostingServiceMgr, error) {
|
||||
remoteUrl, err := self.c.Git().Remote.GetRemoteURL(remoteName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue