diff options
author | zeripath <art27@cantab.net> | 2020-01-22 23:46:46 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-22 23:46:46 +0000 |
commit | c8d7ae1ee33e31ed15632a26c74ba9a3ea115043 (patch) | |
tree | f26103ff819952d2875a48ce0b1fe99417ad2bbd /modules | |
parent | 608cd58db670b061ca898930401458b30264a6c9 (diff) | |
download | gitea-c8d7ae1ee33e31ed15632a26c74ba9a3ea115043.tar.gz gitea-c8d7ae1ee33e31ed15632a26c74ba9a3ea115043.zip |
Make archive prefixing configurable with a global setting (#9943)
* Allow archive prefix setting
* Update copyright
* Update copyright
Diffstat (limited to 'modules')
-rw-r--r-- | modules/git/commit_archive.go | 44 | ||||
-rw-r--r-- | modules/setting/repository.go | 2 |
2 files changed, 37 insertions, 9 deletions
diff --git a/modules/git/commit_archive.go b/modules/git/commit_archive.go index e13825a962..c7d1d06c46 100644 --- a/modules/git/commit_archive.go +++ b/modules/git/commit_archive.go @@ -1,4 +1,5 @@ // Copyright 2015 The Gogs Authors. All rights reserved. +// Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -20,18 +21,43 @@ const ( TARGZ ) -// CreateArchive create archive content to the target path -func (c *Commit) CreateArchive(target string, archiveType ArchiveType) error { - var format string - switch archiveType { +// String converts an ArchiveType to string +func (a ArchiveType) String() string { + switch a { case ZIP: - format = "zip" + return "zip" case TARGZ: - format = "tar.gz" - default: - return fmt.Errorf("unknown format: %v", archiveType) + return "tar.gz" } + return "unknown" +} + +// CreateArchiveOpts represents options for creating an archive +type CreateArchiveOpts struct { + Format ArchiveType + Prefix bool +} + +// CreateArchive create archive content to the target path +func (c *Commit) CreateArchive(target string, opts CreateArchiveOpts) error { + if opts.Format.String() == "unknown" { + return fmt.Errorf("unknown format: %v", opts.Format) + } + + args := []string{ + "archive", + } + if opts.Prefix { + args = append(args, "--prefix="+filepath.Base(strings.TrimSuffix(c.repo.Path, ".git"))+"/") + } + + args = append(args, + "--format="+opts.Format.String(), + "-o", + target, + c.ID.String(), + ) - _, err := NewCommand("archive", "--prefix="+filepath.Base(strings.TrimSuffix(c.repo.Path, ".git"))+"/", "--format="+format, "-o", target, c.ID.String()).RunInDir(c.repo.Path) + _, err := NewCommand(args...).RunInDir(c.repo.Path) return err } diff --git a/modules/setting/repository.go b/modules/setting/repository.go index 807b29b2d8..8af3eaaf46 100644 --- a/modules/setting/repository.go +++ b/modules/setting/repository.go @@ -39,6 +39,7 @@ var ( EnablePushCreateOrg bool DisabledRepoUnits []string DefaultRepoUnits []string + PrefixArchiveFiles bool // Repository editor settings Editor struct { @@ -102,6 +103,7 @@ var ( EnablePushCreateOrg: false, DisabledRepoUnits: []string{}, DefaultRepoUnits: []string{}, + PrefixArchiveFiles: true, // Repository editor settings Editor: struct { |