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.

36 lines
717 B

  1. // Copyright 2014 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. "github.com/Unknwon/com"
  8. )
  9. type ArchiveType int
  10. const (
  11. ZIP ArchiveType = iota + 1
  12. TARGZ
  13. )
  14. func (c *Commit) CreateArchive(path string, archiveType ArchiveType) error {
  15. var format string
  16. switch archiveType {
  17. case ZIP:
  18. format = "zip"
  19. case TARGZ:
  20. format = "tar.gz"
  21. default:
  22. return fmt.Errorf("unknown format: %v", archiveType)
  23. }
  24. _, stderr, err := com.ExecCmdDir(c.repo.Path, "git", "archive", "--format="+format, "-o", path, c.Id.String())
  25. if err != nil {
  26. return fmt.Errorf("%s", stderr)
  27. }
  28. return nil
  29. }