]: %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
diff --git a/services/pull/patch.go b/services/pull/patch.go
index b9f190826a496..9b87ac22e296c 100644
--- a/services/pull/patch.go
+++ b/services/pull/patch.go
@@ -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
}
diff --git a/services/pull/patch_unmerged.go b/services/pull/patch_unmerged.go
index 465465d0daed9..3f1bb7d523490 100644
--- a/services/pull/patch_unmerged.go
+++ b/services/pull/patch_unmerged.go
@@ -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
}
diff --git a/services/pull/pull.go b/services/pull/pull.go
index 3b58c675a37f9..5f8bd6b67120c 100644
--- a/services/pull/pull.go
+++ b/services/pull/pull.go
@@ -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
diff --git a/services/pull/review.go b/services/pull/review.go
index 8d8903c6a9521..16c9e108ee741 100644
--- a/services/pull/review.go
+++ b/services/pull/review.go
@@ -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()
diff --git a/services/pull/temp_repo.go b/services/pull/temp_repo.go
index 6624f5659b605..15e776c4b9ce4 100644
--- a/services/pull/temp_repo.go
+++ b/services/pull/temp_repo.go
@@ -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()
diff --git a/services/pull/update.go b/services/pull/update.go
index 49258a9862d18..bd4880a2fc7a0 100644
--- a/services/pull/update.go
+++ b/services/pull/update.go
@@ -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)
diff --git a/services/release/release.go b/services/release/release.go
index 25b89e1a0b6d7..346c2abd421b6 100644
--- a/services/release/release.go
+++ b/services/release/release.go
@@ -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 {
diff --git a/services/repository/adopt.go b/services/repository/adopt.go
index 9e04c15977637..3b986c66c6138 100644
--- a/services/repository/adopt.go
+++ b/services/repository/adopt.go
@@ -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
diff --git a/services/repository/archiver/archiver.go b/services/repository/archiver/archiver.go
index ae43503bae125..79537ea051678 100644
--- a/services/repository/archiver/archiver.go
+++ b/services/repository/archiver/archiver.go
@@ -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
diff --git a/services/repository/avatar.go b/services/repository/avatar.go
index b9bd36ab66588..b80a8fb77588e 100644
--- a/services/repository/avatar.go
+++ b/services/repository/avatar.go
@@ -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()
diff --git a/services/repository/branch.go b/services/repository/branch.go
index 6c9a5d76caf10..1328422582980 100644
--- a/services/repository/branch.go
+++ b/services/repository/branch.go
@@ -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
diff --git a/services/repository/check.go b/services/repository/check.go
index 1b2da4cc0823b..5529a61b396f4 100644
--- a/services/repository/check.go
+++ b/services/repository/check.go
@@ -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
diff --git a/services/repository/files/cherry_pick.go b/services/repository/files/cherry_pick.go
index 0107d99e665a6..a30d4f6025e8b 100644
--- a/services/repository/files/cherry_pick.go
+++ b/services/repository/files/cherry_pick.go
@@ -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 {
diff --git a/services/repository/files/commit.go b/services/repository/files/commit.go
index ecd981b5ffdba..bc5a4c8ed3a8a 100644
--- a/services/repository/files/commit.go
+++ b/services/repository/files/commit.go
@@ -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() {
diff --git a/services/repository/files/delete.go b/services/repository/files/delete.go
index 781a762d0ff72..f098052ad8abf 100644
--- a/services/repository/files/delete.go
+++ b/services/repository/files/delete.go
@@ -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
diff --git a/services/repository/files/patch.go b/services/repository/files/patch.go
index 437890c488c63..2be01f25be53a 100644
--- a/services/repository/files/patch.go
+++ b/services/repository/files/patch.go
@@ -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
diff --git a/services/repository/files/temp_repo.go b/services/repository/files/temp_repo.go
index 9513f2341e156..b96d9e7b3df5f 100644
--- a/services/repository/files/temp_repo.go
+++ b/services/repository/files/temp_repo.go
@@ -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)
}
diff --git a/services/repository/files/update.go b/services/repository/files/update.go
index 87c622a9be3cc..1721b00b01e93 100644
--- a/services/repository/files/update.go
+++ b/services/repository/files/update.go
@@ -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
}
diff --git a/services/repository/files/upload.go b/services/repository/files/upload.go
index b2dadb6497c5b..372878099103e 100644
--- a/services/repository/files/upload.go
+++ b/services/repository/files/upload.go
@@ -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))
diff --git a/services/repository/fork.go b/services/repository/fork.go
index af0ade99a9472..136d7ccab6520 100644
--- a/services/repository/fork.go
+++ b/services/repository/fork.go
@@ -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
})
diff --git a/services/repository/hooks.go b/services/repository/hooks.go
index 45a031f38e6b0..d326cd26b168f 100644
--- a/services/repository/hooks.go
+++ b/services/repository/hooks.go
@@ -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
diff --git a/services/repository/push.go b/services/repository/push.go
index d645928c43bdc..3a7205d18b6f8 100644
--- a/services/repository/push.go
+++ b/services/repository/push.go
@@ -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)
}
}
diff --git a/services/repository/repository.go b/services/repository/repository.go
index 47687d9a7396f..763ef74927ca6 100644
--- a/services/repository/repository.go
+++ b/services/repository/repository.go
@@ -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()
diff --git a/services/task/migrate.go b/services/task/migrate.go
index 775cbf6128109..faca6908a271b 100644
--- a/services/task/migrate.go
+++ b/services/task/migrate.go
@@ -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
diff --git a/services/user/user.go b/services/user/user.go
index dab9ac61a46c3..c8b497a5c46f8 100644
--- a/services/user/user.go
+++ b/services/user/user.go
@@ -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
}
diff --git a/services/webhook/webhook.go b/services/webhook/webhook.go
index e877e16edaa3f..342e764f4da16 100644
--- a/services/webhook/webhook.go
+++ b/services/webhook/webhook.go
@@ -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...)
diff --git a/services/wiki/wiki.go b/services/wiki/wiki.go
index 8faada4d59a64..f6986cff8603c 100644
--- a/services/wiki/wiki.go
+++ b/services/wiki/wiki.go
@@ -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
diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl
index 728e88b734aa5..94fb67ab44568 100644
--- a/templates/swagger/v1_json.tmpl
+++ b/templates/swagger/v1_json.tmpl
@@ -14645,6 +14645,10 @@
"description": "CreateOAuth2ApplicationOptions holds options to create an oauth2 application",
"type": "object",
"properties": {
+ "confidential_client": {
+ "type": "boolean",
+ "x-go-name": "ConfidentialClient"
+ },
"name": {
"type": "string",
"x-go-name": "Name"
@@ -17306,6 +17310,10 @@
"type": "string",
"x-go-name": "ClientSecret"
},
+ "confidential_client": {
+ "type": "boolean",
+ "x-go-name": "ConfidentialClient"
+ },
"created": {
"type": "string",
"format": "date-time",
diff --git a/templates/user/overview/header.tmpl b/templates/user/overview/header.tmpl
index f0079736079f1..61b19c60326f7 100644
--- a/templates/user/overview/header.tmpl
+++ b/templates/user/overview/header.tmpl
@@ -56,6 +56,22 @@
{{end}}
+ {{else}}
+
+ {{svg "octicon-rss"}} {{.locale.Tr "user.activity"}}
+
+ {{if not .DisableStars}}
+
+ {{svg "octicon-star"}} {{.locale.Tr "user.starred"}}
+ {{if .Owner.NumStars}}
+ {{.Owner.NumStars}}
+ {{end}}
+
+ {{else}}
+
+ {{svg "octicon-eye"}} {{.locale.Tr "user.watched"}}
+
+ {{end}}
{{end}}
diff --git a/templates/user/settings/applications_oauth2_edit_form.tmpl b/templates/user/settings/applications_oauth2_edit_form.tmpl
index 60311983c9057..9d7273fd6d0bf 100644
--- a/templates/user/settings/applications_oauth2_edit_form.tmpl
+++ b/templates/user/settings/applications_oauth2_edit_form.tmpl
@@ -43,6 +43,10 @@
+
+
+
+
diff --git a/templates/user/settings/applications_oauth2_list.tmpl b/templates/user/settings/applications_oauth2_list.tmpl
index 47d7ecfaa482a..fbca5934cd572 100644
--- a/templates/user/settings/applications_oauth2_list.tmpl
+++ b/templates/user/settings/applications_oauth2_list.tmpl
@@ -37,6 +37,10 @@
+
+
+
+
diff --git a/tests/integration/api_oauth2_apps_test.go b/tests/integration/api_oauth2_apps_test.go
index fe3525724e26a..6352449d6acb1 100644
--- a/tests/integration/api_oauth2_apps_test.go
+++ b/tests/integration/api_oauth2_apps_test.go
@@ -34,6 +34,7 @@ func testAPICreateOAuth2Application(t *testing.T) {
RedirectURIs: []string{
"http://www.google.com",
},
+ ConfidentialClient: true,
}
req := NewRequestWithJSON(t, "POST", "/api/v1/user/applications/oauth2", &appBody)
@@ -46,6 +47,7 @@ func testAPICreateOAuth2Application(t *testing.T) {
assert.EqualValues(t, appBody.Name, createdApp.Name)
assert.Len(t, createdApp.ClientSecret, 56)
assert.Len(t, createdApp.ClientID, 36)
+ assert.True(t, createdApp.ConfidentialClient)
assert.NotEmpty(t, createdApp.Created)
assert.EqualValues(t, appBody.RedirectURIs[0], createdApp.RedirectURIs[0])
unittest.AssertExistsAndLoadBean(t, &auth.OAuth2Application{UID: user.ID, Name: createdApp.Name})
@@ -62,6 +64,7 @@ func testAPIListOAuth2Applications(t *testing.T) {
RedirectURIs: []string{
"http://www.google.com",
},
+ ConfidentialClient: true,
})
urlStr := fmt.Sprintf("/api/v1/user/applications/oauth2?token=%s", token)
@@ -74,6 +77,7 @@ func testAPIListOAuth2Applications(t *testing.T) {
assert.EqualValues(t, existApp.Name, expectedApp.Name)
assert.EqualValues(t, existApp.ClientID, expectedApp.ClientID)
+ assert.Equal(t, existApp.ConfidentialClient, expectedApp.ConfidentialClient)
assert.Len(t, expectedApp.ClientID, 36)
assert.Empty(t, expectedApp.ClientSecret)
assert.EqualValues(t, existApp.RedirectURIs[0], expectedApp.RedirectURIs[0])
@@ -112,6 +116,7 @@ func testAPIGetOAuth2Application(t *testing.T) {
RedirectURIs: []string{
"http://www.google.com",
},
+ ConfidentialClient: true,
})
urlStr := fmt.Sprintf("/api/v1/user/applications/oauth2/%d?token=%s", existApp.ID, token)
@@ -124,6 +129,7 @@ func testAPIGetOAuth2Application(t *testing.T) {
assert.EqualValues(t, existApp.Name, expectedApp.Name)
assert.EqualValues(t, existApp.ClientID, expectedApp.ClientID)
+ assert.Equal(t, existApp.ConfidentialClient, expectedApp.ConfidentialClient)
assert.Len(t, expectedApp.ClientID, 36)
assert.Empty(t, expectedApp.ClientSecret)
assert.Len(t, expectedApp.RedirectURIs, 1)
@@ -148,6 +154,7 @@ func testAPIUpdateOAuth2Application(t *testing.T) {
"http://www.google.com/",
"http://www.github.com/",
},
+ ConfidentialClient: true,
}
urlStr := fmt.Sprintf("/api/v1/user/applications/oauth2/%d", existApp.ID)
@@ -162,5 +169,6 @@ func testAPIUpdateOAuth2Application(t *testing.T) {
assert.Len(t, expectedApp.RedirectURIs, 2)
assert.EqualValues(t, expectedApp.RedirectURIs[0], appBody.RedirectURIs[0])
assert.EqualValues(t, expectedApp.RedirectURIs[1], appBody.RedirectURIs[1])
+ assert.Equal(t, expectedApp.ConfidentialClient, appBody.ConfidentialClient)
unittest.AssertExistsAndLoadBean(t, &auth.OAuth2Application{ID: expectedApp.ID, Name: expectedApp.Name})
}
diff --git a/tests/integration/api_packages_container_test.go b/tests/integration/api_packages_container_test.go
index b8a3884371b20..ba76ee4baa7dd 100644
--- a/tests/integration/api_packages_container_test.go
+++ b/tests/integration/api_packages_container_test.go
@@ -471,6 +471,10 @@ func TestPackageContainer(t *testing.T) {
assert.Equal(t, fmt.Sprintf("%d", len(blobContent)), resp.Header().Get("Content-Length"))
assert.Equal(t, blobDigest, resp.Header().Get("Docker-Content-Digest"))
+
+ req = NewRequest(t, "HEAD", fmt.Sprintf("%s/blobs/%s", url, blobDigest))
+ addTokenAuthHeader(req, anonymousToken)
+ MakeRequest(t, req, http.StatusOK)
})
t.Run("GetBlob", func(t *testing.T) {
diff --git a/tests/integration/api_packages_npm_test.go b/tests/integration/api_packages_npm_test.go
index 4fdcf6682e933..20412fe727cf1 100644
--- a/tests/integration/api_packages_npm_test.go
+++ b/tests/integration/api_packages_npm_test.go
@@ -127,10 +127,16 @@ func TestPackageNpm(t *testing.T) {
b, _ := base64.StdEncoding.DecodeString(data)
assert.Equal(t, b, resp.Body.Bytes())
+ req = NewRequest(t, "GET", fmt.Sprintf("%s/-/%s", root, filename))
+ req = addTokenAuthHeader(req, token)
+ resp = MakeRequest(t, req, http.StatusOK)
+
+ assert.Equal(t, b, resp.Body.Bytes())
+
pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeNpm)
assert.NoError(t, err)
assert.Len(t, pvs, 1)
- assert.Equal(t, int64(1), pvs[0].DownloadCount)
+ assert.Equal(t, int64(2), pvs[0].DownloadCount)
})
t.Run("PackageMetadata", func(t *testing.T) {
diff --git a/tests/integration/api_packages_test.go b/tests/integration/api_packages_test.go
index 86d81994d4d22..25f5b3f2a12da 100644
--- a/tests/integration/api_packages_test.go
+++ b/tests/integration/api_packages_test.go
@@ -25,6 +25,7 @@ import (
func TestPackageAPI(t *testing.T) {
defer tests.PrepareTestEnv(t)()
+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4})
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
@@ -144,6 +145,27 @@ func TestPackageAPI(t *testing.T) {
})
}
+func TestPackageAccess(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ admin := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
+ user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5})
+ inactive := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 9})
+
+ uploadPackage := func(doer, owner *user_model.User, expectedStatus int) {
+ url := fmt.Sprintf("/api/packages/%s/generic/test-package/1.0/file.bin", owner.Name)
+ req := NewRequestWithBody(t, "PUT", url, bytes.NewReader([]byte{1}))
+ AddBasicAuthHeader(req, doer.Name)
+ MakeRequest(t, req, expectedStatus)
+ }
+
+ uploadPackage(user, inactive, http.StatusUnauthorized)
+ uploadPackage(inactive, inactive, http.StatusUnauthorized)
+ uploadPackage(inactive, user, http.StatusUnauthorized)
+ uploadPackage(admin, inactive, http.StatusCreated)
+ uploadPackage(admin, user, http.StatusCreated)
+}
+
func TestPackageCleanup(t *testing.T) {
defer tests.PrepareTestEnv(t)()
diff --git a/tests/integration/gpg_git_test.go b/tests/integration/gpg_git_test.go
index 80f484926d3a5..4dcf6276c27d3 100644
--- a/tests/integration/gpg_git_test.go
+++ b/tests/integration/gpg_git_test.go
@@ -358,7 +358,7 @@ func importTestingKey(tmpDir, name, email string) (*openpgp.Entity, error) {
keyring, err := openpgp.ReadKeyRing(block.Body)
if err != nil {
- return nil, fmt.Errorf("Keyring access failed: '%v'", err)
+ return nil, fmt.Errorf("Keyring access failed: '%w'", err)
}
// There should only be one entity in this file.
diff --git a/tests/integration/oauth_test.go b/tests/integration/oauth_test.go
index acd32e3625d7f..7863313b149aa 100644
--- a/tests/integration/oauth_test.go
+++ b/tests/integration/oauth_test.go
@@ -86,6 +86,17 @@ func TestAuthorizeRedirectWithExistingGrant(t *testing.T) {
assert.Equal(t, "https://example.com/xyzzy", u.String())
}
+func TestAuthorizePKCERequiredForPublicClient(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+ req := NewRequest(t, "GET", "/login/oauth/authorize?client_id=ce5a1322-42a7-11ed-b878-0242ac120002&redirect_uri=http%3A%2F%2F127.0.0.1&response_type=code&state=thestate")
+ ctx := loginUser(t, "user1")
+ resp := ctx.MakeRequest(t, req, http.StatusSeeOther)
+ u, err := resp.Result().Location()
+ assert.NoError(t, err)
+ assert.Equal(t, "invalid_request", u.Query().Get("error"))
+ assert.Equal(t, "PKCE is required for public clients", u.Query().Get("error_description"))
+}
+
func TestAccessTokenExchange(t *testing.T) {
defer tests.PrepareTestEnv(t)()
req := NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{