Skip to content

Remote operations fail with 'Failed to parse line' when ssh Banner exists? #781

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
steffenschumacher opened this issue Jul 13, 2018 · 5 comments

Comments

@steffenschumacher
Copy link

Hi,

I'm hitting the below line in git/remote.py:

Seemingly because my git(-lab) server has an SSH banner like this:

$ ssh login
     _ _           _                           _     _  ___  _ 
  __| | | _____ __| | ___ _ __ __ _ _ __   ___(_) __| |/ _ \/ |
 / _` | |/ / __/ _` |/ __| '__/ _` | '_ \ / __| |/ _` | | | | |
| (_| |   < (_| (_| | (__| | | (_| | | | | (__| | (_| | |_| | |
 \__,_|_|\_\___\__,_|\___|_|  \__,_|_| |_|\___|_|\__,_|\___/|_|
                                                               
user@dkcdcrancid01.corp.com's password: 

From what I can tell, then the issue is (also in remote.py) in class Remote._get_fetch_info_from_stderr():

        for line in progress.other_lines:
            line = force_text(line)
            for cmd in cmds:
                if len(line) > 1 and line[0] == ' ' and line[1] == cmd:
                    fetch_info_lines.append(line)
                    continue

where cmd contains ' ' (single whitespace), which will match the very first line, which is clearly not git output.
I know the easy fix is to remove the SSH banner, but it should be relatively easy to improve the matching on valid cmd lines I'd expect?
In my own env, I did a quick fix like so:

        for line in progress.other_lines:
            line = force_text(line)
            if re.match(r'^[a-z^A-Z]+$', line):  # added
                continue                         # added
            for cmd in cmds:
                if len(line) > 1 and line[0] == ' ' and line[1] == cmd:
                    fetch_info_lines.append(line)
                    continue

Probably there are better ways of fixing this?

@Byron
Copy link
Member

Byron commented Jul 15, 2018

Thanks for letting us know!
Maybe there are better ways to solve it, but I would already be happy for a PR along the lines of what you are showing here.

@steffenschumacher
Copy link
Author

steffenschumacher commented Jul 15, 2018 via email

@ohheyrj
Copy link

ohheyrj commented Jan 28, 2019

Is there any update on this? The changes above didn't fix my problem

@ohheyrj
Copy link

ohheyrj commented Jan 29, 2019

There is probably a better way of doing this however this is how I managed to get it to work:

        for line in progress.other_lines:
            line = force_text(line)
            if re.match(r'^[^\nA-Za-z]+', line):
                continue
            for cmd in cmds:
                if len(line) > 1 and line[0] == ' ' and line[1] == cmd:
                    fetch_info_lines.append(line)
                    print(line)
                    print("continue")
                    continue

Happy to put this in as a PR if people are happy with it.

@Byron Byron added this to the v2.1.12 - Bugfixes milestone Jul 6, 2019
@Byron
Copy link
Member

Byron commented Jul 6, 2019

I have tried the suggested regex, but it looks like it breaks a test:

======================================================================
FAIL: test_base (git.test.test_remote.TestRemote)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/sthiel/dev/GitPython/git/test/lib/helper.py", line 298, in remote_repo_creator
    return func(self, rw_repo, rw_daemon_repo)
  File "/Users/sthiel/dev/GitPython/git/test/test_remote.py", line 465, in test_base
    self._do_test_fetch(remote, rw_repo, remote_repo)
  File "/Users/sthiel/dev/GitPython/git/test/test_remote.py", line 189, in _do_test_fetch
    res = fetch_and_test(remote)
  File "/Users/sthiel/dev/GitPython/git/test/test_remote.py", line 179, in fetch_and_test
    self._do_test_fetch_result(res, remote)
  File "/Users/sthiel/dev/GitPython/git/test/test_remote.py", line 117, in _do_test_fetch_result
    self.assertGreater(len(results), 0)
AssertionError: 0 not greater than 0
-

Probably the regular expression is too greedy after all :(.

@Byron Byron removed this from the v2.1.12 - Bugfixes milestone Jul 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants