forked from hinterland/hearth
feat: vendor gitea 1.16.2
This commit is contained in:
@@ -31,6 +31,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/templates/vars"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
)
|
||||
|
||||
// CreateRepoOptions contains the create repository options
|
||||
@@ -69,9 +70,10 @@ func prepareRepoCommit(ctx context.Context, repo *repo_model.Repository, tmpDir
|
||||
)
|
||||
|
||||
// Clone to temporary path and do the init commit.
|
||||
if stdout, _, err := gitcmd.NewCommand("clone").AddDynamicArguments(repo.RepoPath(), tmpDir).
|
||||
RunStdString(ctx, &gitcmd.RunOpts{Dir: "", Env: env}); err != nil {
|
||||
log.Error("Failed to clone from %v into %s: stdout: %s\nError: %v", repo, tmpDir, stdout, err)
|
||||
if err := gitrepo.CloneRepoToLocal(ctx, repo, tmpDir, git.CloneRepoOptions{
|
||||
Env: env,
|
||||
}); err != nil {
|
||||
log.Error("Failed to clone from %v into %s\nError: %v", repo, tmpDir, err)
|
||||
return fmt.Errorf("git clone: %w", err)
|
||||
}
|
||||
|
||||
@@ -84,7 +86,7 @@ func prepareRepoCommit(ctx context.Context, repo *repo_model.Repository, tmpDir
|
||||
cloneLink := repo.CloneLink(ctx, nil /* no doer so do not generate user-related SSH link */)
|
||||
match := map[string]string{
|
||||
"Name": repo.Name,
|
||||
"Description": repo.Description,
|
||||
"Description": util.NormalizeStringEOL(repo.Description),
|
||||
"CloneURL.SSH": cloneLink.SSH,
|
||||
"CloneURL.HTTPS": cloneLink.HTTPS,
|
||||
"OwnerName": repo.OwnerName,
|
||||
@@ -229,6 +231,9 @@ func CreateRepositoryDirectly(ctx context.Context, doer, owner *user_model.User,
|
||||
if opts.ObjectFormatName == "" {
|
||||
opts.ObjectFormatName = git.Sha1ObjectFormat.Name()
|
||||
}
|
||||
if opts.ObjectFormatName != git.Sha1ObjectFormat.Name() && opts.ObjectFormatName != git.Sha256ObjectFormat.Name() {
|
||||
return nil, fmt.Errorf("unsupported object format: %s", opts.ObjectFormatName)
|
||||
}
|
||||
|
||||
repo := &repo_model.Repository{
|
||||
OwnerID: owner.ID,
|
||||
@@ -264,8 +269,8 @@ func CreateRepositoryDirectly(ctx context.Context, doer, owner *user_model.User,
|
||||
// WARNING: Don't override all later err with local variables
|
||||
defer func() {
|
||||
if err != nil {
|
||||
// we can not use the ctx because it maybe canceled or timeout
|
||||
cleanupRepository(repo.ID)
|
||||
// we can not use `ctx` because it may be canceled or timed out
|
||||
cleanupRepository(repo)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -314,7 +319,7 @@ func CreateRepositoryDirectly(ctx context.Context, doer, owner *user_model.User,
|
||||
licenses = append(licenses, opts.License)
|
||||
|
||||
var stdout string
|
||||
stdout, _, err = gitcmd.NewCommand("rev-parse", "HEAD").RunStdString(ctx, &gitcmd.RunOpts{Dir: repo.RepoPath()})
|
||||
stdout, _, err = gitrepo.RunCmdString(ctx, repo, gitcmd.NewCommand("rev-parse", "HEAD"))
|
||||
if err != nil {
|
||||
log.Error("CreateRepository(git rev-parse HEAD) in %v: Stdout: %s\nError: %v", repo, stdout, err)
|
||||
return nil, fmt.Errorf("CreateRepository(git rev-parse HEAD): %w", err)
|
||||
@@ -382,15 +387,7 @@ func createRepositoryInDB(ctx context.Context, doer, u *user_model.User, repo *r
|
||||
},
|
||||
})
|
||||
case unit.TypePullRequests:
|
||||
units = append(units, repo_model.RepoUnit{
|
||||
RepoID: repo.ID,
|
||||
Type: tp,
|
||||
Config: &repo_model.PullRequestsConfig{
|
||||
AllowMerge: true, AllowRebase: true, AllowRebaseMerge: true, AllowSquash: true, AllowFastForwardOnly: true,
|
||||
DefaultMergeStyle: repo_model.MergeStyle(setting.Repository.PullRequest.DefaultMergeStyle),
|
||||
AllowRebaseUpdate: true,
|
||||
},
|
||||
})
|
||||
units = append(units, repo_model.DefaultPullRequestsUnit(repo.ID))
|
||||
case unit.TypeProjects:
|
||||
units = append(units, repo_model.RepoUnit{
|
||||
RepoID: repo.ID,
|
||||
@@ -460,11 +457,11 @@ func createRepositoryInDB(ctx context.Context, doer, u *user_model.User, repo *r
|
||||
return nil
|
||||
}
|
||||
|
||||
func cleanupRepository(repoID int64) {
|
||||
if errDelete := DeleteRepositoryDirectly(graceful.GetManager().ShutdownContext(), repoID); errDelete != nil {
|
||||
func cleanupRepository(repo *repo_model.Repository) {
|
||||
ctx := graceful.GetManager().ShutdownContext()
|
||||
if errDelete := DeleteRepositoryDirectly(ctx, repo.ID); errDelete != nil {
|
||||
log.Error("cleanupRepository failed: %v", errDelete)
|
||||
// add system notice
|
||||
if err := system_model.CreateRepositoryNotice("DeleteRepositoryDirectly failed when cleanup repository: %v", errDelete); err != nil {
|
||||
if err := system_model.CreateRepositoryNotice("DeleteRepositoryDirectly failed when cleanup repository (%s)", repo.FullName(), errDelete); err != nil {
|
||||
log.Error("CreateRepositoryNotice: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -475,8 +472,8 @@ func updateGitRepoAfterCreate(ctx context.Context, repo *repo_model.Repository)
|
||||
return fmt.Errorf("checkDaemonExportOK: %w", err)
|
||||
}
|
||||
|
||||
if stdout, _, err := gitcmd.NewCommand("update-server-info").
|
||||
RunStdString(ctx, &gitcmd.RunOpts{Dir: repo.RepoPath()}); err != nil {
|
||||
if stdout, _, err := gitrepo.RunCmdString(ctx, repo,
|
||||
gitcmd.NewCommand("update-server-info")); 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): %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user