1package git23import (4 "context"5 "path/filepath"6 "strings"7)89// ArchiveFormat is the format of an archive.10type ArchiveFormat string1112// A list of formats can be created by Git for an archive.13const (14 ArchiveZip ArchiveFormat = "zip"15 ArchiveTarGz ArchiveFormat = "tar.gz"16)1718// Archive creates given format of archive to the destination.19func (c *Commit) Archive(ctx context.Context, format ArchiveFormat, dst string) error {20 prefix := filepath.Base(strings.TrimSuffix(c.repo.path, ".git")) + "/"21 _, err := exec(ctx,22 c.repo.path,23 []string{24 "archive",25 "--prefix=" + prefix,26 "--format=" + string(format),27 "-o", dst,28 "--end-of-options",29 c.ID.String(),30 },31 nil,32 )33 return err34}