Skip to content
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

Git.ls_remote fails when stderr isn't empty #516

Closed
serhii-shnurenko opened this issue Feb 25, 2021 · 2 comments
Closed

Git.ls_remote fails when stderr isn't empty #516

serhii-shnurenko opened this issue Feb 25, 2021 · 2 comments

Comments

@serhii-shnurenko
Copy link

Subject of the issue

When the output of ls-remote command is parsed both stout and stderr parsed, what causes the script to fail because of the unexpected git command output.

Your environment

  • git version 1.7.1, ruby-git 1.5.0
  • ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]

Expected behaviour

Git.ls_remote working even if something fails into stderr.
Output to stderr parsed separately from stdout.
IDK how complicated is it, but why not switch Open3::popen3 as command runner?

Steps to reproduce

You should have output in stderr for your git command. Then Git.ls_remote will fail.

Actual behaviour

When running Git.ls_remote and stderr isn't empty, the parsing of ls-remote command will fail because warning in the output causes:

NoMethodError: undefined method `split' for nil:NilClass
  /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/git-1.5.0/lib/git/lib.rb:419:in `block (2 levels) in ls_remote'
  /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/git-1.5.0/lib/git/lib.rb:417:in `each'
  /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/git-1.5.0/lib/git/lib.rb:417:in `block in ls_remote'
  /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/git-1.5.0/lib/git/lib.rb:416:in `tap'
  /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/git-1.5.0/lib/git/lib.rb:416:in `ls_remote'
  /opt/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/git-1.5.0/lib/git.rb:149:in `ls_remote'
....

The reason is that git commands on this host for some reason output warnings about hostkey everytime. And I still searching for the reasons, why ~/.ssh/known_hosts file in the home is ignored, but I believe that this kind of warnings shouldn't fail program execution.
When I running my script, I'm getting:

RSA host key for IP address '**********' not in list of known hosts.

Which then not splitted by the tabs because there are no tabs in this string

(sha, info) = line.split("\t")

I checked the output of the command manually with and without stderr redirection to the /dev/null. as we can see with suppressed stderr script will not fail.

[serhii@host ~] :) git ls-remote 'ssh://git@*********:*****/******.git'
RSA host key for IP address '**********' not in list of known hosts.
5992e82a52648a6348e42bad853ee32ae06d4c5a	HEAD
249d61415a4ea902e453ebb3868835b9e340fc71	refs/heads/**********
4d50c9c33c15e96333f0543a53ae5599b8e7c0a9	refs/heads/alpha/develop
5992e82a52648a6348e42bad853ee32ae06d4c5a	refs/heads/master
c7fdfcd41cab3c419d3b8f94977b395bef25fabf	refs/heads/************

[serhii@host ~] :) git ls-remote 'ssh://git@*********:*****/******.git' 2>/dev/null
5992e82a52648a6348e42bad853ee32ae06d4c5a	HEAD
249d61415a4ea902e453ebb3868835b9e340fc71	refs/heads/**********
4d50c9c33c15e96333f0543a53ae5599b8e7c0a9	refs/heads/alpha/develop
5992e82a52648a6348e42bad853ee32ae06d4c5a	refs/heads/master
c7fdfcd41cab3c419d3b8f94977b395bef25fabf	refs/heads/************

P.S.: Also wondering why ls_remote doesn't support listing tags, but that's another issue.

@stale
Copy link

stale bot commented Jan 9, 2022

A friendly reminder that this issue had no activity for 60 days.

@jcouball
Copy link
Member

Fixed with #684 and released in git-2.0.0-pre1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants