From e1664fcbc4685906d3dabc66bf947a17bce7efc0 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Sat, 22 Jun 2024 16:30:47 +0200 Subject: feat: Add archive capability --- pkg/service/git.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'pkg/service') diff --git a/pkg/service/git.go b/pkg/service/git.go index 6bb6e9e..cbee90a 100644 --- a/pkg/service/git.go +++ b/pkg/service/git.go @@ -1,7 +1,9 @@ package service import ( + "compress/gzip" "errors" + "io" "log/slog" "git.gabrielgio.me/cerrado/pkg/config" @@ -92,6 +94,29 @@ func (g *GitService) ListCommits(name, ref string, count int) ([]*object.Commit, return repo.Commits(count) } +func (g *GitService) WriteTarGZip(w io.Writer, name, ref string, filename string) error { + r := g.configRepo.GetByName(name) + if r == nil { + return RepositoryNotFoundErr + } + + repo, err := git.OpenRepository(r.Path) + if err != nil { + return err + } + + err = repo.SetRef(ref) + if err != nil { + return err + } + + gw := gzip.NewWriter(w) + defer gw.Close() + + return repo.WriteTar(gw, filename) + +} + func (g *GitService) GetTree(name, ref, path string) (*object.Tree, error) { r := g.configRepo.GetByName(name) if r == nil { -- cgit v1.2.3