Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » Setting Transfer Protocol Via Code
Setting Transfer Protocol Via Code [message #1852054] Wed, 27 April 2022 20:04 Go to next message
Ryan Baxter is currently offline Ryan BaxterFriend
Messages: 2
Registered: April 2022
Junior Member
I know I can tell JGit to use a specific transfer protocol by setting it in the global git config, but if there a JGit API I can use in order to specify the transfer protocol explicitly in code?
Re: Setting Transfer Protocol Via Code [message #1852058 is a reply to message #1852054] Thu, 28 April 2022 05:47 Go to previous messageGo to next message
Thomas Wolf is currently offline Thomas WolfFriend
Messages: 494
Registered: August 2016
Senior Member
If you mean the git protocol (config protocol.version): I don't think there is any API for it on the client side.

Server-side you can set a TransferConfig via UploadPack.setTransferConfig(), or just make sure you don't call UploadPack.setExtraParameters(), or if you do, exclude the protocol V2 request from the parameters.

Why would a client-side API be needed? V2 is the default is not set, and it falls back to V0/V1 if the server doesn't reply with a V2 answer. And if the user configured V0/V1 explicitly, would it really be a good idea to force using V2?
Re: Setting Transfer Protocol Via Code [message #1852081 is a reply to message #1852058] Thu, 28 April 2022 13:17 Go to previous messageGo to next message
Ryan Baxter is currently offline Ryan BaxterFriend
Messages: 2
Registered: April 2022
Junior Member
Yes I am talking about the protocol used by the client.

We (Spring Cloud) are seeing reports of people having issues with JGit and Bitbucket when using V2 by default. The fallback does not appear to work
https://github.com/spring-cloud/spring-cloud-config/issues/2015
Re: Setting Transfer Protocol Via Code [message #1852085 is a reply to message #1852081] Thu, 28 April 2022 14:30 Go to previous messageGo to next message
Thomas Wolf is currently offline Thomas WolfFriend
Messages: 494
Registered: August 2016
Senior Member
Thanks for providing context. If there's a problem with the fallback, I'd rather have that fall-back fixed.

The root exception reported at https://github.com/spring-cloud/spring-cloud-config/issues/2015 is an SSH exception. So the problem is not related to the fallback code from V2 to V0/V1.

I bet bitbucket has configured their SSH daemon to fail the connection if the GIT_PROTOCOL environment variable is set. So it already fails the connection when JGit attempts to send that environment variable when opening the SSH channel.

Things to do:

  1. Get bitbucket to allow the GIT_PROTOCOL environment variable to be sent in SSH connections. It's fine it they ignore it afterwards and just do protocol V0/V1.
  2. Since that is unlikely to happen: already have a fallback on opening the SSH connection; if it gets an SSH exception, re-try with protocol V0/V1 (which means, without this environment variable).
  3. Provide an API to set the protocol version. Maybe low-level, on the Transport (to be set via a TransportConfigCallback), like Transport.setConfig(TransferConfig config)? Or more specific like Transport.setProtocolVersion(TransferConfig.ProtocolVersion version)?

With (2) alone that problem would vanish, and nothing would need to be done in Spring Cloud. (Except updating the JGit version). (3) would give users a way to force protocol V0/V1 if they know the server will even refuse a V2 request, which might avoid the (futile) attempt in (2) and thus be a tad faster. But it would require that Spring Cloud not only update the JGit version but also implements such a TransferConfigCallback.

Unfortunately the standard git config has no mechanism to choose the git protocol version by URI. (Like protocol.<uri>.version, similar to the HTTP settings...)
Re: Setting Transfer Protocol Via Code [message #1852102 is a reply to message #1852085] Fri, 29 April 2022 07:58 Go to previous message
Thomas Wolf is currently offline Thomas WolfFriend
Messages: 494
Registered: August 2016
Senior Member
Actually, forget the above.

I see that Spring Cloud is using JSch. This is a JSch bug, see bug 576922.

The JSch integration in JGit is legacy code and is basically unsupported. I recommend that Spring Cloud switches to the newer supported SSH transport based on Apache MINA sshd.

If Spring Cloud wants to stay on JSch, try using the JSch fork as pointed out in bug 576922. (The JSch fork should have this JSch bug fixed; see Github issue 93.) But the JGit team cannot give any support for this combination of libraries.

[Updated on: Fri, 29 April 2022 10:07]

Report message to a moderator

Previous Topic:How can send custom error message after git push from local git server by using jgit api
Next Topic:Update AmazonS3 to authenticate with AWS Signature Version 4
Goto Forum:
  


Current Time: Sun Sep 25 14:42:21 GMT 2022

Powered by FUDForum. Page generated in 0.01963 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top