libgit2 / git2go

Git to Go; bindings for libgit2. Like McDonald's but tastier.
MIT License
1.93k stars 316 forks source link

Make ssh commands used in the git smart transport compatible with libgit2 #852

Closed darkowlzz closed 2 years ago

darkowlzz commented 2 years ago

Before this change, the commands sent to the git server were of the form:

git-upload-pack "/bar/test-reponame"

This resulted in the git server (gitkit) returning error: error parsing command: invalid git command

This change replaces the double quotes with single quotes:

git-upload-pack '/bar/test-reponame'

Using git smart transport via managed ssh transport against gitkit, fails with the following errors:

2021/11/07 21:57:24 ssh: incoming exec request: git-upload-pack "/bar/test-reponame"
2021/11/07 21:57:24 ssh: payload 'git-upload-pack "/bar/test-reponame"'
2021/11/07 21:57:24 ssh: error parsing command: invalid git command

Resulting in a clone failure: unable to clone: EOF.

Using ssh transport based on the libgit2 libraries work with gitkit. Upon further investigation, I found that gitkit has a regular expression for parsing the commands and it fails to parse commands with " (double quote). Replacing the double quotes with single quote fixes the issue. It felt like a bug in gitkit itself. So I wasn't sure if we should fix it in git2go. But after going through the libgit2 code, I found that the libgit2 implementation also uses single quotes, refer: https://github.com/libgit2/libgit2/blob/358a60e1b46000ea99ef10b4dd709e92f75ff74b/src/transports/ssh.c#L96-L99.

I guess it'd be better if we are consistent with libgit2 to maintain compatibility.