Skip to content

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

Closed
@serhii-shnurenko

Description

@serhii-shnurenko

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions