git-module

git clone git://git.lin.moe/fork/git-module.git

 1package git
 2
 3import (
 4	"context"
 5	"path/filepath"
 6	"strings"
 7)
 8
 9// ArchiveFormat is the format of an archive.
10type ArchiveFormat string
11
12// A list of formats can be created by Git for an archive.
13const (
14	ArchiveZip   ArchiveFormat = "zip"
15	ArchiveTarGz ArchiveFormat = "tar.gz"
16)
17
18// 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 err
34}