Gitea: support Git wire protocol

Created on 21 May 2018  Â·  13Comments  Â·  Source: go-gitea/gitea

Most helpful comment

Hi once again. There's a branch for support git protocol v2 for gitlab:
https://gitlab.com/gitlab-org/gitaly/merge_requests/844/diffs
So basic idea for http support as it seems is:

  1. Receive header from client
  2. Put it into a variable
  3. Pass it to git
  4. ?

I'm not a GO developer but out of curiosity I've checked gitea sources and it seems to me that such behaviour could be implemented in routers/repo/http.go
Anyway gitlab is very helpful. Thanks to them.

All 13 comments

Could you please add a link in English, because I am not able to read Chinese?

Useful information about testing v2 protocol:
https://docs.gitlab.com/ee/administration/git_protocol.html
For ssh you should allow env variable in sshd conf as mentioned above. It works, tried with docker container.
Https downgrades to v1 protocol on server side. Something with the headers i suppose

Hi once again. There's a branch for support git protocol v2 for gitlab:
https://gitlab.com/gitlab-org/gitaly/merge_requests/844/diffs
So basic idea for http support as it seems is:

  1. Receive header from client
  2. Put it into a variable
  3. Pass it to git
  4. ?

I'm not a GO developer but out of curiosity I've checked gitea sources and it seems to me that such behaviour could be implemented in routers/repo/http.go
Anyway gitlab is very helpful. Thanks to them.

So, does current version support git v2 protocal?

Could we list the lack of Git Wire Protocol, Version 2 support in the comparison page (https://docs.gitea.io/en-us/comparison/)?

@NLZ please send a PR

We already support git wire protocol version 2. Closing this as complete.

Another reason to choose gitea rather than gogs https://github.com/gogs/gogs/issues/5269

Sorry to raise this issue back from the dead, but cloning Gitea repositories using Git Wire Protocol Version 2 (via HTTP) still doesn't appear to work. I think this is because Gitea isn't passing the Git-Protocol header to git via the GIT_PROTOCOL environment variable like it needs to.

I think we'd need to add something like this:

    if protocol := h.r.Header.Get("Git-Protocol"); protocol != "" {
        h.environ = append(h.environ, "GIT_PROTOCOL="+protocol)
    }

to http.go probably somewhere around here.

(Source code based on the implementation in sourcegraph here)

@wmhilton That looks like it would work. Fancy making a quick PR for this? I'd recommend just double checking that nothing horrible could happen by allowing the user to arbitrarily set the value of environment variables - it might just be easier to do some verification at the cost of having to update the code at a later point.

@zeripath Yes, I'll try making a build with that change and see if it works for me. And yes, the arbitraryness of the env var worries me too a bit... the git docs say it can consist of multiple key=value pairs separated by : but the only defined pair is version=2 so I'm tempted to only match against that... maybe I'll match against /version=\d/ or /[a-z0-9=:]+/i. I wonder how much mischief you can get into with just colons and equals signs in bash.

It's not _quite_ as trivial as I thought, because it requires modification of the getInfoRefs function too. But I think I'll get there.

Also, the really interesting feature of Protocol Version 2 (partial clone) requires that the repos have git config uploadpack.allowfilter 1 set on the Gitea side. And short of running it directly in ~/gitea-repositories/foo/bar I'm not sure how one could enable that. It might be nice to have a graphical checkbox in the repo settings page to enable partial clone. (Or maybe partial clone is not mainstream enough to worry about yet.)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

haytona picture haytona  Â·  3Comments

lunny picture lunny  Â·  3Comments

adpande picture adpande  Â·  3Comments

lunny picture lunny  Â·  3Comments

flozz picture flozz  Â·  3Comments