GitPython icon indicating copy to clipboard operation
GitPython copied to clipboard

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

Open steffenschumacher opened this issue 7 years ago • 5 comments

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
     _ _           _                           _     _  ___  _ 
  __| | | _____ __| | ___ _ __ __ _ _ __   ___(_) __| |/ _ \/ |
 / _` | |/ / __/ _` |/ __| '__/ _` | '_ \ / __| |/ _` | | | | |
| (_| |   < (_| (_| | (__| | | (_| | | | | (__| | (_| | |_| | |
 \__,_|_|\_\___\__,_|\___|_|  \__,_|_| |_|\___|_|\__,_|\___/|_|
                                                               
[email protected]'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?

steffenschumacher avatar Jul 13 '18 15:07 steffenschumacher

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.

Byron avatar Jul 15 '18 13:07 Byron

I’ll give it a crack..

Steffen Schumacher +45 30662747

Den 15. jul. 2018 kl. 15.31 skrev Sebastian Thiel [email protected]:

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.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

steffenschumacher avatar Jul 15 '18 20:07 steffenschumacher

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

ohheyrj avatar Jan 28 '19 21:01 ohheyrj

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.

ohheyrj avatar Jan 29 '19 17:01 ohheyrj

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 avatar Jul 06 '19 03:07 Byron