mirror of
https://github.com/gogs/gogs.git
synced 2026-11-29 21:14:36 +01:00
41 lines
1003 B
Go
41 lines
1003 B
Go
package git
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/trace"
|
|
)
|
|
|
|
// ArchiveFormat is the format of an archive.
|
|
type ArchiveFormat string
|
|
|
|
// A list of formats that Git can create an archive in.
|
|
const (
|
|
ArchiveZip ArchiveFormat = "zip"
|
|
ArchiveTarGz ArchiveFormat = "tar.gz"
|
|
)
|
|
|
|
// Archive creates given format of archive to the destination.
|
|
func (c *Commit) Archive(ctx context.Context, format ArchiveFormat, dst string) (err error) {
|
|
ctx, span := tracer.Start(ctx, "git.Commit.Archive", trace.WithAttributes(attribute.String("git.commit", c.ID.String()), attribute.String("git.archive.format", string(format))))
|
|
defer func() { endSpan(span, err) }()
|
|
|
|
prefix := filepath.Base(strings.TrimSuffix(c.repo.path, ".git")) + "/"
|
|
_, err = exec(ctx,
|
|
c.repo.path,
|
|
[]string{
|
|
"archive",
|
|
"--prefix=" + prefix,
|
|
"--format=" + string(format),
|
|
"-o", dst,
|
|
"--end-of-options",
|
|
c.ID.String(),
|
|
},
|
|
nil,
|
|
)
|
|
return err
|
|
}
|