* Allow archive prefix setting * Update copyright * Update copyrighttags/v1.10.5
; External wiki and issue tracker can't be enabled by default as it requires additional settings. | ; External wiki and issue tracker can't be enabled by default as it requires additional settings. | ||||
; Disabled repo units will not be added to new repositories regardless if it is in the default list. | ; Disabled repo units will not be added to new repositories regardless if it is in the default list. | ||||
DEFAULT_REPO_UNITS = repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki | DEFAULT_REPO_UNITS = repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki | ||||
; Prefix archive files by placing them in a directory named after the repository | |||||
PREFIX_ARCHIVE_FILES = true | |||||
[repository.editor] | [repository.editor] | ||||
; List of file extensions for which lines should be wrapped in the CodeMirror editor | ; List of file extensions for which lines should be wrapped in the CodeMirror editor |
- `DEFAULT_CLOSE_ISSUES_VIA_COMMITS_IN_ANY_BRANCH`: **false**: Close an issue if a commit on a non default branch marks it as closed. | - `DEFAULT_CLOSE_ISSUES_VIA_COMMITS_IN_ANY_BRANCH`: **false**: Close an issue if a commit on a non default branch marks it as closed. | ||||
- `ENABLE_PUSH_CREATE_USER`: **false**: Allow users to push local repositories to Gitea and have them automatically created for a user. | - `ENABLE_PUSH_CREATE_USER`: **false**: Allow users to push local repositories to Gitea and have them automatically created for a user. | ||||
- `ENABLE_PUSH_CREATE_ORG`: **false**: Allow users to push local repositories to Gitea and have them automatically created for an org. | - `ENABLE_PUSH_CREATE_ORG`: **false**: Allow users to push local repositories to Gitea and have them automatically created for an org. | ||||
- `PREFIX_ARCHIVE_FILES`: **true**: Prefix archive files by placing them in a directory named after the repository. | |||||
### Repository - Pull Request (`repository.pull-request`) | ### Repository - Pull Request (`repository.pull-request`) | ||||
// Copyright 2015 The Gogs Authors. All rights reserved. | // 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 | // Use of this source code is governed by a MIT-style | ||||
// license that can be found in the LICENSE file. | // license that can be found in the LICENSE file. | ||||
TARGZ | 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: | case ZIP: | ||||
format = "zip" | |||||
return "zip" | |||||
case TARGZ: | 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 | return err | ||||
} | } |
EnablePushCreateOrg bool | EnablePushCreateOrg bool | ||||
DisabledRepoUnits []string | DisabledRepoUnits []string | ||||
DefaultRepoUnits []string | DefaultRepoUnits []string | ||||
PrefixArchiveFiles bool | |||||
// Repository editor settings | // Repository editor settings | ||||
Editor struct { | Editor struct { | ||||
EnablePushCreateOrg: false, | EnablePushCreateOrg: false, | ||||
DisabledRepoUnits: []string{}, | DisabledRepoUnits: []string{}, | ||||
DefaultRepoUnits: []string{}, | DefaultRepoUnits: []string{}, | ||||
PrefixArchiveFiles: true, | |||||
// Repository editor settings | // Repository editor settings | ||||
Editor: struct { | Editor: struct { |
// Copyright 2014 The Gogs Authors. All rights reserved. | // Copyright 2014 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 | // Use of this source code is governed by a MIT-style | ||||
// license that can be found in the LICENSE file. | // license that can be found in the LICENSE file. | ||||
archivePath = path.Join(archivePath, base.ShortSha(commit.ID.String())+ext) | archivePath = path.Join(archivePath, base.ShortSha(commit.ID.String())+ext) | ||||
if !com.IsFile(archivePath) { | if !com.IsFile(archivePath) { | ||||
if err := commit.CreateArchive(archivePath, archiveType); err != nil { | |||||
if err := commit.CreateArchive(archivePath, git.CreateArchiveOpts{ | |||||
Format: archiveType, | |||||
Prefix: setting.Repository.PrefixArchiveFiles, | |||||
}); err != nil { | |||||
ctx.ServerError("Download -> CreateArchive "+archivePath, err) | ctx.ServerError("Download -> CreateArchive "+archivePath, err) | ||||
return | return | ||||
} | } |