mirror of
https://github.com/go-gitea/gitea
synced 2024-08-17 12:50:52 +02:00
* Add configurable Trust Models Gitea's default signature verification model differs from GitHub. GitHub uses signatures to verify that the committer is who they say they are - meaning that when GitHub makes a signed commit it must be the committer. The GitHub model prevents re-publishing of commits after revocation of a key and prevents re-signing of other people's commits to create a completely trusted repository signed by one key or a set of trusted keys. The default behaviour of Gitea in contrast is to always display the avatar and information related to a signature. This allows signatures to be decoupled from the committer. That being said, allowing arbitary users to present other peoples commits as theirs is not necessarily desired therefore we have a trust model whereby signatures from collaborators are marked trusted, signatures matching the commit line are marked untrusted and signatures that match a user in the db but not the committer line are marked unmatched. The problem with this model is that this conflicts with Github therefore we need to provide an option to allow users to choose the Github model should they wish to. Signed-off-by: Andrew Thornton <art27@cantab.net> * Adjust locale strings Signed-off-by: Andrew Thornton <art27@cantab.net> * as per @6543 Co-authored-by: 6543 <6543@obermui.de> * Update models/gpg_key.go * Add migration for repository Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
83 lines
2.7 KiB
Go
83 lines
2.7 KiB
Go
// Copyright 2019 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.
|
|
|
|
package repository
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"code.gitea.io/gitea/models"
|
|
"code.gitea.io/gitea/modules/git"
|
|
"code.gitea.io/gitea/modules/log"
|
|
"code.gitea.io/gitea/modules/setting"
|
|
"code.gitea.io/gitea/modules/util"
|
|
)
|
|
|
|
// CreateRepository creates a repository for the user/organization.
|
|
func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (_ *models.Repository, err error) {
|
|
if !doer.IsAdmin && !u.CanCreateRepo() {
|
|
return nil, models.ErrReachLimitOfRepo{
|
|
Limit: u.MaxRepoCreation,
|
|
}
|
|
}
|
|
|
|
if len(opts.DefaultBranch) == 0 {
|
|
opts.DefaultBranch = setting.Repository.DefaultBranch
|
|
}
|
|
|
|
repo := &models.Repository{
|
|
OwnerID: u.ID,
|
|
Owner: u,
|
|
OwnerName: u.Name,
|
|
Name: opts.Name,
|
|
LowerName: strings.ToLower(opts.Name),
|
|
Description: opts.Description,
|
|
OriginalURL: opts.OriginalURL,
|
|
OriginalServiceType: opts.GitServiceType,
|
|
IsPrivate: opts.IsPrivate,
|
|
IsFsckEnabled: !opts.IsMirror,
|
|
CloseIssuesViaCommitInAnyBranch: setting.Repository.DefaultCloseIssuesViaCommitsInAnyBranch,
|
|
Status: opts.Status,
|
|
IsEmpty: !opts.AutoInit,
|
|
TrustModel: opts.TrustModel,
|
|
}
|
|
|
|
err = models.WithTx(func(ctx models.DBContext) error {
|
|
if err = models.CreateRepository(ctx, doer, u, repo); err != nil {
|
|
return err
|
|
}
|
|
|
|
// No need for init mirror.
|
|
if !opts.IsMirror {
|
|
repoPath := models.RepoPath(u.Name, repo.Name)
|
|
if err = initRepository(ctx, repoPath, doer, repo, opts); err != nil {
|
|
if err2 := util.RemoveAll(repoPath); err2 != nil {
|
|
log.Error("initRepository: %v", err)
|
|
return fmt.Errorf(
|
|
"delete repo directory %s/%s failed(2): %v", u.Name, repo.Name, err2)
|
|
}
|
|
return fmt.Errorf("initRepository: %v", err)
|
|
}
|
|
|
|
// Initialize Issue Labels if selected
|
|
if len(opts.IssueLabels) > 0 {
|
|
if err = models.InitializeLabels(ctx, repo.ID, opts.IssueLabels, false); err != nil {
|
|
return fmt.Errorf("InitializeLabels: %v", err)
|
|
}
|
|
}
|
|
|
|
if stdout, err := git.NewCommand("update-server-info").
|
|
SetDescription(fmt.Sprintf("CreateRepository(git update-server-info): %s", repoPath)).
|
|
RunInDir(repoPath); err != nil {
|
|
log.Error("CreateRepository(git update-server-info) in %v: Stdout: %s\nError: %v", repo, stdout, err)
|
|
return fmt.Errorf("CreateRepository(git update-server-info): %v", err)
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
|
|
return repo, err
|
|
}
|