-
Notifications
You must be signed in to change notification settings - Fork 743
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
Need an example of creating a git server using go-git #234
Comments
Hello, If someone have any example, even of a simple http upload/receive-pack server, it would be much appreciated. Thanks! |
I would also like to see an example of http server implementation. |
For future reference, an demo server for just git-upload-pack with go-git/v5: https://github.com/seankhliao/gitreposerver |
@seankhliao this has been super useful. Any tips on the order of operations for Happy to PR what I have to your repo |
I have been able to get func receivePack(
context context.Context,
session transport.Session,
body io.ReadCloser,
writer http.ResponseWriter,
) (err error) {
receivePackRequest := packp.NewReferenceUpdateRequest()
receivePackRequest.Decode(body)
receivePackSession, ok := session.(transport.ReceivePackSession)
if !ok {
err = fmt.Errorf("Could not create receive-pack session")
return
}
reportStatus, err := receivePackSession.ReceivePack(context, receivePackRequest)
if err != nil || reportStatus == nil {
return
}
return reportStatus.Encode(writer)
} and then calling it like: err = receivePack(request.Context(), session, request.Body, writer) where the I use essentially the same flow for the |
I'm trying to do this over ssh and run into this error: code sample:
This is based on gitreposerver by @seankhliao -- Pretty sure I'm doing something wrong here 🤔 |
@prologic I have added no-thin capability to advertise reference and it helps:
full code of updated InfoRefs handler:
|
I assume I can do the same/similar with the SSH handler too? 🤔 |
So this helps with pushing over http, but over ssh I end up with an error I don't understand: On the server side:
On the client side:
|
Full code here: https://git.mills.io/prologic/legit |
I've been hit by the same issue but I've been able to figure it out.
And it works. Hopefully someone finds it helpful. |
@scabala Do you have code sample of your workaround? It would be good if this bug was fixed 👌 |
Hi, type ReaderFakeCloser struct {
r io.Reader
}
func (rfc ReaderFakeCloser) Read(data []byte) (int, error) {
return rfc.r.Read(data)
}
func (rfc ReaderFakeCloser) Close() error {
fmt.Println("Gotcha!")
return nil
}
// .. somewhere later in the code ...
// `s` is ssh.Channel instance
receivePackRequest := packp.NewReferenceUpdateRequest()
err = receivePackRequest.Decode(ReaderFakeCloser{r: s})
// ... and later as in other examples In essence, there's assumption that |
@scabala Thanks! I'll try this out 👌 |
I'm not sure that this solved one of my original problems though :/ But I'd need to spend a bit more time to go back and understand what'g going on here hmmm
|
I was able to pull and push on ssh after combining your code and debugging all afternoon. @prologic I was able to get it to work after making the following modifications to yours. ar, err := sess.AdvertisedReferencesContext(ctx)
if err != nil {
return fmt.Errorf("get advertised references: %w", err)
}
+ if err := ar.Capabilities.Add("no-thin"); err != nil {
+ return fmt.Errorf("get advertised references: %w", err)
+ }
err = ar.Encode(ch)
if err != nil {
return fmt.Errorf("encode advertised references: %w", err)
}
rur := packp.NewReferenceUpdateRequest()
+ err = rur.Decode(ReaderFakeCloser{r: ch}) // from @scabala's ReaderFakeCloser
if err != nil {
return fmt.Errorf("decode reference-update request: %w", err)
}
|
Glad it helped you @siaikin. Did you manage to have success for two, consecutive |
Yes I can push multiple times on the normal call flow. Here is my code for this, maybe it will help you. |
To help us keep things tidy and focus on the active tasks, we've introduced a stale bot to spot issues/PRs that haven't had any activity in a while. This particular issue hasn't had any updates or activity in the past 90 days, so it's been labeled as 'stale'. If it remains inactive for the next 30 days, it'll be automatically closed. We understand everyone's busy, but if this issue is still important to you, please feel free to add a comment or make an update to keep it active. Thanks for your understanding and cooperation! |
Hi all, is there have an example of creating a git server using this repository? thanks!
The text was updated successfully, but these errors were encountered: