1package git23import (4 "context"5 "time"6)78// UpdateServerInfoOptions contains optional arguments for updating auxiliary9// info file on the server side.10//11// Docs: https://git-scm.com/docs/git-update-server-info12type UpdateServerInfoOptions struct {13 // Indicates whether to overwrite the existing server info.14 Force bool15 CommandOptions16}1718// UpdateServerInfo updates the auxiliary info file on the server side for the19// repository in given path.20func UpdateServerInfo(ctx context.Context, path string, opts ...UpdateServerInfoOptions) error {21 var opt UpdateServerInfoOptions22 if len(opts) > 0 {23 opt = opts[0]24 }2526 args := []string{"update-server-info"}27 if opt.Force {28 args = append(args, "--force")29 }30 args = append(args, "--end-of-options")31 _, err := exec(ctx, path, args, opt.Envs)32 return err33}3435// ReceivePackOptions contains optional arguments for receiving the info pushed36// to the repository.37//38// Docs: https://git-scm.com/docs/git-receive-pack39type ReceivePackOptions struct {40 // Indicates whether to suppress the log output.41 Quiet bool42 // Indicates whether to generate the "info/refs" used by the "git http-backend".43 HTTPBackendInfoRefs bool44 CommandOptions45}4647// ReceivePack receives what is pushed into the repository in given path.48func ReceivePack(ctx context.Context, path string, opts ...ReceivePackOptions) ([]byte, error) {49 var opt ReceivePackOptions50 if len(opts) > 0 {51 opt = opts[0]52 }5354 args := []string{"receive-pack"}55 if opt.Quiet {56 args = append(args, "--quiet")57 }58 if opt.HTTPBackendInfoRefs {59 args = append(args, "--http-backend-info-refs")60 }61 args = append(args, "--end-of-options", ".")62 return exec(ctx, path, args, opt.Envs)63}6465// UploadPackOptions contains optional arguments for sending the packfile to the66// client.67//68// Docs: https://git-scm.com/docs/git-upload-pack69type UploadPackOptions struct {70 // Indicates whether to quit after a single request/response exchange.71 StatelessRPC bool72 // Indicates whether to not try "<directory>/.git/" if "<directory>" is not a73 // Git directory.74 Strict bool75 // Indicates whether to generate the "info/refs" used by the "git http-backend".76 HTTPBackendInfoRefs bool77 // The git-level inactivity timeout passed to git-upload-pack's --timeout flag.78 // This is separate from the command execution timeout which is controlled via79 // context.Context.80 InactivityTimeout time.Duration81 CommandOptions82}8384// UploadPack sends the packfile to the client for the repository in given path.85func UploadPack(ctx context.Context, path string, opts ...UploadPackOptions) ([]byte, error) {86 var opt UploadPackOptions87 if len(opts) > 0 {88 opt = opts[0]89 }9091 args := []string{"upload-pack"}92 if opt.StatelessRPC {93 args = append(args, "--stateless-rpc")94 }95 if opt.Strict {96 args = append(args, "--strict")97 }98 if opt.InactivityTimeout > 0 {99 args = append(args, "--timeout", opt.InactivityTimeout.String())100 }101 if opt.HTTPBackendInfoRefs {102 args = append(args, "--http-backend-info-refs")103 }104 args = append(args, "--end-of-options", ".")105 return exec(ctx, path, args, opt.Envs)106}