-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Make archive prefixing configurable with a global setting #9943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps, if anything, we could add another constant for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't really seem worth it - the unknown is only used in that file and in those two places. |
||
return fmt.Errorf("unknown format: %v", opts.Format) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @guillep2k this is the line I was referencing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! I'd missed it. |
||
} | ||
|
||
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(), | ||
techknowlogick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"-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 | ||
} |
Uh oh!
There was an error while loading. Please reload this page.