Skip to content

Prepare remote url for specific branch #4026

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
10 changes: 10 additions & 0 deletions pkg/commands/git_commands/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ func (self *RemoteCommands) CheckRemoteBranchExists(branchName string) bool {
return err == nil
}

// Returns remote name for branch
func (self *RemoteCommands) GetRemoteName(branchName string) (string, error) {
cmdArgs := NewGitCmd("config").
Arg(fmt.Sprintf("branch.%s.remote", branchName)).
ToArgv()

remote, err := self.cmd.New(cmdArgs).DontLog().RunWithOutput()
return strings.TrimSpace(remote), err
}

// 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) {
Expand Down
7 changes: 6 additions & 1 deletion pkg/gui/controllers/helpers/host_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ 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")
branch := self.c.IGetContexts.Contexts().Branches.GetSelected().Name
remoteName, err := self.c.Git().Remote.GetRemoteName(branch)
if err != nil {
return nil, err
}
remoteUrl, err := self.c.Git().Remote.GetRemoteURL(remoteName)
if err != nil {
return nil, err
}
Expand Down