You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

commit_archive.go 873B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package git
  5. import (
  6. "fmt"
  7. "path/filepath"
  8. "strings"
  9. )
  10. // ArchiveType archive types
  11. type ArchiveType int
  12. const (
  13. // ZIP zip archive type
  14. ZIP ArchiveType = iota + 1
  15. // TARGZ tar gz archive type
  16. TARGZ
  17. )
  18. // CreateArchive create archive content to the target path
  19. func (c *Commit) CreateArchive(target string, archiveType ArchiveType) error {
  20. var format string
  21. switch archiveType {
  22. case ZIP:
  23. format = "zip"
  24. case TARGZ:
  25. format = "tar.gz"
  26. default:
  27. return fmt.Errorf("unknown format: %v", archiveType)
  28. }
  29. _, err := NewCommand("archive", "--prefix="+filepath.Base(strings.TrimSuffix(c.repo.Path, ".git"))+"/", "--format="+format, "-o", target, c.ID.String()).RunInDir(c.repo.Path)
  30. return err
  31. }