diff options
author | Paulo Gomes <pjbgf@linux.com> | 2023-11-03 21:51:40 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-03 21:51:40 +0000 |
commit | 8c1e3e2eb458677af127fc286a43ad262c3cca1e (patch) | |
tree | 3b609eb2f88bee83076250d1d69fe80b65cf439e /cli | |
parent | 22585738b4b13797f241a04b9cb6b48b31056aac (diff) | |
parent | ce0b76e7674d683db547103bc773305129a0ded4 (diff) | |
download | go-git-8c1e3e2eb458677af127fc286a43ad262c3cca1e.tar.gz |
Merge pull request #896 from aymanbagabas/update-server-info
Implement upload-server-info
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) +} |