mirror of
https://github.com/go-gitea/gitea
synced 2025-07-23 02:38:35 +00:00
Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551)
Found using `find . -type f -name '*.go' -print -exec vim {} -c ':%s/fmt\.Errorf(\(.*\)%v\(.*\)err/fmt.Errorf(\1%w\2err/g' -c ':wq' \;` Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Andrew Thornton <art27@cantab.net> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -99,7 +99,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
||||
pr, err := issues_model.GetUnmergedPullRequest(repo.ID, repo.ID, headBranch, baseBranchName, issues_model.PullRequestFlowAGit)
|
||||
if err != nil {
|
||||
if !issues_model.IsErrPullRequestNotExist(err) {
|
||||
return nil, fmt.Errorf("Failed to get unmerged agit flow pull request in repository: %s/%s Error: %v", ownerName, repoName, err)
|
||||
return nil, fmt.Errorf("Failed to get unmerged agit flow pull request in repository: %s/%s Error: %w", ownerName, repoName, err)
|
||||
}
|
||||
|
||||
// create a new pull request
|
||||
@@ -109,7 +109,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
||||
if !has || len(title) == 0 {
|
||||
commit, err := gitRepo.GetCommit(opts.NewCommitIDs[i])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to get commit %s in repository: %s/%s Error: %v", opts.NewCommitIDs[i], ownerName, repoName, err)
|
||||
return nil, fmt.Errorf("Failed to get commit %s in repository: %s/%s Error: %w", opts.NewCommitIDs[i], ownerName, repoName, err)
|
||||
}
|
||||
title = strings.Split(commit.CommitMessage, "\n")[0]
|
||||
}
|
||||
@@ -118,7 +118,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
||||
|
||||
pusher, err := user_model.GetUserByID(opts.UserID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to get user. Error: %v", err)
|
||||
return nil, fmt.Errorf("Failed to get user. Error: %w", err)
|
||||
}
|
||||
|
||||
prIssue := &issues_model.Issue{
|
||||
@@ -160,12 +160,12 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
||||
|
||||
// update exist pull request
|
||||
if err := pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
return nil, fmt.Errorf("Unable to load base repository for PR[%d] Error: %v", pr.ID, err)
|
||||
return nil, fmt.Errorf("Unable to load base repository for PR[%d] Error: %w", pr.ID, err)
|
||||
}
|
||||
|
||||
oldCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Unable to get ref commit id in base repository for PR[%d] Error: %v", pr.ID, err)
|
||||
return nil, fmt.Errorf("Unable to get ref commit id in base repository for PR[%d] Error: %w", pr.ID, err)
|
||||
}
|
||||
|
||||
if oldCommitID == opts.NewCommitIDs[i] {
|
||||
@@ -181,7 +181,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
||||
if !forcePush {
|
||||
output, _, err := git.NewCommand(ctx, "rev-list", "--max-count=1").AddDynamicArguments(oldCommitID, "^"+opts.NewCommitIDs[i]).RunStdString(&git.RunOpts{Dir: repo.RepoPath(), Env: os.Environ()})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Fail to detect force push: %v", err)
|
||||
return nil, fmt.Errorf("Fail to detect force push: %w", err)
|
||||
} else if len(output) > 0 {
|
||||
results = append(results, private.HookProcReceiveRefResult{
|
||||
OriginalRef: opts.RefFullNames[i],
|
||||
@@ -195,17 +195,17 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
||||
|
||||
pr.HeadCommitID = opts.NewCommitIDs[i]
|
||||
if err = pull_service.UpdateRef(ctx, pr); err != nil {
|
||||
return nil, fmt.Errorf("Failed to update pull ref. Error: %v", err)
|
||||
return nil, fmt.Errorf("Failed to update pull ref. Error: %w", err)
|
||||
}
|
||||
|
||||
pull_service.AddToTaskQueue(pr)
|
||||
pusher, err := user_model.GetUserByID(opts.UserID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to get user. Error: %v", err)
|
||||
return nil, fmt.Errorf("Failed to get user. Error: %w", err)
|
||||
}
|
||||
err = pr.LoadIssue()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to load pull issue. Error: %v", err)
|
||||
return nil, fmt.Errorf("Failed to load pull issue. Error: %w", err)
|
||||
}
|
||||
comment, err := issues_model.CreatePushPullComment(ctx, pusher, pr, oldCommitID, opts.NewCommitIDs[i])
|
||||
if err == nil && comment != nil {
|
||||
|
@@ -29,7 +29,7 @@ func NewAttachment(attach *repo_model.Attachment, file io.Reader) (*repo_model.A
|
||||
attach.UUID = uuid.New().String()
|
||||
size, err := storage.Attachments.Save(attach.RelativePath(), file, -1)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Create: %v", err)
|
||||
return fmt.Errorf("Create: %w", err)
|
||||
}
|
||||
attach.Size = size
|
||||
|
||||
|
@@ -125,13 +125,13 @@ func dial(source *Source) (*ldap.Conn, error) {
|
||||
|
||||
conn, err := ldap.Dial("tcp", net.JoinHostPort(source.Host, strconv.Itoa(source.Port)))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error during Dial: %v", err)
|
||||
return nil, fmt.Errorf("error during Dial: %w", err)
|
||||
}
|
||||
|
||||
if source.SecurityProtocol == SecurityProtocolStartTLS {
|
||||
if err = conn.StartTLS(tlsConfig); err != nil {
|
||||
conn.Close()
|
||||
return nil, fmt.Errorf("error during StartTLS: %v", err)
|
||||
return nil, fmt.Errorf("error during StartTLS: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -339,7 +339,7 @@ func InitSigningKey() error {
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error while loading or creating JWT key: %v", err)
|
||||
return fmt.Errorf("Error while loading or creating JWT key: %w", err)
|
||||
}
|
||||
|
||||
signingKey, err := CreateJWTSigningKey(setting.OAuth2.JWTSigningAlgorithm, key)
|
||||
|
@@ -95,7 +95,7 @@ func Authenticate(a smtp.Auth, source *Source) error {
|
||||
hasStartTLS, _ := client.Extension("STARTTLS")
|
||||
if !source.UseTLS() && hasStartTLS {
|
||||
if err = client.StartTLS(tlsConfig); err != nil {
|
||||
return fmt.Errorf("failed to start StartTLS: %v", err)
|
||||
return fmt.Errorf("failed to start StartTLS: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -19,7 +19,7 @@ func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *is
|
||||
if issue.MilestoneID > 0 {
|
||||
has, err := issues_model.HasMilestoneByRepoID(ctx, issue.RepoID, issue.MilestoneID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("HasMilestoneByRepoID: %v", err)
|
||||
return fmt.Errorf("HasMilestoneByRepoID: %w", err)
|
||||
}
|
||||
if !has {
|
||||
return fmt.Errorf("HasMilestoneByRepoID: issue doesn't exist")
|
||||
@@ -76,7 +76,7 @@ func ChangeMilestoneAssign(issue *issues_model.Issue, doer *user_model.User, old
|
||||
}
|
||||
|
||||
if err = committer.Commit(); err != nil {
|
||||
return fmt.Errorf("Commit: %v", err)
|
||||
return fmt.Errorf("Commit: %w", err)
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeMilestone(doer, issue, oldMilestoneID)
|
||||
|
@@ -44,13 +44,13 @@ const (
|
||||
func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_model.User) error {
|
||||
// Required by the mail composer; make sure to load these before calling the async function
|
||||
if err := ctx.Issue.LoadRepo(ctx); err != nil {
|
||||
return fmt.Errorf("LoadRepo(): %v", err)
|
||||
return fmt.Errorf("LoadRepo(): %w", err)
|
||||
}
|
||||
if err := ctx.Issue.LoadPoster(); err != nil {
|
||||
return fmt.Errorf("LoadPoster(): %v", err)
|
||||
return fmt.Errorf("LoadPoster(): %w", err)
|
||||
}
|
||||
if err := ctx.Issue.LoadPullRequest(); err != nil {
|
||||
return fmt.Errorf("LoadPullRequest(): %v", err)
|
||||
return fmt.Errorf("LoadPullRequest(): %w", err)
|
||||
}
|
||||
|
||||
// Enough room to avoid reallocations
|
||||
@@ -62,21 +62,21 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_mo
|
||||
// =========== Assignees ===========
|
||||
ids, err := issues_model.GetAssigneeIDsByIssue(ctx.Issue.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetAssigneeIDsByIssue(%d): %v", ctx.Issue.ID, err)
|
||||
return fmt.Errorf("GetAssigneeIDsByIssue(%d): %w", ctx.Issue.ID, err)
|
||||
}
|
||||
unfiltered = append(unfiltered, ids...)
|
||||
|
||||
// =========== Participants (i.e. commenters, reviewers) ===========
|
||||
ids, err = issues_model.GetParticipantsIDsByIssueID(ctx.Issue.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetParticipantsIDsByIssueID(%d): %v", ctx.Issue.ID, err)
|
||||
return fmt.Errorf("GetParticipantsIDsByIssueID(%d): %w", ctx.Issue.ID, err)
|
||||
}
|
||||
unfiltered = append(unfiltered, ids...)
|
||||
|
||||
// =========== Issue watchers ===========
|
||||
ids, err = issues_model.GetIssueWatchersIDs(ctx, ctx.Issue.ID, true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetIssueWatchersIDs(%d): %v", ctx.Issue.ID, err)
|
||||
return fmt.Errorf("GetIssueWatchersIDs(%d): %w", ctx.Issue.ID, err)
|
||||
}
|
||||
unfiltered = append(unfiltered, ids...)
|
||||
|
||||
@@ -85,7 +85,7 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_mo
|
||||
if !(ctx.Issue.IsPull && ctx.Issue.PullRequest.IsWorkInProgress() && ctx.ActionType != activities_model.ActionCreatePullRequest) {
|
||||
ids, err = repo_model.GetRepoWatchersIDs(ctx, ctx.Issue.RepoID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetRepoWatchersIDs(%d): %v", ctx.Issue.RepoID, err)
|
||||
return fmt.Errorf("GetRepoWatchersIDs(%d): %w", ctx.Issue.RepoID, err)
|
||||
}
|
||||
unfiltered = append(ids, unfiltered...)
|
||||
}
|
||||
@@ -99,13 +99,13 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_mo
|
||||
|
||||
// =========== Mentions ===========
|
||||
if err = mailIssueCommentBatch(ctx, mentions, visited, true); err != nil {
|
||||
return fmt.Errorf("mailIssueCommentBatch() mentions: %v", err)
|
||||
return fmt.Errorf("mailIssueCommentBatch() mentions: %w", err)
|
||||
}
|
||||
|
||||
// Avoid mailing explicit unwatched
|
||||
ids, err = issues_model.GetIssueWatchersIDs(ctx, ctx.Issue.ID, false)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetIssueWatchersIDs(%d): %v", ctx.Issue.ID, err)
|
||||
return fmt.Errorf("GetIssueWatchersIDs(%d): %w", ctx.Issue.ID, err)
|
||||
}
|
||||
visited.AddMultiple(ids...)
|
||||
|
||||
@@ -114,7 +114,7 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_mo
|
||||
return err
|
||||
}
|
||||
if err = mailIssueCommentBatch(ctx, unfilteredUsers, visited, false); err != nil {
|
||||
return fmt.Errorf("mailIssueCommentBatch(): %v", err)
|
||||
return fmt.Errorf("mailIssueCommentBatch(): %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@@ -161,7 +161,7 @@ func (s *smtpSender) Send(from string, to []string, msg io.WriterTo) error {
|
||||
|
||||
conn, err := net.Dial(network, address)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to establish network connection to SMTP server: %v", err)
|
||||
return fmt.Errorf("failed to establish network connection to SMTP server: %w", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
@@ -175,7 +175,7 @@ func (s *smtpSender) Send(from string, to []string, msg io.WriterTo) error {
|
||||
if opts.UseClientCert {
|
||||
cert, err := tls.LoadX509KeyPair(opts.ClientCertFile, opts.ClientKeyFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not load SMTP client certificate: %v", err)
|
||||
return fmt.Errorf("could not load SMTP client certificate: %w", err)
|
||||
}
|
||||
tlsconfig.Certificates = []tls.Certificate{cert}
|
||||
}
|
||||
@@ -191,7 +191,7 @@ func (s *smtpSender) Send(from string, to []string, msg io.WriterTo) error {
|
||||
}
|
||||
client, err := smtp.NewClient(conn, host)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not initiate SMTP session: %v", err)
|
||||
return fmt.Errorf("could not initiate SMTP session: %w", err)
|
||||
}
|
||||
|
||||
if opts.EnableHelo {
|
||||
@@ -199,12 +199,12 @@ func (s *smtpSender) Send(from string, to []string, msg io.WriterTo) error {
|
||||
if len(hostname) == 0 {
|
||||
hostname, err = os.Hostname()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not retrieve system hostname: %v", err)
|
||||
return fmt.Errorf("could not retrieve system hostname: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if err = client.Hello(hostname); err != nil {
|
||||
return fmt.Errorf("failed to issue HELO command: %v", err)
|
||||
return fmt.Errorf("failed to issue HELO command: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ func (s *smtpSender) Send(from string, to []string, msg io.WriterTo) error {
|
||||
hasStartTLS, _ := client.Extension("STARTTLS")
|
||||
if hasStartTLS {
|
||||
if err = client.StartTLS(tlsconfig); err != nil {
|
||||
return fmt.Errorf("failed to start TLS connection: %v", err)
|
||||
return fmt.Errorf("failed to start TLS connection: %w", err)
|
||||
}
|
||||
} else {
|
||||
log.Warn("StartTLS requested, but SMTP server does not support it; falling back to regular SMTP")
|
||||
@@ -238,34 +238,34 @@ func (s *smtpSender) Send(from string, to []string, msg io.WriterTo) error {
|
||||
|
||||
if auth != nil {
|
||||
if err = client.Auth(auth); err != nil {
|
||||
return fmt.Errorf("failed to authenticate SMTP: %v", err)
|
||||
return fmt.Errorf("failed to authenticate SMTP: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if opts.OverrideEnvelopeFrom {
|
||||
if err = client.Mail(opts.EnvelopeFrom); err != nil {
|
||||
return fmt.Errorf("failed to issue MAIL command: %v", err)
|
||||
return fmt.Errorf("failed to issue MAIL command: %w", err)
|
||||
}
|
||||
} else {
|
||||
if err = client.Mail(from); err != nil {
|
||||
return fmt.Errorf("failed to issue MAIL command: %v", err)
|
||||
return fmt.Errorf("failed to issue MAIL command: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, rec := range to {
|
||||
if err = client.Rcpt(rec); err != nil {
|
||||
return fmt.Errorf("failed to issue RCPT command: %v", err)
|
||||
return fmt.Errorf("failed to issue RCPT command: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
w, err := client.Data()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to issue DATA command: %v", err)
|
||||
return fmt.Errorf("failed to issue DATA command: %w", err)
|
||||
} else if _, err = msg.WriteTo(w); err != nil {
|
||||
return fmt.Errorf("SMTP write failed: %v", err)
|
||||
return fmt.Errorf("SMTP write failed: %w", err)
|
||||
} else if err = w.Close(); err != nil {
|
||||
return fmt.Errorf("SMTP close failed: %v", err)
|
||||
return fmt.Errorf("SMTP close failed: %w", err)
|
||||
}
|
||||
|
||||
return client.Quit()
|
||||
|
@@ -157,7 +157,7 @@ func (g *RepositoryDumper) CreateRepo(repo *base.Repository, opts base.MigrateOp
|
||||
SkipTLSVerify: setting.Migrations.SkipTLSVerify,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Clone: %v", err)
|
||||
return fmt.Errorf("Clone: %w", err)
|
||||
}
|
||||
if err := git.WriteCommitGraph(g.ctx, repoPath); err != nil {
|
||||
return err
|
||||
@@ -168,7 +168,7 @@ func (g *RepositoryDumper) CreateRepo(repo *base.Repository, opts base.MigrateOp
|
||||
wikiRemotePath := repository.WikiRemoteURL(g.ctx, remoteAddr)
|
||||
if len(wikiRemotePath) > 0 {
|
||||
if err := os.MkdirAll(wikiPath, os.ModePerm); err != nil {
|
||||
return fmt.Errorf("Failed to remove %s: %v", wikiPath, err)
|
||||
return fmt.Errorf("Failed to remove %s: %w", wikiPath, err)
|
||||
}
|
||||
|
||||
if err := git.Clone(g.ctx, wikiRemotePath, wikiPath, git.CloneRepoOptions{
|
||||
@@ -180,7 +180,7 @@ func (g *RepositoryDumper) CreateRepo(repo *base.Repository, opts base.MigrateOp
|
||||
}); err != nil {
|
||||
log.Warn("Clone wiki: %v", err)
|
||||
if err := os.RemoveAll(wikiPath); err != nil {
|
||||
return fmt.Errorf("Failed to remove %s: %v", wikiPath, err)
|
||||
return fmt.Errorf("Failed to remove %s: %w", wikiPath, err)
|
||||
}
|
||||
} else if err := git.WriteCommitGraph(g.ctx, wikiPath); err != nil {
|
||||
return err
|
||||
|
@@ -408,7 +408,7 @@ func (g *GiteaDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, err
|
||||
Type: gitea_sdk.IssueTypeIssue,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("error while listing issues: %v", err)
|
||||
return nil, false, fmt.Errorf("error while listing issues: %w", err)
|
||||
}
|
||||
for _, issue := range issues {
|
||||
|
||||
@@ -476,7 +476,7 @@ func (g *GiteaDownloader) GetComments(commentable base.Commentable) ([]*base.Com
|
||||
Page: i,
|
||||
}})
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("error while listing comments for issue #%d. Error: %v", commentable.GetForeignIndex(), err)
|
||||
return nil, false, fmt.Errorf("error while listing comments for issue #%d. Error: %w", commentable.GetForeignIndex(), err)
|
||||
}
|
||||
|
||||
for _, comment := range comments {
|
||||
@@ -520,7 +520,7 @@ func (g *GiteaDownloader) GetPullRequests(page, perPage int) ([]*base.PullReques
|
||||
State: gitea_sdk.StateAll,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("error while listing pull requests (page: %d, pagesize: %d). Error: %v", page, perPage, err)
|
||||
return nil, false, fmt.Errorf("error while listing pull requests (page: %d, pagesize: %d). Error: %w", page, perPage, err)
|
||||
}
|
||||
for _, pr := range prs {
|
||||
var milestone string
|
||||
|
@@ -288,12 +288,12 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error {
|
||||
commit, err := g.gitRepo.GetTagCommit(rel.TagName)
|
||||
if !git.IsErrNotExist(err) {
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetTagCommit[%v]: %v", rel.TagName, err)
|
||||
return fmt.Errorf("GetTagCommit[%v]: %w", rel.TagName, err)
|
||||
}
|
||||
rel.Sha1 = commit.ID.String()
|
||||
rel.NumCommits, err = commit.CommitsCount()
|
||||
if err != nil {
|
||||
return fmt.Errorf("CommitsCount: %v", err)
|
||||
return fmt.Errorf("CommitsCount: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -427,7 +427,7 @@ func (g *GithubDownloaderV3) GetIssues(page, perPage int) ([]*base.Issue, bool,
|
||||
g.waitAndPickClient()
|
||||
issues, resp, err := g.getClient().Issues.ListByRepo(g.ctx, g.repoOwner, g.repoName, opt)
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("error while listing repos: %v", err)
|
||||
return nil, false, fmt.Errorf("error while listing repos: %w", err)
|
||||
}
|
||||
log.Trace("Request get issues %d/%d, but in fact get %d", perPage, page, len(issues))
|
||||
g.setRate(&resp.Rate)
|
||||
@@ -523,7 +523,7 @@ func (g *GithubDownloaderV3) getComments(commentable base.Commentable) ([]*base.
|
||||
g.waitAndPickClient()
|
||||
comments, resp, err := g.getClient().Issues.ListComments(g.ctx, g.repoOwner, g.repoName, int(commentable.GetForeignIndex()), opt)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error while listing repos: %v", err)
|
||||
return nil, fmt.Errorf("error while listing repos: %w", err)
|
||||
}
|
||||
g.setRate(&resp.Rate)
|
||||
for _, comment := range comments {
|
||||
@@ -595,7 +595,7 @@ func (g *GithubDownloaderV3) GetAllComments(page, perPage int) ([]*base.Comment,
|
||||
g.waitAndPickClient()
|
||||
comments, resp, err := g.getClient().Issues.ListComments(g.ctx, g.repoOwner, g.repoName, 0, opt)
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("error while listing repos: %v", err)
|
||||
return nil, false, fmt.Errorf("error while listing repos: %w", err)
|
||||
}
|
||||
isEnd := resp.NextPage == 0
|
||||
|
||||
@@ -663,7 +663,7 @@ func (g *GithubDownloaderV3) GetPullRequests(page, perPage int) ([]*base.PullReq
|
||||
g.waitAndPickClient()
|
||||
prs, resp, err := g.getClient().PullRequests.List(g.ctx, g.repoOwner, g.repoName, opt)
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("error while listing repos: %v", err)
|
||||
return nil, false, fmt.Errorf("error while listing repos: %w", err)
|
||||
}
|
||||
log.Trace("Request get pull requests %d/%d, but in fact get %d", perPage, page, len(prs))
|
||||
g.setRate(&resp.Rate)
|
||||
@@ -813,7 +813,7 @@ func (g *GithubDownloaderV3) GetReviews(reviewable base.Reviewable) ([]*base.Rev
|
||||
g.waitAndPickClient()
|
||||
reviews, resp, err := g.getClient().PullRequests.ListReviews(g.ctx, g.repoOwner, g.repoName, int(reviewable.GetForeignIndex()), opt)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error while listing repos: %v", err)
|
||||
return nil, fmt.Errorf("error while listing repos: %w", err)
|
||||
}
|
||||
g.setRate(&resp.Rate)
|
||||
for _, review := range reviews {
|
||||
@@ -827,7 +827,7 @@ func (g *GithubDownloaderV3) GetReviews(reviewable base.Reviewable) ([]*base.Rev
|
||||
g.waitAndPickClient()
|
||||
reviewComments, resp, err := g.getClient().PullRequests.ListReviewComments(g.ctx, g.repoOwner, g.repoName, int(reviewable.GetForeignIndex()), review.GetID(), opt2)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error while listing repos: %v", err)
|
||||
return nil, fmt.Errorf("error while listing repos: %w", err)
|
||||
}
|
||||
g.setRate(&resp.Rate)
|
||||
|
||||
@@ -853,7 +853,7 @@ func (g *GithubDownloaderV3) GetReviews(reviewable base.Reviewable) ([]*base.Rev
|
||||
g.waitAndPickClient()
|
||||
reviewers, resp, err := g.getClient().PullRequests.ListReviewers(g.ctx, g.repoOwner, g.repoName, int(reviewable.GetForeignIndex()), opt)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error while listing repos: %v", err)
|
||||
return nil, fmt.Errorf("error while listing repos: %w", err)
|
||||
}
|
||||
g.setRate(&resp.Rate)
|
||||
for _, user := range reviewers.Users {
|
||||
|
@@ -398,7 +398,7 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
|
||||
|
||||
issues, _, err := g.client.Issues.ListProjectIssues(g.repoID, opt, nil, gitlab.WithContext(g.ctx))
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("error while listing issues: %v", err)
|
||||
return nil, false, fmt.Errorf("error while listing issues: %w", err)
|
||||
}
|
||||
for _, issue := range issues {
|
||||
|
||||
@@ -419,7 +419,7 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
|
||||
for {
|
||||
awards, _, err := g.client.AwardEmoji.ListIssueAwardEmoji(g.repoID, issue.IID, &gitlab.ListAwardEmojiOptions{Page: awardPage, PerPage: perPage}, gitlab.WithContext(g.ctx))
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("error while listing issue awards: %v", err)
|
||||
return nil, false, fmt.Errorf("error while listing issue awards: %w", err)
|
||||
}
|
||||
|
||||
for i := range awards {
|
||||
@@ -487,7 +487,7 @@ func (g *GitlabDownloader) GetComments(commentable base.Commentable) ([]*base.Co
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("error while listing comments: %v %v", g.repoID, err)
|
||||
return nil, false, fmt.Errorf("error while listing comments: %v %w", g.repoID, err)
|
||||
}
|
||||
for _, comment := range comments {
|
||||
// Flatten comment threads
|
||||
@@ -541,7 +541,7 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
|
||||
|
||||
prs, _, err := g.client.MergeRequests.ListProjectMergeRequests(g.repoID, opt, nil, gitlab.WithContext(g.ctx))
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("error while listing merge requests: %v", err)
|
||||
return nil, false, fmt.Errorf("error while listing merge requests: %w", err)
|
||||
}
|
||||
for _, pr := range prs {
|
||||
|
||||
@@ -583,7 +583,7 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
|
||||
for {
|
||||
awards, _, err := g.client.AwardEmoji.ListMergeRequestAwardEmoji(g.repoID, pr.IID, &gitlab.ListAwardEmojiOptions{Page: awardPage, PerPage: perPage}, gitlab.WithContext(g.ctx))
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("error while listing merge requests awards: %v", err)
|
||||
return nil, false, fmt.Errorf("error while listing merge requests awards: %w", err)
|
||||
}
|
||||
|
||||
for i := range awards {
|
||||
|
@@ -223,7 +223,7 @@ func (g *GogsDownloader) getIssues(page int, state string) ([]*base.Issue, bool,
|
||||
State: state,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("error while listing repos: %v", err)
|
||||
return nil, false, fmt.Errorf("error while listing repos: %w", err)
|
||||
}
|
||||
|
||||
for _, issue := range issues {
|
||||
@@ -242,7 +242,7 @@ func (g *GogsDownloader) GetComments(commentable base.Commentable) ([]*base.Comm
|
||||
|
||||
comments, err := g.client.ListIssueComments(g.repoOwner, g.repoName, commentable.GetForeignIndex())
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("error while listing repos: %v", err)
|
||||
return nil, false, fmt.Errorf("error while listing repos: %w", err)
|
||||
}
|
||||
for _, comment := range comments {
|
||||
if len(comment.Body) == 0 || comment.Poster == nil {
|
||||
|
@@ -28,20 +28,20 @@ func DeleteOrganization(org *organization.Organization) error {
|
||||
// Check ownership of repository.
|
||||
count, err := repo_model.CountRepositories(ctx, repo_model.CountRepositoryOptions{OwnerID: org.ID})
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetRepositoryCount: %v", err)
|
||||
return fmt.Errorf("GetRepositoryCount: %w", err)
|
||||
} else if count > 0 {
|
||||
return models.ErrUserOwnRepos{UID: org.ID}
|
||||
}
|
||||
|
||||
// Check ownership of packages.
|
||||
if ownsPackages, err := packages_model.HasOwnerPackages(ctx, org.ID); err != nil {
|
||||
return fmt.Errorf("HasOwnerPackages: %v", err)
|
||||
return fmt.Errorf("HasOwnerPackages: %w", err)
|
||||
} else if ownsPackages {
|
||||
return models.ErrUserOwnPackages{UID: org.ID}
|
||||
}
|
||||
|
||||
if err := organization.DeleteOrganization(ctx, org); err != nil {
|
||||
return fmt.Errorf("DeleteOrganization: %v", err)
|
||||
return fmt.Errorf("DeleteOrganization: %w", err)
|
||||
}
|
||||
|
||||
if err := commiter.Commit(); err != nil {
|
||||
@@ -54,13 +54,13 @@ func DeleteOrganization(org *organization.Organization) error {
|
||||
path := user_model.UserPath(org.Name)
|
||||
|
||||
if err := util.RemoveAll(path); err != nil {
|
||||
return fmt.Errorf("Failed to RemoveAll %s: %v", path, err)
|
||||
return fmt.Errorf("Failed to RemoveAll %s: %w", path, err)
|
||||
}
|
||||
|
||||
if len(org.Avatar) > 0 {
|
||||
avatarPath := org.CustomAvatarRelativePath()
|
||||
if err := storage.Avatars.Delete(avatarPath); err != nil {
|
||||
return fmt.Errorf("Failed to remove %s: %v", avatarPath, err)
|
||||
return fmt.Errorf("Failed to remove %s: %w", avatarPath, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -168,13 +168,13 @@ func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Com
|
||||
var err error
|
||||
pr.BaseRepo, err = repo_model.GetRepositoryByID(pr.BaseRepoID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("GetRepositoryByID: %v", err)
|
||||
return nil, fmt.Errorf("GetRepositoryByID: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
indexTmpPath, err := os.MkdirTemp(os.TempDir(), "gitea-"+pr.BaseRepo.Name)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to create temp dir for repository %s: %v", pr.BaseRepo.RepoPath(), err)
|
||||
return nil, fmt.Errorf("Failed to create temp dir for repository %s: %w", pr.BaseRepo.RepoPath(), err)
|
||||
}
|
||||
defer func() {
|
||||
if err := util.RemoveAll(indexTmpPath); err != nil {
|
||||
@@ -192,12 +192,12 @@ func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Com
|
||||
if strings.Contains(err.Error(), "exit status 1") {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, fmt.Errorf("git merge-base --is-ancestor: %v", err)
|
||||
return nil, fmt.Errorf("git merge-base --is-ancestor: %w", err)
|
||||
}
|
||||
|
||||
commitIDBytes, err := os.ReadFile(pr.BaseRepo.RepoPath() + "/" + headFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ReadFile(%s): %v", headFile, err)
|
||||
return nil, fmt.Errorf("ReadFile(%s): %w", headFile, err)
|
||||
}
|
||||
commitID := string(commitIDBytes)
|
||||
if len(commitID) < 40 {
|
||||
@@ -209,7 +209,7 @@ func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Com
|
||||
mergeCommit, _, err := git.NewCommand(ctx, "rev-list", "--ancestry-path", "--merges", "--reverse").AddDynamicArguments(cmd).
|
||||
RunStdString(&git.RunOpts{Dir: "", Env: []string{"GIT_INDEX_FILE=" + indexTmpPath, "GIT_DIR=" + pr.BaseRepo.RepoPath()}})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("git rev-list --ancestry-path --merges --reverse: %v", err)
|
||||
return nil, fmt.Errorf("git rev-list --ancestry-path --merges --reverse: %w", err)
|
||||
} else if len(mergeCommit) < 40 {
|
||||
// PR was maybe fast-forwarded, so just use last commit of PR
|
||||
mergeCommit = commitID[:40]
|
||||
@@ -217,13 +217,13 @@ func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Com
|
||||
|
||||
gitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("OpenRepository: %v", err)
|
||||
return nil, fmt.Errorf("OpenRepository: %w", err)
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
commit, err := gitRepo.GetCommit(mergeCommit[:40])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("GetMergeCommit[%v]: %v", mergeCommit[:40], err)
|
||||
return nil, fmt.Errorf("GetMergeCommit[%v]: %w", mergeCommit[:40], err)
|
||||
}
|
||||
|
||||
return commit, nil
|
||||
|
@@ -136,10 +136,10 @@ func GetDefaultMergeMessage(baseGitRepo *git.Repository, pr *issues_model.PullRe
|
||||
func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.User, baseGitRepo *git.Repository, mergeStyle repo_model.MergeStyle, expectedHeadCommitID, message string) error {
|
||||
if err := pr.LoadHeadRepo(); err != nil {
|
||||
log.Error("LoadHeadRepo: %v", err)
|
||||
return fmt.Errorf("LoadHeadRepo: %v", err)
|
||||
return fmt.Errorf("LoadHeadRepo: %w", err)
|
||||
} else if err := pr.LoadBaseRepo(); err != nil {
|
||||
log.Error("LoadBaseRepo: %v", err)
|
||||
return fmt.Errorf("LoadBaseRepo: %v", err)
|
||||
return fmt.Errorf("LoadBaseRepo: %w", err)
|
||||
}
|
||||
|
||||
pullWorkingPool.CheckIn(fmt.Sprint(pr.ID))
|
||||
@@ -247,7 +247,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
|
||||
trackingCommitID, _, err := git.NewCommand(ctx, "show-ref", "--hash").AddDynamicArguments(git.BranchPrefix + trackingBranch).RunStdString(&git.RunOpts{Dir: tmpBasePath})
|
||||
if err != nil {
|
||||
log.Error("show-ref[%s] --hash refs/heads/trackingn: %v", tmpBasePath, git.BranchPrefix+trackingBranch, err)
|
||||
return "", fmt.Errorf("getDiffTree: %v", err)
|
||||
return "", fmt.Errorf("getDiffTree: %w", err)
|
||||
}
|
||||
if strings.TrimSpace(trackingCommitID) != expectedHeadCommitID {
|
||||
return "", models.ErrSHADoesNotMatch{
|
||||
@@ -263,19 +263,19 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
|
||||
sparseCheckoutList, err := getDiffTree(ctx, tmpBasePath, baseBranch, trackingBranch)
|
||||
if err != nil {
|
||||
log.Error("getDiffTree(%s, %s, %s): %v", tmpBasePath, baseBranch, trackingBranch, err)
|
||||
return "", fmt.Errorf("getDiffTree: %v", err)
|
||||
return "", fmt.Errorf("getDiffTree: %w", err)
|
||||
}
|
||||
|
||||
infoPath := filepath.Join(tmpBasePath, ".git", "info")
|
||||
if err := os.MkdirAll(infoPath, 0o700); err != nil {
|
||||
log.Error("Unable to create .git/info in %s: %v", tmpBasePath, err)
|
||||
return "", fmt.Errorf("Unable to create .git/info in tmpBasePath: %v", err)
|
||||
return "", fmt.Errorf("Unable to create .git/info in tmpBasePath: %w", err)
|
||||
}
|
||||
|
||||
sparseCheckoutListPath := filepath.Join(infoPath, "sparse-checkout")
|
||||
if err := os.WriteFile(sparseCheckoutListPath, []byte(sparseCheckoutList), 0o600); err != nil {
|
||||
log.Error("Unable to write .git/info/sparse-checkout file in %s: %v", tmpBasePath, err)
|
||||
return "", fmt.Errorf("Unable to write .git/info/sparse-checkout file in tmpBasePath: %v", err)
|
||||
return "", fmt.Errorf("Unable to write .git/info/sparse-checkout file in tmpBasePath: %w", err)
|
||||
}
|
||||
|
||||
gitConfigCommand := func() *git.Command {
|
||||
@@ -290,7 +290,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
|
||||
Stderr: &errbuf,
|
||||
}); err != nil {
|
||||
log.Error("git config [filter.lfs.process -> <> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git config [filter.lfs.process -> <> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git config [filter.lfs.process -> <> ]: %w\n%s\n%s", err, outbuf.String(), errbuf.String())
|
||||
}
|
||||
outbuf.Reset()
|
||||
errbuf.Reset()
|
||||
@@ -302,7 +302,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
|
||||
Stderr: &errbuf,
|
||||
}); err != nil {
|
||||
log.Error("git config [filter.lfs.required -> <false> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git config [filter.lfs.required -> <false> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git config [filter.lfs.required -> <false> ]: %w\n%s\n%s", err, outbuf.String(), errbuf.String())
|
||||
}
|
||||
outbuf.Reset()
|
||||
errbuf.Reset()
|
||||
@@ -314,7 +314,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
|
||||
Stderr: &errbuf,
|
||||
}); err != nil {
|
||||
log.Error("git config [filter.lfs.clean -> <> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git config [filter.lfs.clean -> <> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git config [filter.lfs.clean -> <> ]: %w\n%s\n%s", err, outbuf.String(), errbuf.String())
|
||||
}
|
||||
outbuf.Reset()
|
||||
errbuf.Reset()
|
||||
@@ -326,7 +326,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
|
||||
Stderr: &errbuf,
|
||||
}); err != nil {
|
||||
log.Error("git config [filter.lfs.smudge -> <> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git config [filter.lfs.smudge -> <> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git config [filter.lfs.smudge -> <> ]: %w\n%s\n%s", err, outbuf.String(), errbuf.String())
|
||||
}
|
||||
outbuf.Reset()
|
||||
errbuf.Reset()
|
||||
@@ -338,7 +338,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
|
||||
Stderr: &errbuf,
|
||||
}); err != nil {
|
||||
log.Error("git config [core.sparseCheckout -> true ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git config [core.sparsecheckout -> true]: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git config [core.sparsecheckout -> true]: %w\n%s\n%s", err, outbuf.String(), errbuf.String())
|
||||
}
|
||||
outbuf.Reset()
|
||||
errbuf.Reset()
|
||||
@@ -351,7 +351,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
|
||||
Stderr: &errbuf,
|
||||
}); err != nil {
|
||||
log.Error("git read-tree HEAD: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("Unable to read base branch in to the index: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("Unable to read base branch in to the index: %w\n%s\n%s", err, outbuf.String(), errbuf.String())
|
||||
}
|
||||
outbuf.Reset()
|
||||
errbuf.Reset()
|
||||
@@ -409,7 +409,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
|
||||
Stderr: &errbuf,
|
||||
}); err != nil {
|
||||
log.Error("git checkout base prior to merge post staging rebase [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git checkout base prior to merge post staging rebase [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git checkout base prior to merge post staging rebase [%s:%s -> %s:%s]: %w\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
}
|
||||
outbuf.Reset()
|
||||
errbuf.Reset()
|
||||
@@ -435,7 +435,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
|
||||
if readErr != nil {
|
||||
// Abandon this attempt to handle the error
|
||||
log.Error("git rebase staging on to base [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git rebase staging on to base [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git rebase staging on to base [%s:%s -> %s:%s]: %w\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
}
|
||||
commitSha = strings.TrimSpace(string(commitShaBytes))
|
||||
ok = true
|
||||
@@ -445,7 +445,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
|
||||
if !ok {
|
||||
log.Error("Unable to determine failing commit sha for this rebase message. Cannot cast as models.ErrRebaseConflicts.")
|
||||
log.Error("git rebase staging on to base [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git rebase staging on to base [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git rebase staging on to base [%s:%s -> %s:%s]: %w\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
}
|
||||
log.Debug("RebaseConflict at %s [%s:%s -> %s:%s]: %v\n%s\n%s", commitSha, pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
return "", models.ErrRebaseConflicts{
|
||||
@@ -457,7 +457,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
|
||||
}
|
||||
}
|
||||
log.Error("git rebase staging on to base [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git rebase staging on to base [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git rebase staging on to base [%s:%s -> %s:%s]: %w\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
}
|
||||
outbuf.Reset()
|
||||
errbuf.Reset()
|
||||
@@ -475,7 +475,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
|
||||
Stderr: &errbuf,
|
||||
}); err != nil {
|
||||
log.Error("git checkout base prior to merge post staging rebase [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git checkout base prior to merge post staging rebase [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git checkout base prior to merge post staging rebase [%s:%s -> %s:%s]: %w\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
}
|
||||
outbuf.Reset()
|
||||
errbuf.Reset()
|
||||
@@ -509,7 +509,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
|
||||
|
||||
if err = pr.Issue.LoadPoster(); err != nil {
|
||||
log.Error("LoadPoster: %v", err)
|
||||
return "", fmt.Errorf("LoadPoster: %v", err)
|
||||
return "", fmt.Errorf("LoadPoster: %w", err)
|
||||
}
|
||||
sig := pr.Issue.Poster.NewGitSig()
|
||||
if signArg == "" {
|
||||
@@ -521,7 +521,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
|
||||
Stderr: &errbuf,
|
||||
}); err != nil {
|
||||
log.Error("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git commit [%s:%s -> %s:%s]: %w\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
}
|
||||
} else {
|
||||
if setting.Repository.PullRequest.AddCoCommitterTrailers && committer.String() != sig.String() {
|
||||
@@ -539,7 +539,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
|
||||
Stderr: &errbuf,
|
||||
}); err != nil {
|
||||
log.Error("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("git commit [%s:%s -> %s:%s]: %w\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
}
|
||||
}
|
||||
outbuf.Reset()
|
||||
@@ -551,15 +551,15 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
|
||||
// OK we should cache our current head and origin/headbranch
|
||||
mergeHeadSHA, err := git.GetFullCommitID(ctx, tmpBasePath, "HEAD")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Failed to get full commit id for HEAD: %v", err)
|
||||
return "", fmt.Errorf("Failed to get full commit id for HEAD: %w", err)
|
||||
}
|
||||
mergeBaseSHA, err := git.GetFullCommitID(ctx, tmpBasePath, "original_"+baseBranch)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Failed to get full commit id for origin/%s: %v", pr.BaseBranch, err)
|
||||
return "", fmt.Errorf("Failed to get full commit id for origin/%s: %w", pr.BaseBranch, err)
|
||||
}
|
||||
mergeCommitID, err := git.GetFullCommitID(ctx, tmpBasePath, baseBranch)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Failed to get full commit id for the new merge: %v", err)
|
||||
return "", fmt.Errorf("Failed to get full commit id for the new merge: %w", err)
|
||||
}
|
||||
|
||||
// Now it's questionable about where this should go - either after or before the push
|
||||
@@ -643,7 +643,7 @@ func commitAndSignNoAuthor(ctx context.Context, pr *issues_model.PullRequest, me
|
||||
Stderr: &errbuf,
|
||||
}); err != nil {
|
||||
log.Error("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
return fmt.Errorf("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
return fmt.Errorf("git commit [%s:%s -> %s:%s]: %w\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
}
|
||||
} else {
|
||||
if err := git.NewCommand(ctx, "commit").AddArguments(signArg).AddArguments("-m").AddDynamicArguments(message).
|
||||
@@ -654,7 +654,7 @@ func commitAndSignNoAuthor(ctx context.Context, pr *issues_model.PullRequest, me
|
||||
Stderr: &errbuf,
|
||||
}); err != nil {
|
||||
log.Error("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
return fmt.Errorf("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
return fmt.Errorf("git commit [%s:%s -> %s:%s]: %w\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -687,7 +687,7 @@ func runMergeCommand(pr *issues_model.PullRequest, mergeStyle repo_model.MergeSt
|
||||
}
|
||||
}
|
||||
log.Error("git merge [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
return fmt.Errorf("git merge [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
return fmt.Errorf("git merge [%s:%s -> %s:%s]: %w\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -764,11 +764,11 @@ func IsUserAllowedToMerge(ctx context.Context, pr *issues_model.PullRequest, p a
|
||||
// CheckPullBranchProtections checks whether the PR is ready to be merged (reviews and status checks)
|
||||
func CheckPullBranchProtections(ctx context.Context, pr *issues_model.PullRequest, skipProtectedFilesCheck bool) (err error) {
|
||||
if err = pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
return fmt.Errorf("LoadBaseRepo: %v", err)
|
||||
return fmt.Errorf("LoadBaseRepo: %w", err)
|
||||
}
|
||||
|
||||
if err = pr.LoadProtectedBranchCtx(ctx); err != nil {
|
||||
return fmt.Errorf("LoadProtectedBranch: %v", err)
|
||||
return fmt.Errorf("LoadProtectedBranch: %w", err)
|
||||
}
|
||||
if pr.ProtectedBranch == nil {
|
||||
return nil
|
||||
|
@@ -37,13 +37,13 @@ func DownloadDiffOrPatch(ctx context.Context, pr *issues_model.PullRequest, w io
|
||||
|
||||
gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath())
|
||||
if err != nil {
|
||||
return fmt.Errorf("OpenRepository: %v", err)
|
||||
return fmt.Errorf("OpenRepository: %w", err)
|
||||
}
|
||||
defer closer.Close()
|
||||
|
||||
if err := gitRepo.GetDiffOrPatch(pr.MergeBase, pr.GetGitRefName(), w, patch, binary); err != nil {
|
||||
log.Error("Unable to get patch file from %s to %s in %s Error: %v", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err)
|
||||
return fmt.Errorf("Unable to get patch file from %s to %s in %s Error: %v", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err)
|
||||
return fmt.Errorf("Unable to get patch file from %s to %s in %s Error: %w", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -74,7 +74,7 @@ func TestPatch(pr *issues_model.PullRequest) error {
|
||||
|
||||
gitRepo, err := git.OpenRepository(ctx, tmpBasePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("OpenRepository: %v", err)
|
||||
return fmt.Errorf("OpenRepository: %w", err)
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
@@ -84,7 +84,7 @@ func TestPatch(pr *issues_model.PullRequest) error {
|
||||
var err2 error
|
||||
pr.MergeBase, err2 = gitRepo.GetRefCommitID(git.BranchPrefix + "base")
|
||||
if err2 != nil {
|
||||
return fmt.Errorf("GetMergeBase: %v and can't find commit ID for base: %v", err, err2)
|
||||
return fmt.Errorf("GetMergeBase: %v and can't find commit ID for base: %w", err, err2)
|
||||
}
|
||||
}
|
||||
pr.MergeBase = strings.TrimSpace(pr.MergeBase)
|
||||
@@ -104,7 +104,7 @@ func TestPatch(pr *issues_model.PullRequest) error {
|
||||
|
||||
// 3. Check for protected files changes
|
||||
if err = checkPullFilesProtection(pr, gitRepo); err != nil {
|
||||
return fmt.Errorf("pr.CheckPullFilesProtection(): %v", err)
|
||||
return fmt.Errorf("pr.CheckPullFilesProtection(): %w", err)
|
||||
}
|
||||
|
||||
if len(pr.ChangedProtectedFiles) > 0 {
|
||||
@@ -237,7 +237,7 @@ func AttemptThreeWayMerge(ctx context.Context, gitPath string, gitRepo *git.Repo
|
||||
// First we use read-tree to do a simple three-way merge
|
||||
if _, _, err := git.NewCommand(ctx, "read-tree", "-m").AddDynamicArguments(base, ours, theirs).RunStdString(&git.RunOpts{Dir: gitPath}); err != nil {
|
||||
log.Error("Unable to run read-tree -m! Error: %v", err)
|
||||
return false, nil, fmt.Errorf("unable to run read-tree -m! Error: %v", err)
|
||||
return false, nil, fmt.Errorf("unable to run read-tree -m! Error: %w", err)
|
||||
}
|
||||
|
||||
// Then we use git ls-files -u to list the unmerged files and collate the triples in unmergedfiles
|
||||
@@ -319,7 +319,7 @@ func checkConflicts(ctx context.Context, pr *issues_model.PullRequest, gitRepo *
|
||||
tmpPatchFile, err := os.CreateTemp("", "patch")
|
||||
if err != nil {
|
||||
log.Error("Unable to create temporary patch file! Error: %v", err)
|
||||
return false, fmt.Errorf("unable to create temporary patch file! Error: %v", err)
|
||||
return false, fmt.Errorf("unable to create temporary patch file! Error: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
_ = util.Remove(tmpPatchFile.Name())
|
||||
@@ -328,12 +328,12 @@ func checkConflicts(ctx context.Context, pr *issues_model.PullRequest, gitRepo *
|
||||
if err := gitRepo.GetDiffBinary(pr.MergeBase, "tracking", tmpPatchFile); err != nil {
|
||||
tmpPatchFile.Close()
|
||||
log.Error("Unable to get patch file from %s to %s in %s Error: %v", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err)
|
||||
return false, fmt.Errorf("unable to get patch file from %s to %s in %s Error: %v", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err)
|
||||
return false, fmt.Errorf("unable to get patch file from %s to %s in %s Error: %w", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err)
|
||||
}
|
||||
stat, err := tmpPatchFile.Stat()
|
||||
if err != nil {
|
||||
tmpPatchFile.Close()
|
||||
return false, fmt.Errorf("unable to stat patch file: %v", err)
|
||||
return false, fmt.Errorf("unable to stat patch file: %w", err)
|
||||
}
|
||||
patchPath := tmpPatchFile.Name()
|
||||
tmpPatchFile.Close()
|
||||
@@ -350,7 +350,7 @@ func checkConflicts(ctx context.Context, pr *issues_model.PullRequest, gitRepo *
|
||||
// 4. Read the base branch in to the index of the temporary repository
|
||||
_, _, err = git.NewCommand(gitRepo.Ctx, "read-tree", "base").RunStdString(&git.RunOpts{Dir: tmpBasePath})
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("git read-tree %s: %v", pr.BaseBranch, err)
|
||||
return false, fmt.Errorf("git read-tree %s: %w", pr.BaseBranch, err)
|
||||
}
|
||||
|
||||
// 5. Now get the pull request configuration to check if we need to ignore whitespace
|
||||
@@ -383,7 +383,7 @@ func checkConflicts(ctx context.Context, pr *issues_model.PullRequest, gitRepo *
|
||||
stderrReader, stderrWriter, err := os.Pipe()
|
||||
if err != nil {
|
||||
log.Error("Unable to open stderr pipe: %v", err)
|
||||
return false, fmt.Errorf("unable to open stderr pipe: %v", err)
|
||||
return false, fmt.Errorf("unable to open stderr pipe: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
_ = stderrReader.Close()
|
||||
@@ -467,7 +467,7 @@ func checkConflicts(ctx context.Context, pr *issues_model.PullRequest, gitRepo *
|
||||
return true, nil
|
||||
}
|
||||
} else if err != nil {
|
||||
return false, fmt.Errorf("git apply --check: %v", err)
|
||||
return false, fmt.Errorf("git apply --check: %w", err)
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
@@ -64,7 +64,7 @@ func readUnmergedLsFileLines(ctx context.Context, tmpBasePath string, outputChan
|
||||
lsFilesReader, lsFilesWriter, err := os.Pipe()
|
||||
if err != nil {
|
||||
log.Error("Unable to open stderr pipe: %v", err)
|
||||
outputChan <- &lsFileLine{err: fmt.Errorf("unable to open stderr pipe: %v", err)}
|
||||
outputChan <- &lsFileLine{err: fmt.Errorf("unable to open stderr pipe: %w", err)}
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
@@ -117,7 +117,7 @@ func readUnmergedLsFileLines(ctx context.Context, tmpBasePath string, outputChan
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
outputChan <- &lsFileLine{err: fmt.Errorf("git ls-files -u -z: %v", git.ConcatenateError(err, stderr.String()))}
|
||||
outputChan <- &lsFileLine{err: fmt.Errorf("git ls-files -u -z: %w", git.ConcatenateError(err, stderr.String()))}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ func unmergedFiles(ctx context.Context, tmpBasePath string, unmerged chan *unmer
|
||||
log.Trace("Got line: %v Current State:\n%v", line, next)
|
||||
if line.err != nil {
|
||||
log.Error("Unable to run ls-files -u -z! Error: %v", line.err)
|
||||
unmerged <- &unmergedFile{err: fmt.Errorf("unable to run ls-files -u -z! Error: %v", line.err)}
|
||||
unmerged <- &unmergedFile{err: fmt.Errorf("unable to run ls-files -u -z! Error: %w", line.err)}
|
||||
return
|
||||
}
|
||||
|
||||
|
@@ -224,7 +224,7 @@ func ChangeTargetBranch(ctx context.Context, pr *issues_model.PullRequest, doer
|
||||
NewRef: targetBranch,
|
||||
}
|
||||
if _, err = issues_model.CreateComment(options); err != nil {
|
||||
return fmt.Errorf("CreateChangeTargetBranchComment: %v", err)
|
||||
return fmt.Errorf("CreateChangeTargetBranchComment: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -233,11 +233,11 @@ func ChangeTargetBranch(ctx context.Context, pr *issues_model.PullRequest, doer
|
||||
func checkForInvalidation(ctx context.Context, requests issues_model.PullRequestList, repoID int64, doer *user_model.User, branch string) error {
|
||||
repo, err := repo_model.GetRepositoryByID(repoID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetRepositoryByID: %v", err)
|
||||
return fmt.Errorf("GetRepositoryByID: %w", err)
|
||||
}
|
||||
gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
|
||||
if err != nil {
|
||||
return fmt.Errorf("git.OpenRepository: %v", err)
|
||||
return fmt.Errorf("git.OpenRepository: %w", err)
|
||||
}
|
||||
go func() {
|
||||
// FIXME: graceful: We need to tell the manager we're doing something...
|
||||
@@ -353,26 +353,26 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
|
||||
// A commit can be considered to leave the PR untouched if the patch/diff with its merge base is unchanged
|
||||
func checkIfPRContentChanged(ctx context.Context, pr *issues_model.PullRequest, oldCommitID, newCommitID string) (hasChanged bool, err error) {
|
||||
if err = pr.LoadHeadRepoCtx(ctx); err != nil {
|
||||
return false, fmt.Errorf("LoadHeadRepo: %v", err)
|
||||
return false, fmt.Errorf("LoadHeadRepo: %w", err)
|
||||
} else if pr.HeadRepo == nil {
|
||||
// corrupt data assumed changed
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if err = pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
return false, fmt.Errorf("LoadBaseRepo: %v", err)
|
||||
return false, fmt.Errorf("LoadBaseRepo: %w", err)
|
||||
}
|
||||
|
||||
headGitRepo, err := git.OpenRepository(ctx, pr.HeadRepo.RepoPath())
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("OpenRepository: %v", err)
|
||||
return false, fmt.Errorf("OpenRepository: %w", err)
|
||||
}
|
||||
defer headGitRepo.Close()
|
||||
|
||||
// Add a temporary remote.
|
||||
tmpRemote := "checkIfPRContentChanged-" + fmt.Sprint(time.Now().UnixNano())
|
||||
if err = headGitRepo.AddRemote(tmpRemote, pr.BaseRepo.RepoPath(), true); err != nil {
|
||||
return false, fmt.Errorf("AddRemote: %s/%s-%s: %v", pr.HeadRepo.OwnerName, pr.HeadRepo.Name, tmpRemote, err)
|
||||
return false, fmt.Errorf("AddRemote: %s/%s-%s: %w", pr.HeadRepo.OwnerName, pr.HeadRepo.Name, tmpRemote, err)
|
||||
}
|
||||
defer func() {
|
||||
if err := headGitRepo.RemoveRemote(tmpRemote); err != nil {
|
||||
@@ -382,7 +382,7 @@ func checkIfPRContentChanged(ctx context.Context, pr *issues_model.PullRequest,
|
||||
// To synchronize repo and get a base ref
|
||||
_, base, err := headGitRepo.GetMergeBase(tmpRemote, pr.BaseBranch, pr.HeadBranch)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("GetMergeBase: %v", err)
|
||||
return false, fmt.Errorf("GetMergeBase: %w", err)
|
||||
}
|
||||
|
||||
diffBefore := &bytes.Buffer{}
|
||||
@@ -394,7 +394,7 @@ func checkIfPRContentChanged(ctx context.Context, pr *issues_model.PullRequest,
|
||||
}
|
||||
if err := headGitRepo.GetDiffFromMergeBase(base, newCommitID, diffAfter); err != nil {
|
||||
// New commit should be found
|
||||
return false, fmt.Errorf("GetDiffFromMergeBase: %v", err)
|
||||
return false, fmt.Errorf("GetDiffFromMergeBase: %w", err)
|
||||
}
|
||||
|
||||
diffBeforeLines := bufio.NewScanner(diffBefore)
|
||||
@@ -443,10 +443,10 @@ func pushToBaseRepoHelper(ctx context.Context, pr *issues_model.PullRequest, pre
|
||||
baseRepoPath := pr.BaseRepo.RepoPath()
|
||||
|
||||
if err = pr.LoadIssue(); err != nil {
|
||||
return fmt.Errorf("unable to load issue %d for pr %d: %v", pr.IssueID, pr.ID, err)
|
||||
return fmt.Errorf("unable to load issue %d for pr %d: %w", pr.IssueID, pr.ID, err)
|
||||
}
|
||||
if err = pr.Issue.LoadPoster(); err != nil {
|
||||
return fmt.Errorf("unable to load poster %d for pr %d: %v", pr.Issue.PosterID, pr.ID, err)
|
||||
return fmt.Errorf("unable to load poster %d for pr %d: %w", pr.Issue.PosterID, pr.ID, err)
|
||||
}
|
||||
|
||||
gitRefName := pr.GetGitRefName()
|
||||
@@ -476,7 +476,7 @@ func pushToBaseRepoHelper(ctx context.Context, pr *issues_model.PullRequest, pre
|
||||
return err
|
||||
}
|
||||
log.Error("Unable to push PR head for %s#%d (%-v:%s) due to Error: %v", pr.BaseRepo.FullName(), pr.Index, pr.BaseRepo, gitRefName, err)
|
||||
return fmt.Errorf("Push: %s:%s %s:%s %v", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), gitRefName, err)
|
||||
return fmt.Errorf("Push: %s:%s %s:%s %w", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), gitRefName, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@@ -120,15 +120,15 @@ var notEnoughLines = regexp.MustCompile(`exit status 128 - fatal: file .* has on
|
||||
func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, content, treePath string, line, reviewID int64) (*issues_model.Comment, error) {
|
||||
var commitID, patch string
|
||||
if err := issue.LoadPullRequest(); err != nil {
|
||||
return nil, fmt.Errorf("GetPullRequestByIssueID: %v", err)
|
||||
return nil, fmt.Errorf("GetPullRequestByIssueID: %w", err)
|
||||
}
|
||||
pr := issue.PullRequest
|
||||
if err := pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
return nil, fmt.Errorf("LoadHeadRepo: %v", err)
|
||||
return nil, fmt.Errorf("LoadHeadRepo: %w", err)
|
||||
}
|
||||
gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("RepositoryFromContextOrOpen: %v", err)
|
||||
return nil, fmt.Errorf("RepositoryFromContextOrOpen: %w", err)
|
||||
}
|
||||
defer closer.Close()
|
||||
|
||||
@@ -151,13 +151,13 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo
|
||||
invalidated = first[0].Invalidated
|
||||
patch = first[0].Patch
|
||||
} else if err != nil && !issues_model.IsErrCommentNotExist(err) {
|
||||
return nil, fmt.Errorf("Find first comment for %d line %d path %s. Error: %v", reviewID, line, treePath, err)
|
||||
return nil, fmt.Errorf("Find first comment for %d line %d path %s. Error: %w", reviewID, line, treePath, err)
|
||||
} else {
|
||||
review, err := issues_model.GetReviewByID(ctx, reviewID)
|
||||
if err == nil && len(review.CommitID) > 0 {
|
||||
head = review.CommitID
|
||||
} else if err != nil && !issues_model.IsErrReviewNotExist(err) {
|
||||
return nil, fmt.Errorf("GetReviewByID %d. Error: %v", reviewID, err)
|
||||
return nil, fmt.Errorf("GetReviewByID %d. Error: %w", reviewID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -170,7 +170,7 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo
|
||||
if err == nil {
|
||||
commitID = commit.ID.String()
|
||||
} else if !(strings.Contains(err.Error(), "exit status 128 - fatal: no such path") || notEnoughLines.MatchString(err.Error())) {
|
||||
return nil, fmt.Errorf("LineBlame[%s, %s, %s, %d]: %v", pr.GetGitRefName(), gitRepo.Path, treePath, line, err)
|
||||
return nil, fmt.Errorf("LineBlame[%s, %s, %s, %d]: %w", pr.GetGitRefName(), gitRepo.Path, treePath, line, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -179,7 +179,7 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo
|
||||
if len(patch) == 0 && reviewID != 0 {
|
||||
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("GetRefCommitID[%s]: %v", pr.GetGitRefName(), err)
|
||||
return nil, fmt.Errorf("GetRefCommitID[%s]: %w", pr.GetGitRefName(), err)
|
||||
}
|
||||
if len(commitID) == 0 {
|
||||
commitID = headCommitID
|
||||
@@ -191,7 +191,7 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo
|
||||
}()
|
||||
go func() {
|
||||
if err := git.GetRepoRawDiffForFile(gitRepo, pr.MergeBase, headCommitID, git.RawDiffNormal, treePath, writer); err != nil {
|
||||
_ = writer.CloseWithError(fmt.Errorf("GetRawDiffForLine[%s, %s, %s, %s]: %v", gitRepo.Path, pr.MergeBase, headCommitID, treePath, err))
|
||||
_ = writer.CloseWithError(fmt.Errorf("GetRawDiffForLine[%s, %s, %s, %s]: %w", gitRepo.Path, pr.MergeBase, headCommitID, treePath, err))
|
||||
return
|
||||
}
|
||||
_ = writer.Close()
|
||||
|
@@ -25,7 +25,7 @@ import (
|
||||
func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (string, error) {
|
||||
if err := pr.LoadHeadRepoCtx(ctx); err != nil {
|
||||
log.Error("LoadHeadRepo: %v", err)
|
||||
return "", fmt.Errorf("LoadHeadRepo: %v", err)
|
||||
return "", fmt.Errorf("LoadHeadRepo: %w", err)
|
||||
} else if pr.HeadRepo == nil {
|
||||
log.Error("Pr %d HeadRepo %d does not exist", pr.ID, pr.HeadRepoID)
|
||||
return "", &repo_model.ErrRepoNotExist{
|
||||
@@ -33,7 +33,7 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str
|
||||
}
|
||||
} else if err := pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
log.Error("LoadBaseRepo: %v", err)
|
||||
return "", fmt.Errorf("LoadBaseRepo: %v", err)
|
||||
return "", fmt.Errorf("LoadBaseRepo: %w", err)
|
||||
} else if pr.BaseRepo == nil {
|
||||
log.Error("Pr %d BaseRepo %d does not exist", pr.ID, pr.BaseRepoID)
|
||||
return "", &repo_model.ErrRepoNotExist{
|
||||
@@ -41,10 +41,10 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str
|
||||
}
|
||||
} else if err := pr.HeadRepo.GetOwner(ctx); err != nil {
|
||||
log.Error("HeadRepo.GetOwner: %v", err)
|
||||
return "", fmt.Errorf("HeadRepo.GetOwner: %v", err)
|
||||
return "", fmt.Errorf("HeadRepo.GetOwner: %w", err)
|
||||
} else if err := pr.BaseRepo.GetOwner(ctx); err != nil {
|
||||
log.Error("BaseRepo.GetOwner: %v", err)
|
||||
return "", fmt.Errorf("BaseRepo.GetOwner: %v", err)
|
||||
return "", fmt.Errorf("BaseRepo.GetOwner: %w", err)
|
||||
}
|
||||
|
||||
// Clone base repo.
|
||||
@@ -90,7 +90,7 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str
|
||||
if err := repo_module.RemoveTemporaryPath(tmpBasePath); err != nil {
|
||||
log.Error("CreateTempRepo: RemoveTemporaryPath: %s", err)
|
||||
}
|
||||
return "", fmt.Errorf("Unable to add base repository to temporary repo [%s -> tmpBasePath]: %v", pr.BaseRepo.FullName(), err)
|
||||
return "", fmt.Errorf("Unable to add base repository to temporary repo [%s -> tmpBasePath]: %w", pr.BaseRepo.FullName(), err)
|
||||
}
|
||||
|
||||
var outbuf, errbuf strings.Builder
|
||||
@@ -104,7 +104,7 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str
|
||||
if err := repo_module.RemoveTemporaryPath(tmpBasePath); err != nil {
|
||||
log.Error("CreateTempRepo: RemoveTemporaryPath: %s", err)
|
||||
}
|
||||
return "", fmt.Errorf("Unable to add base repository as origin [%s -> tmpBasePath]: %v\n%s\n%s", pr.BaseRepo.FullName(), err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("Unable to add base repository as origin [%s -> tmpBasePath]: %w\n%s\n%s", pr.BaseRepo.FullName(), err, outbuf.String(), errbuf.String())
|
||||
}
|
||||
outbuf.Reset()
|
||||
errbuf.Reset()
|
||||
@@ -119,7 +119,7 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str
|
||||
if err := repo_module.RemoveTemporaryPath(tmpBasePath); err != nil {
|
||||
log.Error("CreateTempRepo: RemoveTemporaryPath: %s", err)
|
||||
}
|
||||
return "", fmt.Errorf("Unable to fetch origin base branch [%s:%s -> base, original_base in tmpBasePath]: %v\n%s\n%s", pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("Unable to fetch origin base branch [%s:%s -> base, original_base in tmpBasePath]: %w\n%s\n%s", pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
|
||||
}
|
||||
outbuf.Reset()
|
||||
errbuf.Reset()
|
||||
@@ -134,7 +134,7 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str
|
||||
if err := repo_module.RemoveTemporaryPath(tmpBasePath); err != nil {
|
||||
log.Error("CreateTempRepo: RemoveTemporaryPath: %s", err)
|
||||
}
|
||||
return "", fmt.Errorf("Unable to set HEAD as base branch [tmpBasePath]: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("Unable to set HEAD as base branch [tmpBasePath]: %w\n%s\n%s", err, outbuf.String(), errbuf.String())
|
||||
}
|
||||
outbuf.Reset()
|
||||
errbuf.Reset()
|
||||
@@ -144,7 +144,7 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str
|
||||
if err := repo_module.RemoveTemporaryPath(tmpBasePath); err != nil {
|
||||
log.Error("CreateTempRepo: RemoveTemporaryPath: %s", err)
|
||||
}
|
||||
return "", fmt.Errorf("Unable to head base repository to temporary repo [%s -> tmpBasePath]: %v", pr.HeadRepo.FullName(), err)
|
||||
return "", fmt.Errorf("Unable to head base repository to temporary repo [%s -> tmpBasePath]: %w", pr.HeadRepo.FullName(), err)
|
||||
}
|
||||
|
||||
if err := git.NewCommand(ctx, "remote", "add").AddDynamicArguments(remoteRepoName, headRepoPath).
|
||||
@@ -157,7 +157,7 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str
|
||||
if err := repo_module.RemoveTemporaryPath(tmpBasePath); err != nil {
|
||||
log.Error("CreateTempRepo: RemoveTemporaryPath: %s", err)
|
||||
}
|
||||
return "", fmt.Errorf("Unable to add head repository as head_repo [%s -> tmpBasePath]: %v\n%s\n%s", pr.HeadRepo.FullName(), err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("Unable to add head repository as head_repo [%s -> tmpBasePath]: %w\n%s\n%s", pr.HeadRepo.FullName(), err, outbuf.String(), errbuf.String())
|
||||
}
|
||||
outbuf.Reset()
|
||||
errbuf.Reset()
|
||||
@@ -187,7 +187,7 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str
|
||||
}
|
||||
}
|
||||
log.Error("Unable to fetch head_repo head branch [%s:%s -> tracking in %s]: %v:\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, tmpBasePath, err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("Unable to fetch head_repo head branch [%s:%s -> tracking in tmpBasePath]: %v\n%s\n%s", pr.HeadRepo.FullName(), headBranch, err, outbuf.String(), errbuf.String())
|
||||
return "", fmt.Errorf("Unable to fetch head_repo head branch [%s:%s -> tracking in tmpBasePath]: %w\n%s\n%s", pr.HeadRepo.FullName(), headBranch, err, outbuf.String(), errbuf.String())
|
||||
}
|
||||
outbuf.Reset()
|
||||
errbuf.Reset()
|
||||
|
@@ -50,10 +50,10 @@ func Update(ctx context.Context, pull *issues_model.PullRequest, doer *user_mode
|
||||
|
||||
if err := pr.LoadHeadRepoCtx(ctx); err != nil {
|
||||
log.Error("LoadHeadRepo: %v", err)
|
||||
return fmt.Errorf("LoadHeadRepo: %v", err)
|
||||
return fmt.Errorf("LoadHeadRepo: %w", err)
|
||||
} else if err = pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
log.Error("LoadBaseRepo: %v", err)
|
||||
return fmt.Errorf("LoadBaseRepo: %v", err)
|
||||
return fmt.Errorf("LoadBaseRepo: %w", err)
|
||||
}
|
||||
|
||||
diffCount, err := GetDiverging(ctx, pull)
|
||||
|
@@ -36,7 +36,7 @@ func createTag(gitRepo *git.Repository, rel *repo_model.Release, msg string) (bo
|
||||
|
||||
protectedTags, err := git_model.GetProtectedTags(rel.Repo.ID)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("GetProtectedTags: %v", err)
|
||||
return false, fmt.Errorf("GetProtectedTags: %w", err)
|
||||
}
|
||||
|
||||
// Trim '--' prefix to prevent command line argument vulnerability.
|
||||
@@ -53,7 +53,7 @@ func createTag(gitRepo *git.Repository, rel *repo_model.Release, msg string) (bo
|
||||
|
||||
commit, err := gitRepo.GetCommit(rel.Target)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("createTag::GetCommit[%v]: %v", rel.Target, err)
|
||||
return false, fmt.Errorf("createTag::GetCommit[%v]: %w", rel.Target, err)
|
||||
}
|
||||
|
||||
if len(msg) > 0 {
|
||||
@@ -92,13 +92,13 @@ func createTag(gitRepo *git.Repository, rel *repo_model.Release, msg string) (bo
|
||||
}
|
||||
commit, err := gitRepo.GetTagCommit(rel.TagName)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("GetTagCommit: %v", err)
|
||||
return false, fmt.Errorf("GetTagCommit: %w", err)
|
||||
}
|
||||
|
||||
rel.Sha1 = commit.ID.String()
|
||||
rel.NumCommits, err = commit.CommitsCount()
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("CommitsCount: %v", err)
|
||||
return false, fmt.Errorf("CommitsCount: %w", err)
|
||||
}
|
||||
|
||||
if rel.PublisherID <= 0 {
|
||||
@@ -207,7 +207,7 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod
|
||||
}
|
||||
|
||||
if err = repo_model.AddReleaseAttachments(ctx, rel.ID, addAttachmentUUIDs); err != nil {
|
||||
return fmt.Errorf("AddReleaseAttachments: %v", err)
|
||||
return fmt.Errorf("AddReleaseAttachments: %w", err)
|
||||
}
|
||||
|
||||
deletedUUIDs := make(container.Set[string])
|
||||
@@ -215,7 +215,7 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod
|
||||
// Check attachments
|
||||
attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, delAttachmentUUIDs)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetAttachmentsByUUIDs [uuids: %v]: %v", delAttachmentUUIDs, err)
|
||||
return fmt.Errorf("GetAttachmentsByUUIDs [uuids: %v]: %w", delAttachmentUUIDs, err)
|
||||
}
|
||||
for _, attach := range attachments {
|
||||
if attach.ReleaseID != rel.ID {
|
||||
@@ -225,7 +225,7 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod
|
||||
}
|
||||
|
||||
if _, err := repo_model.DeleteAttachments(ctx, attachments, false); err != nil {
|
||||
return fmt.Errorf("DeleteAttachments [uuids: %v]: %v", delAttachmentUUIDs, err)
|
||||
return fmt.Errorf("DeleteAttachments [uuids: %v]: %w", delAttachmentUUIDs, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod
|
||||
// Check attachments
|
||||
attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, updateAttachmentsList)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetAttachmentsByUUIDs [uuids: %v]: %v", updateAttachmentsList, err)
|
||||
return fmt.Errorf("GetAttachmentsByUUIDs [uuids: %v]: %w", updateAttachmentsList, err)
|
||||
}
|
||||
for _, attach := range attachments {
|
||||
if attach.ReleaseID != rel.ID {
|
||||
@@ -286,18 +286,18 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod
|
||||
func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, delTag bool) error {
|
||||
rel, err := repo_model.GetReleaseByID(ctx, id)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetReleaseByID: %v", err)
|
||||
return fmt.Errorf("GetReleaseByID: %w", err)
|
||||
}
|
||||
|
||||
repo, err := repo_model.GetRepositoryByIDCtx(ctx, rel.RepoID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetRepositoryByID: %v", err)
|
||||
return fmt.Errorf("GetRepositoryByID: %w", err)
|
||||
}
|
||||
|
||||
if delTag {
|
||||
protectedTags, err := git_model.GetProtectedTags(rel.RepoID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetProtectedTags: %v", err)
|
||||
return fmt.Errorf("GetProtectedTags: %w", err)
|
||||
}
|
||||
isAllowed, err := git_model.IsUserAllowedToControlTag(protectedTags, rel.TagName, rel.PublisherID)
|
||||
if err != nil {
|
||||
@@ -313,7 +313,7 @@ func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, del
|
||||
SetDescription(fmt.Sprintf("DeleteReleaseByID (git tag -d): %d", rel.ID)).
|
||||
RunStdString(&git.RunOpts{Dir: repo.RepoPath()}); err != nil && !strings.Contains(err.Error(), "not found") {
|
||||
log.Error("DeleteReleaseByID (git tag -d): %d in %v Failed:\nStdout: %s\nError: %v", rel.ID, repo, stdout, err)
|
||||
return fmt.Errorf("git tag -d: %v", err)
|
||||
return fmt.Errorf("git tag -d: %w", err)
|
||||
}
|
||||
|
||||
notification.NotifyPushCommits(
|
||||
@@ -326,23 +326,23 @@ func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, del
|
||||
notification.NotifyDeleteRef(doer, repo, "tag", git.TagPrefix+rel.TagName)
|
||||
|
||||
if err := repo_model.DeleteReleaseByID(id); err != nil {
|
||||
return fmt.Errorf("DeleteReleaseByID: %v", err)
|
||||
return fmt.Errorf("DeleteReleaseByID: %w", err)
|
||||
}
|
||||
} else {
|
||||
rel.IsTag = true
|
||||
|
||||
if err = repo_model.UpdateRelease(ctx, rel); err != nil {
|
||||
return fmt.Errorf("Update: %v", err)
|
||||
return fmt.Errorf("Update: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
rel.Repo = repo
|
||||
if err = rel.LoadAttributes(); err != nil {
|
||||
return fmt.Errorf("LoadAttributes: %v", err)
|
||||
return fmt.Errorf("LoadAttributes: %w", err)
|
||||
}
|
||||
|
||||
if err := repo_model.DeleteAttachmentsByRelease(rel.ID); err != nil {
|
||||
return fmt.Errorf("DeleteAttachments: %v", err)
|
||||
return fmt.Errorf("DeleteAttachments: %w", err)
|
||||
}
|
||||
|
||||
for i := range rel.Attachments {
|
||||
|
@@ -71,16 +71,16 @@ func AdoptRepository(doer, u *user_model.User, opts repo_module.CreateRepoOption
|
||||
return err
|
||||
}
|
||||
if err := adoptRepository(ctx, repoPath, doer, repo, opts); err != nil {
|
||||
return fmt.Errorf("createDelegateHooks: %v", err)
|
||||
return fmt.Errorf("createDelegateHooks: %w", err)
|
||||
}
|
||||
if err := repo_module.CheckDaemonExportOK(ctx, repo); err != nil {
|
||||
return fmt.Errorf("checkDaemonExportOK: %v", err)
|
||||
return fmt.Errorf("checkDaemonExportOK: %w", err)
|
||||
}
|
||||
|
||||
// Initialize Issue Labels if selected
|
||||
if len(opts.IssueLabels) > 0 {
|
||||
if err := repo_module.InitializeLabels(ctx, repo.ID, opts.IssueLabels, false); err != nil {
|
||||
return fmt.Errorf("InitializeLabels: %v", err)
|
||||
return fmt.Errorf("InitializeLabels: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ func AdoptRepository(doer, u *user_model.User, opts repo_module.CreateRepoOption
|
||||
SetDescription(fmt.Sprintf("CreateRepository(git update-server-info): %s", repoPath)).
|
||||
RunStdString(&git.RunOpts{Dir: 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 fmt.Errorf("CreateRepository(git update-server-info): %w", err)
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
@@ -111,13 +111,13 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r
|
||||
}
|
||||
|
||||
if err := repo_module.CreateDelegateHooks(repoPath); err != nil {
|
||||
return fmt.Errorf("createDelegateHooks: %v", err)
|
||||
return fmt.Errorf("createDelegateHooks: %w", err)
|
||||
}
|
||||
|
||||
// Re-fetch the repository from database before updating it (else it would
|
||||
// override changes that were done earlier with sql)
|
||||
if repo, err = repo_model.GetRepositoryByIDCtx(ctx, repo.ID); err != nil {
|
||||
return fmt.Errorf("getRepositoryByID: %v", err)
|
||||
return fmt.Errorf("getRepositoryByID: %w", err)
|
||||
}
|
||||
|
||||
repo.IsEmpty = false
|
||||
@@ -125,7 +125,7 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r
|
||||
// Don't bother looking this repo in the context it won't be there
|
||||
gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
|
||||
if err != nil {
|
||||
return fmt.Errorf("openRepository: %v", err)
|
||||
return fmt.Errorf("openRepository: %w", err)
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
@@ -133,14 +133,14 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r
|
||||
repo.DefaultBranch = opts.DefaultBranch
|
||||
|
||||
if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil {
|
||||
return fmt.Errorf("setDefaultBranch: %v", err)
|
||||
return fmt.Errorf("setDefaultBranch: %w", err)
|
||||
}
|
||||
} else {
|
||||
repo.DefaultBranch, err = gitRepo.GetDefaultBranch()
|
||||
if err != nil {
|
||||
repo.DefaultBranch = setting.Repository.DefaultBranch
|
||||
if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil {
|
||||
return fmt.Errorf("setDefaultBranch: %v", err)
|
||||
return fmt.Errorf("setDefaultBranch: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -176,12 +176,12 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r
|
||||
}
|
||||
|
||||
if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil {
|
||||
return fmt.Errorf("setDefaultBranch: %v", err)
|
||||
return fmt.Errorf("setDefaultBranch: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if err = repo_module.UpdateRepository(ctx, repo, false); err != nil {
|
||||
return fmt.Errorf("updateRepository: %v", err)
|
||||
return fmt.Errorf("updateRepository: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@@ -139,7 +139,7 @@ func (aReq *ArchiveRequest) GetArchiveName() string {
|
||||
func (aReq *ArchiveRequest) Await(ctx context.Context) (*repo_model.RepoArchiver, error) {
|
||||
archiver, err := repo_model.GetRepoArchiver(ctx, aReq.RepoID, aReq.Type, aReq.CommitID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("models.GetRepoArchiver: %v", err)
|
||||
return nil, fmt.Errorf("models.GetRepoArchiver: %w", err)
|
||||
}
|
||||
|
||||
if archiver != nil && archiver.Status == repo_model.ArchiverReady {
|
||||
@@ -148,7 +148,7 @@ func (aReq *ArchiveRequest) Await(ctx context.Context) (*repo_model.RepoArchiver
|
||||
}
|
||||
|
||||
if err := StartArchive(aReq); err != nil {
|
||||
return nil, fmt.Errorf("archiver.StartArchive: %v", err)
|
||||
return nil, fmt.Errorf("archiver.StartArchive: %w", err)
|
||||
}
|
||||
|
||||
poll := time.NewTicker(time.Second * 1)
|
||||
@@ -164,7 +164,7 @@ func (aReq *ArchiveRequest) Await(ctx context.Context) (*repo_model.RepoArchiver
|
||||
case <-poll.C:
|
||||
archiver, err = repo_model.GetRepoArchiver(ctx, aReq.RepoID, aReq.Type, aReq.CommitID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("repo_model.GetRepoArchiver: %v", err)
|
||||
return nil, fmt.Errorf("repo_model.GetRepoArchiver: %w", err)
|
||||
}
|
||||
if archiver != nil && archiver.Status == repo_model.ArchiverReady {
|
||||
return archiver, nil
|
||||
@@ -218,7 +218,7 @@ func doArchive(r *ArchiveRequest) (*repo_model.RepoArchiver, error) {
|
||||
}
|
||||
|
||||
if !errors.Is(err, os.ErrNotExist) {
|
||||
return nil, fmt.Errorf("unable to stat archive: %v", err)
|
||||
return nil, fmt.Errorf("unable to stat archive: %w", err)
|
||||
}
|
||||
|
||||
rd, w := io.Pipe()
|
||||
@@ -229,7 +229,7 @@ func doArchive(r *ArchiveRequest) (*repo_model.RepoArchiver, error) {
|
||||
done := make(chan error, 1) // Ensure that there is some capacity which will ensure that the goroutine below can always finish
|
||||
repo, err := repo_model.GetRepositoryByID(archiver.RepoID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("archiver.LoadRepo failed: %v", err)
|
||||
return nil, fmt.Errorf("archiver.LoadRepo failed: %w", err)
|
||||
}
|
||||
|
||||
gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
|
||||
@@ -268,7 +268,7 @@ func doArchive(r *ArchiveRequest) (*repo_model.RepoArchiver, error) {
|
||||
// TODO: add submodule data to zip
|
||||
|
||||
if _, err := storage.RepoArchives.Save(rPath, rd, -1); err != nil {
|
||||
return nil, fmt.Errorf("unable to write archive: %v", err)
|
||||
return nil, fmt.Errorf("unable to write archive: %w", err)
|
||||
}
|
||||
|
||||
err = <-done
|
||||
|
@@ -45,7 +45,7 @@ func UploadAvatar(repo *repo_model.Repository, data []byte) error {
|
||||
// Then repo will be removed - only it avatar file will be removed
|
||||
repo.Avatar = newAvatar
|
||||
if err := repo_model.UpdateRepositoryCols(ctx, repo, "avatar"); err != nil {
|
||||
return fmt.Errorf("UploadAvatar: Update repository avatar: %v", err)
|
||||
return fmt.Errorf("UploadAvatar: Update repository avatar: %w", err)
|
||||
}
|
||||
|
||||
if err := storage.SaveFrom(storage.RepoAvatars, repo.CustomAvatarRelativePath(), func(w io.Writer) error {
|
||||
@@ -54,12 +54,12 @@ func UploadAvatar(repo *repo_model.Repository, data []byte) error {
|
||||
}
|
||||
return err
|
||||
}); err != nil {
|
||||
return fmt.Errorf("UploadAvatar %s failed: Failed to remove old repo avatar %s: %v", repo.RepoPath(), newAvatar, err)
|
||||
return fmt.Errorf("UploadAvatar %s failed: Failed to remove old repo avatar %s: %w", repo.RepoPath(), newAvatar, err)
|
||||
}
|
||||
|
||||
if len(oldAvatarPath) > 0 {
|
||||
if err := storage.RepoAvatars.Delete(oldAvatarPath); err != nil {
|
||||
return fmt.Errorf("UploadAvatar: Failed to remove old repo avatar %s: %v", oldAvatarPath, err)
|
||||
return fmt.Errorf("UploadAvatar: Failed to remove old repo avatar %s: %w", oldAvatarPath, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,11 +84,11 @@ func DeleteAvatar(repo *repo_model.Repository) error {
|
||||
|
||||
repo.Avatar = ""
|
||||
if err := repo_model.UpdateRepositoryCols(ctx, repo, "avatar"); err != nil {
|
||||
return fmt.Errorf("DeleteAvatar: Update repository avatar: %v", err)
|
||||
return fmt.Errorf("DeleteAvatar: Update repository avatar: %w", err)
|
||||
}
|
||||
|
||||
if err := storage.RepoAvatars.Delete(avatarPath); err != nil {
|
||||
return fmt.Errorf("DeleteAvatar: Failed to remove %s: %v", avatarPath, err)
|
||||
return fmt.Errorf("DeleteAvatar: Failed to remove %s: %w", avatarPath, err)
|
||||
}
|
||||
|
||||
return committer.Commit()
|
||||
|
@@ -42,7 +42,7 @@ func CreateNewBranch(ctx context.Context, doer *user_model.User, repo *repo_mode
|
||||
if git.IsErrPushOutOfDate(err) || git.IsErrPushRejected(err) {
|
||||
return err
|
||||
}
|
||||
return fmt.Errorf("Push: %v", err)
|
||||
return fmt.Errorf("Push: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -99,7 +99,7 @@ func CreateNewBranchFromCommit(ctx context.Context, doer *user_model.User, repo
|
||||
if git.IsErrPushOutOfDate(err) || git.IsErrPushRejected(err) {
|
||||
return err
|
||||
}
|
||||
return fmt.Errorf("Push: %v", err)
|
||||
return fmt.Errorf("Push: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@@ -86,7 +86,7 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...git.CmdArg)
|
||||
if err = system_model.CreateRepositoryNotice(desc); err != nil {
|
||||
log.Error("CreateRepositoryNotice: %v", err)
|
||||
}
|
||||
return fmt.Errorf("Repository garbage collection failed in repo: %s: Error: %v", repo.FullName(), err)
|
||||
return fmt.Errorf("Repository garbage collection failed in repo: %s: Error: %w", repo.FullName(), err)
|
||||
}
|
||||
|
||||
// Now update the size of the repository
|
||||
@@ -96,7 +96,7 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...git.CmdArg)
|
||||
if err = system_model.CreateRepositoryNotice(desc); err != nil {
|
||||
log.Error("CreateRepositoryNotice: %v", err)
|
||||
}
|
||||
return fmt.Errorf("Updating size as part of garbage collection failed in repo: %s: Error: %v", repo.FullName(), err)
|
||||
return fmt.Errorf("Updating size as part of garbage collection failed in repo: %s: Error: %w", repo.FullName(), err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@@ -51,7 +51,7 @@ func CherryPick(ctx context.Context, repo *repo_model.Repository, doer *user_mod
|
||||
} else {
|
||||
lastCommitID, err := t.gitRepo.ConvertToSHA1(opts.LastCommitID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("CherryPick: Invalid last commit ID: %v", err)
|
||||
return nil, fmt.Errorf("CherryPick: Invalid last commit ID: %w", err)
|
||||
}
|
||||
opts.LastCommitID = lastCommitID.String()
|
||||
if commit.ID.String() != opts.LastCommitID {
|
||||
@@ -81,7 +81,7 @@ func CherryPick(ctx context.Context, repo *repo_model.Repository, doer *user_mod
|
||||
conflict, _, err := pull.AttemptThreeWayMerge(ctx,
|
||||
t.basePath, t.gitRepo, base, opts.LastCommitID, right, description)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to three-way merge %s onto %s: %v", right, opts.OldBranch, err)
|
||||
return nil, fmt.Errorf("failed to three-way merge %s onto %s: %w", right, opts.OldBranch, err)
|
||||
}
|
||||
|
||||
if conflict {
|
||||
|
@@ -26,13 +26,13 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato
|
||||
// confirm that commit is exist
|
||||
gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath())
|
||||
if err != nil {
|
||||
return fmt.Errorf("OpenRepository[%s]: %v", repoPath, err)
|
||||
return fmt.Errorf("OpenRepository[%s]: %w", repoPath, err)
|
||||
}
|
||||
defer closer.Close()
|
||||
|
||||
if _, err := gitRepo.GetCommit(sha); err != nil {
|
||||
gitRepo.Close()
|
||||
return fmt.Errorf("GetCommit[%s]: %v", sha, err)
|
||||
return fmt.Errorf("GetCommit[%s]: %w", sha, err)
|
||||
}
|
||||
gitRepo.Close()
|
||||
|
||||
@@ -42,7 +42,7 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato
|
||||
SHA: sha,
|
||||
CommitStatus: status,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("NewCommitStatus[repo_id: %d, user_id: %d, sha: %s]: %v", repo.ID, creator.ID, sha, err)
|
||||
return fmt.Errorf("NewCommitStatus[repo_id: %d, user_id: %d, sha: %s]: %w", repo.ID, creator.ID, sha, err)
|
||||
}
|
||||
|
||||
if status.State.IsSuccess() {
|
||||
|
@@ -104,7 +104,7 @@ func DeleteRepoFile(ctx context.Context, repo *repo_model.Repository, doer *user
|
||||
} else {
|
||||
lastCommitID, err := t.gitRepo.ConvertToSHA1(opts.LastCommitID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("DeleteRepoFile: Invalid last commit ID: %v", err)
|
||||
return nil, fmt.Errorf("DeleteRepoFile: Invalid last commit ID: %w", err)
|
||||
}
|
||||
opts.LastCommitID = lastCommitID.String()
|
||||
}
|
||||
@@ -112,7 +112,7 @@ func DeleteRepoFile(ctx context.Context, repo *repo_model.Repository, doer *user
|
||||
// Get the files in the index
|
||||
filesInIndex, err := t.LsFiles(opts.TreePath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("DeleteRepoFile: %v", err)
|
||||
return nil, fmt.Errorf("DeleteRepoFile: %w", err)
|
||||
}
|
||||
|
||||
// Find the file we want to delete in the index
|
||||
|
@@ -125,7 +125,7 @@ func ApplyDiffPatch(ctx context.Context, repo *repo_model.Repository, doer *user
|
||||
} else {
|
||||
lastCommitID, err := t.gitRepo.ConvertToSHA1(opts.LastCommitID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ApplyPatch: Invalid last commit ID: %v", err)
|
||||
return nil, fmt.Errorf("ApplyPatch: Invalid last commit ID: %w", err)
|
||||
}
|
||||
opts.LastCommitID = lastCommitID.String()
|
||||
if commit.ID.String() != opts.LastCommitID {
|
||||
@@ -152,7 +152,7 @@ func ApplyDiffPatch(ctx context.Context, repo *repo_model.Repository, doer *user
|
||||
Stderr: stderr,
|
||||
Stdin: strings.NewReader(opts.Content),
|
||||
}); err != nil {
|
||||
return nil, fmt.Errorf("Error: Stdout: %s\nStderr: %s\nErr: %v", stdout.String(), stderr.String(), err)
|
||||
return nil, fmt.Errorf("Error: Stdout: %s\nStderr: %s\nErr: %w", stdout.String(), stderr.String(), err)
|
||||
}
|
||||
|
||||
// Now write the tree
|
||||
|
@@ -67,7 +67,7 @@ func (t *TemporaryUploadRepository) Clone(branch string) error {
|
||||
Name: t.repo.Name,
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("Clone: %v %s", err, stderr)
|
||||
return fmt.Errorf("Clone: %w %s", err, stderr)
|
||||
}
|
||||
}
|
||||
gitRepo, err := git.OpenRepository(t.ctx, t.basePath)
|
||||
@@ -94,7 +94,7 @@ func (t *TemporaryUploadRepository) Init() error {
|
||||
// SetDefaultIndex sets the git index to our HEAD
|
||||
func (t *TemporaryUploadRepository) SetDefaultIndex() error {
|
||||
if _, _, err := git.NewCommand(t.ctx, "read-tree", "HEAD").RunStdString(&git.RunOpts{Dir: t.basePath}); err != nil {
|
||||
return fmt.Errorf("SetDefaultIndex: %v", err)
|
||||
return fmt.Errorf("SetDefaultIndex: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -111,7 +111,7 @@ func (t *TemporaryUploadRepository) LsFiles(filenames ...string) ([]string, erro
|
||||
Stderr: stdErr,
|
||||
}); err != nil {
|
||||
log.Error("Unable to run git ls-files for temporary repo: %s (%s) Error: %v\nstdout: %s\nstderr: %s", t.repo.FullName(), t.basePath, err, stdOut.String(), stdErr.String())
|
||||
err = fmt.Errorf("Unable to run git ls-files for temporary repo of: %s Error: %v\nstdout: %s\nstderr: %s", t.repo.FullName(), err, stdOut.String(), stdErr.String())
|
||||
err = fmt.Errorf("Unable to run git ls-files for temporary repo of: %s Error: %w\nstdout: %s\nstderr: %s", t.repo.FullName(), err, stdOut.String(), stdErr.String())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ func (t *TemporaryUploadRepository) RemoveFilesFromIndex(filenames ...string) er
|
||||
Stderr: stdErr,
|
||||
}); err != nil {
|
||||
log.Error("Unable to update-index for temporary repo: %s (%s) Error: %v\nstdout: %s\nstderr: %s", t.repo.FullName(), t.basePath, err, stdOut.String(), stdErr.String())
|
||||
return fmt.Errorf("Unable to update-index for temporary repo: %s Error: %v\nstdout: %s\nstderr: %s", t.repo.FullName(), err, stdOut.String(), stdErr.String())
|
||||
return fmt.Errorf("Unable to update-index for temporary repo: %s Error: %w\nstdout: %s\nstderr: %s", t.repo.FullName(), err, stdOut.String(), stdErr.String())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -162,7 +162,7 @@ func (t *TemporaryUploadRepository) HashObject(content io.Reader) (string, error
|
||||
Stderr: stdErr,
|
||||
}); err != nil {
|
||||
log.Error("Unable to hash-object to temporary repo: %s (%s) Error: %v\nstdout: %s\nstderr: %s", t.repo.FullName(), t.basePath, err, stdOut.String(), stdErr.String())
|
||||
return "", fmt.Errorf("Unable to hash-object to temporary repo: %s Error: %v\nstdout: %s\nstderr: %s", t.repo.FullName(), err, stdOut.String(), stdErr.String())
|
||||
return "", fmt.Errorf("Unable to hash-object to temporary repo: %s Error: %w\nstdout: %s\nstderr: %s", t.repo.FullName(), err, stdOut.String(), stdErr.String())
|
||||
}
|
||||
|
||||
return strings.TrimSpace(stdOut.String()), nil
|
||||
@@ -179,7 +179,7 @@ func (t *TemporaryUploadRepository) AddObjectToIndex(mode, objectHash, objectPat
|
||||
}
|
||||
}
|
||||
log.Error("Unable to add object to index: %s %s %s in temporary repo %s(%s) Error: %v", mode, objectHash, objectPath, t.repo.FullName(), t.basePath, err)
|
||||
return fmt.Errorf("Unable to add object to index at %s in temporary repo %s Error: %v", objectPath, t.repo.FullName(), err)
|
||||
return fmt.Errorf("Unable to add object to index at %s in temporary repo %s Error: %w", objectPath, t.repo.FullName(), err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -189,7 +189,7 @@ func (t *TemporaryUploadRepository) WriteTree() (string, error) {
|
||||
stdout, _, err := git.NewCommand(t.ctx, "write-tree").RunStdString(&git.RunOpts{Dir: t.basePath})
|
||||
if err != nil {
|
||||
log.Error("Unable to write tree in temporary repo: %s(%s): Error: %v", t.repo.FullName(), t.basePath, err)
|
||||
return "", fmt.Errorf("Unable to write-tree in temporary repo for: %s Error: %v", t.repo.FullName(), err)
|
||||
return "", fmt.Errorf("Unable to write-tree in temporary repo for: %s Error: %w", t.repo.FullName(), err)
|
||||
}
|
||||
return strings.TrimSpace(stdout), nil
|
||||
}
|
||||
@@ -207,7 +207,7 @@ func (t *TemporaryUploadRepository) GetLastCommitByRef(ref string) (string, erro
|
||||
stdout, _, err := git.NewCommand(t.ctx, "rev-parse").AddDynamicArguments(ref).RunStdString(&git.RunOpts{Dir: t.basePath})
|
||||
if err != nil {
|
||||
log.Error("Unable to get last ref for %s in temporary repo: %s(%s): Error: %v", ref, t.repo.FullName(), t.basePath, err)
|
||||
return "", fmt.Errorf("Unable to rev-parse %s in temporary repo for: %s Error: %v", ref, t.repo.FullName(), err)
|
||||
return "", fmt.Errorf("Unable to rev-parse %s in temporary repo for: %s Error: %w", ref, t.repo.FullName(), err)
|
||||
}
|
||||
return strings.TrimSpace(stdout), nil
|
||||
}
|
||||
@@ -292,7 +292,7 @@ func (t *TemporaryUploadRepository) CommitTreeWithDate(parent string, author, co
|
||||
}); err != nil {
|
||||
log.Error("Unable to commit-tree in temporary repo: %s (%s) Error: %v\nStdout: %s\nStderr: %s",
|
||||
t.repo.FullName(), t.basePath, err, stdout, stderr)
|
||||
return "", fmt.Errorf("Unable to commit-tree in temporary repo: %s Error: %v\nStdout: %s\nStderr: %s",
|
||||
return "", fmt.Errorf("Unable to commit-tree in temporary repo: %s Error: %w\nStdout: %s\nStderr: %s",
|
||||
t.repo.FullName(), err, stdout, stderr)
|
||||
}
|
||||
return strings.TrimSpace(stdout.String()), nil
|
||||
@@ -328,7 +328,7 @@ func (t *TemporaryUploadRepository) DiffIndex() (*gitdiff.Diff, error) {
|
||||
stdoutReader, stdoutWriter, err := os.Pipe()
|
||||
if err != nil {
|
||||
log.Error("Unable to open stdout pipe: %v", err)
|
||||
return nil, fmt.Errorf("Unable to open stdout pipe: %v", err)
|
||||
return nil, fmt.Errorf("Unable to open stdout pipe: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
_ = stdoutReader.Close()
|
||||
@@ -361,7 +361,7 @@ func (t *TemporaryUploadRepository) DiffIndex() (*gitdiff.Diff, error) {
|
||||
}
|
||||
log.Error("Unable to run diff-index pipeline in temporary repo %s (%s). Error: %v\nStderr: %s",
|
||||
t.repo.FullName(), t.basePath, err, stderr)
|
||||
return nil, fmt.Errorf("Unable to run diff-index pipeline in temporary repo %s. Error: %v\nStderr: %s",
|
||||
return nil, fmt.Errorf("Unable to run diff-index pipeline in temporary repo %s. Error: %w\nStderr: %s",
|
||||
t.repo.FullName(), err, stderr)
|
||||
}
|
||||
|
||||
|
@@ -226,7 +226,7 @@ func CreateOrUpdateRepoFile(ctx context.Context, repo *repo_model.Repository, do
|
||||
} else {
|
||||
lastCommitID, err := t.gitRepo.ConvertToSHA1(opts.LastCommitID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ConvertToSHA1: Invalid last commit ID: %v", err)
|
||||
return nil, fmt.Errorf("ConvertToSHA1: Invalid last commit ID: %w", err)
|
||||
}
|
||||
opts.LastCommitID = lastCommitID.String()
|
||||
|
||||
@@ -321,7 +321,7 @@ func CreateOrUpdateRepoFile(ctx context.Context, repo *repo_model.Repository, do
|
||||
// Get the two paths (might be the same if not moving) from the index if they exist
|
||||
filesInIndex, err := t.LsFiles(opts.TreePath, opts.FromTreePath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("UpdateRepoFile: %v", err)
|
||||
return nil, fmt.Errorf("UpdateRepoFile: %w", err)
|
||||
}
|
||||
// If is a new file (not updating) then the given path shouldn't exist
|
||||
if opts.IsNewFile {
|
||||
@@ -436,7 +436,7 @@ func CreateOrUpdateRepoFile(ctx context.Context, repo *repo_model.Repository, do
|
||||
if !exist {
|
||||
if err := contentStore.Put(lfsMetaObject.Pointer, strings.NewReader(opts.Content)); err != nil {
|
||||
if _, err2 := git_model.RemoveLFSMetaObjectByOid(repo.ID, lfsMetaObject.Oid); err2 != nil {
|
||||
return nil, fmt.Errorf("Error whilst removing failed inserted LFS object %s: %v (Prev Error: %v)", lfsMetaObject.Oid, err2, err)
|
||||
return nil, fmt.Errorf("Error whilst removing failed inserted LFS object %s: %v (Prev Error: %w)", lfsMetaObject.Oid, err2, err)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -42,7 +42,7 @@ func cleanUpAfterFailure(infos *[]uploadInfo, t *TemporaryUploadRepository, orig
|
||||
}
|
||||
if !info.lfsMetaObject.Existing {
|
||||
if _, err := git_model.RemoveLFSMetaObjectByOid(t.repo.ID, info.lfsMetaObject.Oid); err != nil {
|
||||
original = fmt.Errorf("%v, %v", original, err)
|
||||
original = fmt.Errorf("%w, %v", original, err) // We wrap the original error - as this is the underlying error that required the fallback
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ func UploadRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use
|
||||
|
||||
uploads, err := repo_model.GetUploadsByUUIDs(opts.Files)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetUploadsByUUIDs [uuids: %v]: %v", opts.Files, err)
|
||||
return fmt.Errorf("GetUploadsByUUIDs [uuids: %v]: %w", opts.Files, err)
|
||||
}
|
||||
|
||||
names := make([]string, len(uploads))
|
||||
|
@@ -134,22 +134,22 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
|
||||
SetDescription(fmt.Sprintf("ForkRepository(git clone): %s to %s", opts.BaseRepo.FullName(), repo.FullName())).
|
||||
RunStdBytes(&git.RunOpts{Timeout: 10 * time.Minute}); err != nil {
|
||||
log.Error("Fork Repository (git clone) Failed for %v (from %v):\nStdout: %s\nError: %v", repo, opts.BaseRepo, stdout, err)
|
||||
return fmt.Errorf("git clone: %v", err)
|
||||
return fmt.Errorf("git clone: %w", err)
|
||||
}
|
||||
|
||||
if err := repo_module.CheckDaemonExportOK(txCtx, repo); err != nil {
|
||||
return fmt.Errorf("checkDaemonExportOK: %v", err)
|
||||
return fmt.Errorf("checkDaemonExportOK: %w", err)
|
||||
}
|
||||
|
||||
if stdout, _, err := git.NewCommand(txCtx, "update-server-info").
|
||||
SetDescription(fmt.Sprintf("ForkRepository(git update-server-info): %s", repo.FullName())).
|
||||
RunStdString(&git.RunOpts{Dir: repoPath}); err != nil {
|
||||
log.Error("Fork Repository (git update-server-info) failed for %v:\nStdout: %s\nError: %v", repo, stdout, err)
|
||||
return fmt.Errorf("git update-server-info: %v", err)
|
||||
return fmt.Errorf("git update-server-info: %w", err)
|
||||
}
|
||||
|
||||
if err = repo_module.CreateDelegateHooks(repoPath); err != nil {
|
||||
return fmt.Errorf("createDelegateHooks: %v", err)
|
||||
return fmt.Errorf("createDelegateHooks: %w", err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
@@ -36,11 +36,11 @@ func SyncRepositoryHooks(ctx context.Context) error {
|
||||
}
|
||||
|
||||
if err := repo_module.CreateDelegateHooks(repo.RepoPath()); err != nil {
|
||||
return fmt.Errorf("SyncRepositoryHook: %v", err)
|
||||
return fmt.Errorf("SyncRepositoryHook: %w", err)
|
||||
}
|
||||
if repo.HasWiki() {
|
||||
if err := repo_module.CreateDelegateHooks(repo.WikiPath()); err != nil {
|
||||
return fmt.Errorf("SyncRepositoryHook: %v", err)
|
||||
return fmt.Errorf("SyncRepositoryHook: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@@ -84,14 +84,14 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
|
||||
repo, err := repo_model.GetRepositoryByOwnerAndName(optsList[0].RepoUserName, optsList[0].RepoName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetRepositoryByOwnerAndName failed: %v", err)
|
||||
return fmt.Errorf("GetRepositoryByOwnerAndName failed: %w", err)
|
||||
}
|
||||
|
||||
repoPath := repo.RepoPath()
|
||||
|
||||
gitRepo, err := git.OpenRepository(ctx, repoPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("OpenRepository[%s]: %v", repoPath, err)
|
||||
return fmt.Errorf("OpenRepository[%s]: %w", repoPath, err)
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
@@ -129,7 +129,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
} else { // is new tag
|
||||
newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("gitRepo.GetCommit: %v", err)
|
||||
return fmt.Errorf("gitRepo.GetCommit: %w", err)
|
||||
}
|
||||
|
||||
commits := repo_module.NewPushCommits()
|
||||
@@ -162,7 +162,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
|
||||
newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("gitRepo.GetCommit: %v", err)
|
||||
return fmt.Errorf("gitRepo.GetCommit: %w", err)
|
||||
}
|
||||
|
||||
refName := opts.RefName()
|
||||
@@ -182,19 +182,19 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
}
|
||||
// Update the is empty and default_branch columns
|
||||
if err := repo_model.UpdateRepositoryCols(db.DefaultContext, repo, "default_branch", "is_empty"); err != nil {
|
||||
return fmt.Errorf("UpdateRepositoryCols: %v", err)
|
||||
return fmt.Errorf("UpdateRepositoryCols: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
l, err = newCommit.CommitsBeforeLimit(10)
|
||||
if err != nil {
|
||||
return fmt.Errorf("newCommit.CommitsBeforeLimit: %v", err)
|
||||
return fmt.Errorf("newCommit.CommitsBeforeLimit: %w", err)
|
||||
}
|
||||
notification.NotifyCreateRef(pusher, repo, "branch", opts.RefFullName, opts.NewCommitID)
|
||||
} else {
|
||||
l, err = newCommit.CommitsBeforeUntil(opts.OldCommitID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("newCommit.CommitsBeforeUntil: %v", err)
|
||||
return fmt.Errorf("newCommit.CommitsBeforeUntil: %w", err)
|
||||
}
|
||||
|
||||
isForce, err := repo_module.IsForcePush(ctx, opts)
|
||||
@@ -277,12 +277,12 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
}
|
||||
}
|
||||
if err := PushUpdateAddDeleteTags(repo, gitRepo, addTags, delTags); err != nil {
|
||||
return fmt.Errorf("PushUpdateAddDeleteTags: %v", err)
|
||||
return fmt.Errorf("PushUpdateAddDeleteTags: %w", err)
|
||||
}
|
||||
|
||||
// Change repository last updated time.
|
||||
if err := repo_model.UpdateRepositoryUpdatedTime(repo.ID, time.Now()); err != nil {
|
||||
return fmt.Errorf("UpdateRepositoryUpdatedTime: %v", err)
|
||||
return fmt.Errorf("UpdateRepositoryUpdatedTime: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -311,7 +311,7 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo
|
||||
|
||||
releases, err := repo_model.GetReleasesByRepoIDAndNames(ctx, repo.ID, lowerTags)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetReleasesByRepoIDAndNames: %v", err)
|
||||
return fmt.Errorf("GetReleasesByRepoIDAndNames: %w", err)
|
||||
}
|
||||
relMap := make(map[string]*repo_model.Release)
|
||||
for _, rel := range releases {
|
||||
@@ -325,11 +325,11 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo
|
||||
for i, lowerTag := range lowerTags {
|
||||
tag, err := gitRepo.GetTag(tags[i])
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetTag: %v", err)
|
||||
return fmt.Errorf("GetTag: %w", err)
|
||||
}
|
||||
commit, err := tag.Commit(gitRepo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Commit: %v", err)
|
||||
return fmt.Errorf("Commit: %w", err)
|
||||
}
|
||||
|
||||
sig := tag.Tagger
|
||||
@@ -348,7 +348,7 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo
|
||||
if !ok {
|
||||
author, err = user_model.GetUserByEmailContext(ctx, sig.Email)
|
||||
if err != nil && !user_model.IsErrUserNotExist(err) {
|
||||
return fmt.Errorf("GetUserByEmail: %v", err)
|
||||
return fmt.Errorf("GetUserByEmail: %w", err)
|
||||
}
|
||||
if author != nil {
|
||||
emailToUser[sig.Email] = author
|
||||
@@ -359,7 +359,7 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo
|
||||
|
||||
commitsCount, err := commit.CommitsCount()
|
||||
if err != nil {
|
||||
return fmt.Errorf("CommitsCount: %v", err)
|
||||
return fmt.Errorf("CommitsCount: %w", err)
|
||||
}
|
||||
|
||||
rel, has := relMap[lowerTag]
|
||||
@@ -393,14 +393,14 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo
|
||||
rel.PublisherID = author.ID
|
||||
}
|
||||
if err = repo_model.UpdateRelease(ctx, rel); err != nil {
|
||||
return fmt.Errorf("Update: %v", err)
|
||||
return fmt.Errorf("Update: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(newReleases) > 0 {
|
||||
if err = db.Insert(ctx, newReleases); err != nil {
|
||||
return fmt.Errorf("Insert: %v", err)
|
||||
return fmt.Errorf("Insert: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -97,7 +97,7 @@ func UpdateRepository(repo *repo_model.Repository, visibilityChanged bool) (err
|
||||
defer committer.Close()
|
||||
|
||||
if err = repo_module.UpdateRepository(ctx, repo, visibilityChanged); err != nil {
|
||||
return fmt.Errorf("updateRepository: %v", err)
|
||||
return fmt.Errorf("updateRepository: %w", err)
|
||||
}
|
||||
|
||||
return committer.Commit()
|
||||
|
@@ -133,9 +133,9 @@ func runMigrateTask(t *admin_model.Task) (err error) {
|
||||
err = util.SanitizeErrorCredentialURLs(err)
|
||||
if strings.Contains(err.Error(), "Authentication failed") ||
|
||||
strings.Contains(err.Error(), "could not read Username") {
|
||||
return fmt.Errorf("Authentication failed: %v", err.Error())
|
||||
return fmt.Errorf("Authentication failed: %w", err)
|
||||
} else if strings.Contains(err.Error(), "fatal:") {
|
||||
return fmt.Errorf("Migration failed: %v", err.Error())
|
||||
return fmt.Errorf("Migration failed: %w", err)
|
||||
}
|
||||
|
||||
// do not be tempted to coalesce this line with the return
|
||||
|
@@ -78,14 +78,14 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error {
|
||||
Actor: u,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("SearchRepositoryByName: %v", err)
|
||||
return fmt.Errorf("SearchRepositoryByName: %w", err)
|
||||
}
|
||||
if len(repos) == 0 {
|
||||
break
|
||||
}
|
||||
for _, repo := range repos {
|
||||
if err := models.DeleteRepository(u, u.ID, repo.ID); err != nil {
|
||||
return fmt.Errorf("unable to delete repository %s for %s[%d]. Error: %v", repo.Name, u.Name, u.ID, err)
|
||||
return fmt.Errorf("unable to delete repository %s for %s[%d]. Error: %w", repo.Name, u.Name, u.ID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,7 +107,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error {
|
||||
IncludePrivate: true,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to find org list for %s[%d]. Error: %v", u.Name, u.ID, err)
|
||||
return fmt.Errorf("unable to find org list for %s[%d]. Error: %w", u.Name, u.ID, err)
|
||||
}
|
||||
if len(orgs) == 0 {
|
||||
break
|
||||
@@ -118,7 +118,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error {
|
||||
err = organization.DeleteOrganization(ctx, org)
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to remove user %s[%d] from org %s[%d]. Error: %v", u.Name, u.ID, org.Name, org.ID, err)
|
||||
return fmt.Errorf("unable to remove user %s[%d] from org %s[%d]. Error: %w", u.Name, u.ID, org.Name, org.ID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,7 +145,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error {
|
||||
// Check ownership of repository.
|
||||
count, err := repo_model.CountRepositories(ctx, repo_model.CountRepositoryOptions{OwnerID: u.ID})
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetRepositoryCount: %v", err)
|
||||
return fmt.Errorf("GetRepositoryCount: %w", err)
|
||||
} else if count > 0 {
|
||||
return models.ErrUserOwnRepos{UID: u.ID}
|
||||
}
|
||||
@@ -153,20 +153,20 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error {
|
||||
// Check membership of organization.
|
||||
count, err = organization.GetOrganizationCount(ctx, u)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetOrganizationCount: %v", err)
|
||||
return fmt.Errorf("GetOrganizationCount: %w", err)
|
||||
} else if count > 0 {
|
||||
return models.ErrUserHasOrgs{UID: u.ID}
|
||||
}
|
||||
|
||||
// Check ownership of packages.
|
||||
if ownsPackages, err := packages_model.HasOwnerPackages(ctx, u.ID); err != nil {
|
||||
return fmt.Errorf("HasOwnerPackages: %v", err)
|
||||
return fmt.Errorf("HasOwnerPackages: %w", err)
|
||||
} else if ownsPackages {
|
||||
return models.ErrUserOwnPackages{UID: u.ID}
|
||||
}
|
||||
|
||||
if err := models.DeleteUser(ctx, u, purge); err != nil {
|
||||
return fmt.Errorf("DeleteUser: %v", err)
|
||||
return fmt.Errorf("DeleteUser: %w", err)
|
||||
}
|
||||
|
||||
if err := committer.Commit(); err != nil {
|
||||
@@ -185,7 +185,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error {
|
||||
// so just keep error logs of those operations.
|
||||
path := user_model.UserPath(u.Name)
|
||||
if err := util.RemoveAll(path); err != nil {
|
||||
err = fmt.Errorf("Failed to RemoveAll %s: %v", path, err)
|
||||
err = fmt.Errorf("Failed to RemoveAll %s: %w", path, err)
|
||||
_ = system_model.CreateNotice(ctx, system_model.NoticeTask, fmt.Sprintf("delete user '%s': %v", u.Name, err))
|
||||
return err
|
||||
}
|
||||
@@ -193,7 +193,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error {
|
||||
if u.Avatar != "" {
|
||||
avatarPath := u.CustomAvatarRelativePath()
|
||||
if err := storage.Avatars.Delete(avatarPath); err != nil {
|
||||
err = fmt.Errorf("Failed to remove %s: %v", avatarPath, err)
|
||||
err = fmt.Errorf("Failed to remove %s: %w", avatarPath, err)
|
||||
_ = system_model.CreateNotice(ctx, system_model.NoticeTask, fmt.Sprintf("delete user '%s': %v", u.Name, err))
|
||||
return err
|
||||
}
|
||||
@@ -248,7 +248,7 @@ func UploadAvatar(u *user_model.User, data []byte) error {
|
||||
// Other users will lose their avatars too.
|
||||
u.Avatar = fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%d-%x", u.ID, md5.Sum(data)))))
|
||||
if err = user_model.UpdateUserCols(ctx, u, "use_custom_avatar", "avatar"); err != nil {
|
||||
return fmt.Errorf("updateUser: %v", err)
|
||||
return fmt.Errorf("updateUser: %w", err)
|
||||
}
|
||||
|
||||
if err := storage.SaveFrom(storage.Avatars, u.CustomAvatarRelativePath(), func(w io.Writer) error {
|
||||
@@ -257,7 +257,7 @@ func UploadAvatar(u *user_model.User, data []byte) error {
|
||||
}
|
||||
return err
|
||||
}); err != nil {
|
||||
return fmt.Errorf("Failed to create dir %s: %v", u.CustomAvatarRelativePath(), err)
|
||||
return fmt.Errorf("Failed to create dir %s: %w", u.CustomAvatarRelativePath(), err)
|
||||
}
|
||||
|
||||
return committer.Commit()
|
||||
@@ -269,14 +269,14 @@ func DeleteAvatar(u *user_model.User) error {
|
||||
log.Trace("DeleteAvatar[%d]: %s", u.ID, aPath)
|
||||
if len(u.Avatar) > 0 {
|
||||
if err := storage.Avatars.Delete(aPath); err != nil {
|
||||
return fmt.Errorf("Failed to remove %s: %v", aPath, err)
|
||||
return fmt.Errorf("Failed to remove %s: %w", aPath, err)
|
||||
}
|
||||
}
|
||||
|
||||
u.UseCustomAvatar = false
|
||||
u.Avatar = ""
|
||||
if _, err := db.GetEngine(db.DefaultContext).ID(u.ID).Cols("avatar, use_custom_avatar").Update(u); err != nil {
|
||||
return fmt.Errorf("UpdateUser: %v", err)
|
||||
return fmt.Errorf("UpdateUser: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@@ -190,7 +190,7 @@ func PrepareWebhook(ctx context.Context, w *webhook_model.Webhook, event webhook
|
||||
if ok {
|
||||
payloader, err = webhook.payloadCreator(p, event, w.Meta)
|
||||
if err != nil {
|
||||
return fmt.Errorf("create payload for %s[%s]: %v", w.Type, event, err)
|
||||
return fmt.Errorf("create payload for %s[%s]: %w", w.Type, event, err)
|
||||
}
|
||||
} else {
|
||||
payloader = p
|
||||
@@ -202,7 +202,7 @@ func PrepareWebhook(ctx context.Context, w *webhook_model.Webhook, event webhook
|
||||
EventType: event,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("CreateHookTask: %v", err)
|
||||
return fmt.Errorf("CreateHookTask: %w", err)
|
||||
}
|
||||
|
||||
return enqueueHookTask(task)
|
||||
@@ -220,7 +220,7 @@ func PrepareWebhooks(ctx context.Context, source EventSource, event webhook_mode
|
||||
IsActive: util.OptionalBoolTrue,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("ListWebhooksByOpts: %v", err)
|
||||
return fmt.Errorf("ListWebhooksByOpts: %w", err)
|
||||
}
|
||||
ws = append(ws, repoHooks...)
|
||||
|
||||
@@ -234,7 +234,7 @@ func PrepareWebhooks(ctx context.Context, source EventSource, event webhook_mode
|
||||
IsActive: util.OptionalBoolTrue,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("ListWebhooksByOpts: %v", err)
|
||||
return fmt.Errorf("ListWebhooksByOpts: %w", err)
|
||||
}
|
||||
ws = append(ws, orgHooks...)
|
||||
}
|
||||
@@ -242,7 +242,7 @@ func PrepareWebhooks(ctx context.Context, source EventSource, event webhook_mode
|
||||
// Add any admin-defined system webhooks
|
||||
systemHooks, err := webhook_model.GetSystemWebhooks(ctx, util.OptionalBoolTrue)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetSystemWebhooks: %v", err)
|
||||
return fmt.Errorf("GetSystemWebhooks: %w", err)
|
||||
}
|
||||
ws = append(ws, systemHooks...)
|
||||
|
||||
|
@@ -83,11 +83,11 @@ func InitWiki(ctx context.Context, repo *repo_model.Repository) error {
|
||||
}
|
||||
|
||||
if err := git.InitRepository(ctx, repo.WikiPath(), true); err != nil {
|
||||
return fmt.Errorf("InitRepository: %v", err)
|
||||
return fmt.Errorf("InitRepository: %w", err)
|
||||
} else if err = repo_module.CreateDelegateHooks(repo.WikiPath()); err != nil {
|
||||
return fmt.Errorf("createDelegateHooks: %v", err)
|
||||
return fmt.Errorf("createDelegateHooks: %w", err)
|
||||
} else if _, _, err = git.NewCommand(ctx, "symbolic-ref", "HEAD", git.BranchPrefix+DefaultBranch).RunStdString(&git.RunOpts{Dir: repo.WikiPath()}); err != nil {
|
||||
return fmt.Errorf("unable to set default wiki branch to master: %v", err)
|
||||
return fmt.Errorf("unable to set default wiki branch to master: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -132,7 +132,7 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
|
||||
defer wikiWorkingPool.CheckOut(fmt.Sprint(repo.ID))
|
||||
|
||||
if err = InitWiki(ctx, repo); err != nil {
|
||||
return fmt.Errorf("InitWiki: %v", err)
|
||||
return fmt.Errorf("InitWiki: %w", err)
|
||||
}
|
||||
|
||||
hasMasterBranch := git.IsBranchExist(ctx, repo.WikiPath(), DefaultBranch)
|
||||
@@ -158,20 +158,20 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
|
||||
|
||||
if err := git.Clone(ctx, repo.WikiPath(), basePath, cloneOpts); err != nil {
|
||||
log.Error("Failed to clone repository: %s (%v)", repo.FullName(), err)
|
||||
return fmt.Errorf("Failed to clone repository: %s (%v)", repo.FullName(), err)
|
||||
return fmt.Errorf("Failed to clone repository: %s (%w)", repo.FullName(), err)
|
||||
}
|
||||
|
||||
gitRepo, err := git.OpenRepository(ctx, basePath)
|
||||
if err != nil {
|
||||
log.Error("Unable to open temporary repository: %s (%v)", basePath, err)
|
||||
return fmt.Errorf("Failed to open new temporary repository in: %s %v", basePath, err)
|
||||
return fmt.Errorf("Failed to open new temporary repository in: %s %w", basePath, err)
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
if hasMasterBranch {
|
||||
if err := gitRepo.ReadTreeToIndex("HEAD"); err != nil {
|
||||
log.Error("Unable to read HEAD tree to index in: %s %v", basePath, err)
|
||||
return fmt.Errorf("Unable to read HEAD tree to index in: %s %v", basePath, err)
|
||||
return fmt.Errorf("Unable to read HEAD tree to index in: %s %w", basePath, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,7 +265,7 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
|
||||
if git.IsErrPushOutOfDate(err) || git.IsErrPushRejected(err) {
|
||||
return err
|
||||
}
|
||||
return fmt.Errorf("Push: %v", err)
|
||||
return fmt.Errorf("Push: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -288,7 +288,7 @@ func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
|
||||
defer wikiWorkingPool.CheckOut(fmt.Sprint(repo.ID))
|
||||
|
||||
if err = InitWiki(ctx, repo); err != nil {
|
||||
return fmt.Errorf("InitWiki: %v", err)
|
||||
return fmt.Errorf("InitWiki: %w", err)
|
||||
}
|
||||
|
||||
basePath, err := repo_module.CreateTemporaryPath("update-wiki")
|
||||
@@ -307,19 +307,19 @@ func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
|
||||
Branch: DefaultBranch,
|
||||
}); err != nil {
|
||||
log.Error("Failed to clone repository: %s (%v)", repo.FullName(), err)
|
||||
return fmt.Errorf("Failed to clone repository: %s (%v)", repo.FullName(), err)
|
||||
return fmt.Errorf("Failed to clone repository: %s (%w)", repo.FullName(), err)
|
||||
}
|
||||
|
||||
gitRepo, err := git.OpenRepository(ctx, basePath)
|
||||
if err != nil {
|
||||
log.Error("Unable to open temporary repository: %s (%v)", basePath, err)
|
||||
return fmt.Errorf("Failed to open new temporary repository in: %s %v", basePath, err)
|
||||
return fmt.Errorf("Failed to open new temporary repository in: %s %w", basePath, err)
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
if err := gitRepo.ReadTreeToIndex("HEAD"); err != nil {
|
||||
log.Error("Unable to read HEAD tree to index in: %s %v", basePath, err)
|
||||
return fmt.Errorf("Unable to read HEAD tree to index in: %s %v", basePath, err)
|
||||
return fmt.Errorf("Unable to read HEAD tree to index in: %s %w", basePath, err)
|
||||
}
|
||||
|
||||
found, wikiPath, err := prepareWikiFileName(gitRepo, wikiName)
|
||||
@@ -372,7 +372,7 @@ func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
|
||||
if git.IsErrPushOutOfDate(err) || git.IsErrPushRejected(err) {
|
||||
return err
|
||||
}
|
||||
return fmt.Errorf("Push: %v", err)
|
||||
return fmt.Errorf("Push: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user