Closed Vlad-Herus closed 5 years ago
Hi thank you for writing in! This might be related or identical to https://github.com/github/hub/issues/1934.
hub version
?~/.ssh/config
(at least the part that pertains to github.com hosts)?Host github.com-devops HostName github.com User git IdentityFile ~/.ssh/github_devops
Host github.com-vlad HostName github.com User git IdentityFile ~/.ssh/github_vlad
Thank you for additional info. I cannot reproduce this. I've changed my git remote url to start with: git@github.com-devops:
and I've added to ~/.ssh/config
:
Host github.com-devops
HostName github.com
User git
IdentityFile ~/.ssh/github_devops
and after that hub pr list
correctly recognizes the host as GitHub.com and displays the list of pull requests.
We also have a test that SSH hostname aliases are properly expanded: https://github.com/github/hub/blob/4aba5854179b8e381bebd08ec9b2d49a3613eb15/features/browse.feature#L200-L209
Can you try poke more in your configuration, or build hub from source so you can add debugging statements? Note that setting HUB_VERBOSE=1
enables verbose mode, altough in this case I don't think it would provide relevant extra information.
Thanks for detailed reply, I switched my ssh configuration back and forth a couple of times - still able to consistently reproduce the issue. Can you : 1 make sure that your openssh config does not contain default github host, only aliased? 2 call git remote -v to make sure that only aliased git remote shows up?
I've looked through the source code of the hub and put in a couple of trace outputs to help diagnose the issue, you can find them in here. With those changes here's output of the hub :
It compares github.com-vlad to the list of known hosts in hosts.go::knownGitHubHostsInclude and obviously fails. I tried to look for the code that addresses test case you listed but couldn't find it.
I've made a pull request with my understanding of how to address this issue.
I'm somewhat new to git, github, ssh, go. So all comments suggestions are appreciated.
Thanks for looking into this!
I still can't reproduce. It's possible that something is wrong with the SSHConfig parser. If you apply the following patch, hub will print the parsed hostname aliases from ~/.ssh/config
when it processes the git remote URL configuration
diff --git a/git/url.go b/git/url.go
index f3f4adf..f19aa90 100644
--- a/git/url.go
+++ b/git/url.go
@@ -1,6 +1,7 @@
package git
import (
+ "fmt"
"net/url"
"regexp"
"strings"
@@ -44,6 +45,7 @@ func (p *URLParser) Parse(rawURL string) (u *url.URL, err error) {
u.Host = u.Host[0:idx]
}
+ fmt.Printf("%#v\n", p.SSHConfig)
sshHost := p.SSHConfig[u.Host]
// ignore replacing host that fixes for limited network
// https://help.github.com/articles/using-ssh-over-the-https-port
it should show something like
$ hub pr list -L1 [43/1473]
git.SSHConfig{"github.com-devops":"github.com"}
#2272 fixes #2270 resolving host name with openssh alias
This demonstrates how, on my system, the github.com-devops
host is correctly translated into github.com
and the API of that host is then queried.
I see, I was looking in github folder only.
with your change here's output of the pr list :
I've added more traces here. It seems it tries to read .ssh\config(located in user home dir) when current directory is my repo folder.
here's output with my traces :
And here's output after I copies .ssh folder into my git repo folder :
Not sure what is the right way to fix this.
whoops, just noticed that I attached same image twice. the middle one was supposed to show that it tries to find .ssh\config and is unable to and git.SSHConfig is empty (as the first image shows)
When you were reproducing the issue were you on windows or linux?
@VladimirUAZ Ah thanks to your debugging I see now that .ssh/config
was looked up in the wrong location. Can you try https://github.com/github/hub/pull/2274 please?
I'm using openssh on windows to authenticate my git calls for two different github accounts. I've setup my openssh config according to https://gist.github.com/jexchan/2351996 . As a result my repository origin is git@github.com-sshUser:gitUser/repository.git instead of usual git@github.com:gitUser/repository.git.
With this change hub refuses to recognize my repository with following message : Aborted: could not find any git remote pointing to a GitHub repository.
When I switch my ssh config to have only one github user and switch my repository origin not to include sshUser - hub works fine.