本站源代码
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

38 行
873B

  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. }
上海开阖软件有限公司 沪ICP备12045867号-1