diff options
author | Ayman Bagabas <ayman.bagabas@gmail.com> | 2023-10-29 16:35:09 -0400 |
---|---|---|
committer | Ayman Bagabas <ayman.bagabas@gmail.com> | 2023-11-03 16:59:11 -0400 |
commit | ce0b76e7674d683db547103bc773305129a0ded4 (patch) | |
tree | 3b609eb2f88bee83076250d1d69fe80b65cf439e /cli | |
parent | 22585738b4b13797f241a04b9cb6b48b31056aac (diff) | |
download | go-git-ce0b76e7674d683db547103bc773305129a0ded4.tar.gz |
git: implement upload-server-info. Fixes #731
This adds UpdateServerInfo along with a new go-git command to generate
info files to help git dumb http serve refs and their objects.
This also updates the docs to reflect this.
Docs: https://git-scm.com/docs/git-update-server-info
Fixes: https://github.com/go-git/go-git/issues/731
Diffstat (limited to 'cli')
-rw-r--r-- | cli/go-git/main.go | 1 | ||||
-rw-r--r-- | cli/go-git/update_server_info.go | 34 |
2 files changed, 35 insertions, 0 deletions
diff --git a/cli/go-git/main.go b/cli/go-git/main.go index 97b8c3e..0a5ad2c 100644 --- a/cli/go-git/main.go +++ b/cli/go-git/main.go @@ -22,6 +22,7 @@ func main() { } parser := flags.NewNamedParser(bin, flags.Default) + parser.AddCommand("update-server-info", "", "", &CmdUpdateServerInfo{}) parser.AddCommand("receive-pack", "", "", &CmdReceivePack{}) parser.AddCommand("upload-pack", "", "", &CmdUploadPack{}) parser.AddCommand("version", "Show the version information.", "", &CmdVersion{}) diff --git a/cli/go-git/update_server_info.go b/cli/go-git/update_server_info.go new file mode 100644 index 0000000..a7f3e3e --- /dev/null +++ b/cli/go-git/update_server_info.go @@ -0,0 +1,34 @@ +package main + +import ( + "fmt" + "os" + + "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing/serverinfo" + "github.com/go-git/go-git/v5/storage/filesystem" +) + +// CmdUpdateServerInfo command updates the server info files in the repository. +// This is used by git http transport (dumb) to generate a list of available +// refs for the repository. See: +// https://git-scm.com/docs/git-update-server-info +type CmdUpdateServerInfo struct { + cmd +} + +// Usage returns the usage of the command. +func (CmdUpdateServerInfo) Usage() string { + return fmt.Sprintf("within a git repository run: %s", os.Args[0]) +} + +// Execute runs the command. +func (c *CmdUpdateServerInfo) Execute(args []string) error { + r, err := git.PlainOpen(".") + if err != nil { + return err + } + + fs := r.Storer.(*filesystem.Storage).Filesystem() + return serverinfo.UpdateServerInfo(r.Storer, fs) +} |