Hello,
if I try to use hub browse
when my repo's remote is in https
form - it works fine. However, if the repo's remote is in ssh
, hub browse
fails.
Even more specifically, it fails, if a browser session is already in use / opened (at least for google chrome)
$ hub remote set-url origin https://github.com/sarpik/angular-learning.git
$ hub browse
[6330:6359:0430/195454.358191:ERROR:browser_process_sub_thread.cc(217)] Waited 3 ms for network service
Opening in existing browser session
Opens the repository.
$ hub remote set-url origin [email protected]:sarpik/angular-learning.git
$ hub browse
if a browser is already open, it throws this and opens a new empty window without the repository.
[13005:13034:0430/200211.701130:ERROR:browser_process_sub_thread.cc(217)] Waited 3 ms for network service
Opening in existing browser session.
otherwise, if the browser is not open, it does not display this error and opens the browser with the repository successfully.
My system:
$ uname -a
Linux arch-usb 5.0.9-arch1-1-ARCH #1 SMP PREEMPT Sat Apr 20 15:00:46 UTC 2019 x86_64 GNU/Linux
Google chrome:
$ pacman -Qe google-chrome
google-chrome 74.0.3729.108-1
Hi thank you for reporting! This is strange. There should be no difference when opening a repository that has an SSH remote compared to an HTTPS remote. The project url to open in the browser is identical:
$ git init
Initialized empty Git repository in /private/tmp/hub-test/.git/
$ hub remote add origin [email protected]:sarpik/angular-learning.git
$ hub browse -u
https://github.com/sarpik/angular-learning
$ hub remote set-url origin https://github.com/sarpik/angular-learning.git
$ hub browse -u
https://github.com/sarpik/angular-learning
I assume your system has either xdg-open
or x-www-browser
in PATH; hub will execute the first one found to open the resolved url. It doesn't itself communicate with a web browser on your system nor can it know whether the browser is already opened or not.
Are you on the latest version of hub, btw?
Try experimenting with skipping hub altogether and running something like this repeatedly in different scenarios:
$ xdg-open https://github.com/sarpik/angular-learning
Hello, no problem.
My hub
version is up to date - I sync my arch packages automatically every 6 hours:D
$ hub --version
git version 2.21.0
hub version 2.11.2
The hub browse -u
output after setting an ssh
remote url is different from your output.
$ git init
Initialized empty Git repository in /home/kipras/temp/hub-ssh-bug-testing/.git/
$ hub remote add origin [email protected]:sarpik/angular-learning.git
$ hub browse -u
ssh://github.com/sarpik/angular-learning # <--- this is weird
$ hub remote set-url origin https://github.com/sarpik/angular-learning.git
$ hub browse -u
https://github.com/sarpik/angular-learning
I'm not sure if the ssh
url is even valid. Shouldn't there be a :
before the username + git@
before github.com
?
Note that I've set the protocol
to ssh
in my $HOME/.config/hub
file:
github.com:
- user: sarpik
oauth_token: <oauth_token_hidden>
protocol: ssh
I've done this because instead of entering my password + 2 FA token every time, I instead just use my ssh passphrase.
Regarding the $PATH variable - no, I don't think that I have neither xdg-open
nor x-www-browser
$ echo $PATH | grep -i xdg # no output
$ echo $PATH | grep -i xdg-open # no output
$ echo $PATH | grep -i x-www-browser # no output
Running xdg-open https://github.com/sarpik/angular-learning
works as expected - both when a browser session is open and closed.
Anything else I could help with?
Edit:
If I set the url back to https
, it works perfectly. Setting it back to ssh
url brings back the buggies.
So if you're testing, don't forget to set it back to ssh :D
_Note_ that I've set the
protocol
tossh
in my$HOME/.config/hub
file:
There's your bug: the protocol
option here doesn't support "ssh". It defines the protocol to communicate with the GitHub API with, which can only be HTTPS and sometimes HTTP if communicating with a GitHub Enterprise instance.
I've done this because instead of entering my password + 2 FA token every time, I instead just use my ssh passphrase.
You literally only ever have to do this once after installing hub, then your credentials get converted to oauth_token
in $HOME/.config/hub
and then you never have to enter credentials again.
Hey, thanks @mislav!
I figured out that I need to set the ssh
protocol inside my $HOME/.gitconfig
like so:
[hub]
protocol = ssh
and keep the https
protocol inside $HOME/.config/hub
:
github.com:
- user: sarpik
oauth_token: <the_oauth_token>
protocol: https
Thanks again:)
You literally only ever have to do this once after installing hub, then your credentials get converted to
oauth_token
in$HOME/.config/hub
and then you never have to enter credentials again.
@mislav Hello again, I've discovered that hub
somehow ignores the ~/.config/hub
file's oauth_token
parameter and does not work with https
(this happens when 2FA is enabled).
~/.confih/hub
file is NOT present, hub
asks for the username
, password
, two-factor authentication code
.~/.config/hub
file.If the file IS present, just skip step 1
and 2
.
g
is aliased ashub
in the photo below; I try to clone fromsarpik/stylus
~/.config/hub
:
github.com:
- user: sarpik
oauth_token: <oauth_token>
protocol: https
~/.gitconfig
:
<...>
[hub]
protocol = https
$ uname -a
Linux arch-usb 5.1.2-arch1-1-ARCH #1 SMP PREEMPT Wed May 15 00:09:47 UTC 2019 x86_64 GNU/Linux
I also tried to create the access token myself, as mentioned in this tutorial from github, and placing it inside the ~/.config/hub
file - hub
doesn't seem to read it though.
If I input the token manually when prompted for the username & password - everything works just fine.
@sarpik It's weird that ~/.config/hub
file wasn't read.
If I input the token manually when prompted for the username & password - everything works just fine.
Did you find out if that information was saved somewhere after you got prompted?
Do you have environment variables XDG_CONFIG_HOME
or HUB_CONFIG
present?
Do you have environment variable GITHUB_TOKEN
present?
@sarpik Ah I see what is happening now. I've commented too soon.
After you got asked for two-factor authentication code, your GitHub API authentication info that hub uses got succcessfully stored into $HOME/.config/hub
. Then it started cloning the repo via git.
You got prompted for username/password again by git's own HTTPS transport mechanism. That authentication is within git and completely separate from hub. You have to set up git credential caching separately and paste your Personal Access Token instead of password (unlike with hub, your actual GitHub password will not work here).
Sorry that this is all so confusing. In the future I would want to imagine hub helping you out with both its own authentication mechanism and that for git cloning.
@mislav Sorry for the late reply.
Yeah, that's confusing a little.
I noticed that on my Windows PC, I entered my credentials into git
(without hub
) once and they stay there forever - I never need to re-enter them.
git-bash
must be using some sort of credential store I suppose.
On my arch linux laptop, I now am still continuing to use ssh
, and I've started to use a credential store (there were many choices, I went with Keychain) - now I only need to input my ssh passphrase once per session login, so that helps.
Hopefully this process will be automated in the future - best of luck once again, and if I find something else useful, I'll be sure to notify ya'll.
Most helpful comment
There's your bug: the
protocol
option here doesn't support "ssh". It defines the protocol to communicate with the GitHub API with, which can only be HTTPS and sometimes HTTP if communicating with a GitHub Enterprise instance.You literally only ever have to do this once after installing hub, then your credentials get converted to
oauth_token
in$HOME/.config/hub
and then you never have to enter credentials again.