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.

33 lines
730 B

  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. type ArchiveType int
  11. const (
  12. ZIP ArchiveType = iota + 1
  13. TARGZ
  14. )
  15. func (c *Commit) CreateArchive(target string, archiveType ArchiveType) error {
  16. var format string
  17. switch archiveType {
  18. case ZIP:
  19. format = "zip"
  20. case TARGZ:
  21. format = "tar.gz"
  22. default:
  23. return fmt.Errorf("unknown format: %v", archiveType)
  24. }
  25. _, err := NewCommand("archive", "--prefix="+filepath.Base(strings.TrimSuffix(c.repo.Path, ".git"))+"/", "--format="+format, "-o", target, c.ID.String()).RunInDir(c.repo.Path)
  26. return err
  27. }