aboutsummaryrefslogtreecommitdiffstats
path: root/modules/repository
diff options
context:
space:
mode:
authordelvh <leon@kske.dev>2022-10-24 21:29:17 +0200
committerGitHub <noreply@github.com>2022-10-24 20:29:17 +0100
commit0ebb45cfe7606adf021ad359d6fbfcefc54360a5 (patch)
tree541b75d083213e93bbbfadbdc5d560c739543903 /modules/repository
parent7c11a73833f3aa9783015e5e13871d3c298d3ef6 (diff)
downloadgitea-0ebb45cfe7606adf021ad359d6fbfcefc54360a5.tar.gz
gitea-0ebb45cfe7606adf021ad359d6fbfcefc54360a5.zip
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>
Diffstat (limited to 'modules/repository')
-rw-r--r--modules/repository/commits.go2
-rw-r--r--modules/repository/create.go44
-rw-r--r--modules/repository/generate.go30
-rw-r--r--modules/repository/hooks.go14
-rw-r--r--modules/repository/init.go40
-rw-r--r--modules/repository/repo.go32
-rw-r--r--modules/repository/temp.go4
7 files changed, 83 insertions, 83 deletions
diff --git a/modules/repository/commits.go b/modules/repository/commits.go
index c4a69f4a01..7d6eec151f 100644
--- a/modules/repository/commits.go
+++ b/modules/repository/commits.go
@@ -78,7 +78,7 @@ func (pc *PushCommits) toAPIPayloadCommit(ctx context.Context, repoPath, repoLin
fileStatus, err := git.GetCommitFileStatus(ctx, repoPath, commit.Sha1)
if err != nil {
- return nil, fmt.Errorf("FileStatus [commit_sha1: %s]: %v", commit.Sha1, err)
+ return nil, fmt.Errorf("FileStatus [commit_sha1: %s]: %w", commit.Sha1, err)
}
return &api.PayloadCommit{
diff --git a/modules/repository/create.go b/modules/repository/create.go
index 966a6a2f21..1fec0335a2 100644
--- a/modules/repository/create.go
+++ b/modules/repository/create.go
@@ -37,7 +37,7 @@ func CreateRepositoryByExample(ctx context.Context, doer, u *user_model.User, re
has, err := repo_model.IsRepositoryExist(ctx, u, repo.Name)
if err != nil {
- return fmt.Errorf("IsRepositoryExist: %v", err)
+ return fmt.Errorf("IsRepositoryExist: %w", err)
} else if has {
return repo_model.ErrRepoAlreadyExist{
Uname: u.Name,
@@ -100,11 +100,11 @@ func CreateRepositoryByExample(ctx context.Context, doer, u *user_model.User, re
// Remember visibility preference.
u.LastRepoVisibility = repo.IsPrivate
if err = user_model.UpdateUserCols(ctx, u, "last_repo_visibility"); err != nil {
- return fmt.Errorf("UpdateUserCols: %v", err)
+ return fmt.Errorf("UpdateUserCols: %w", err)
}
if err = user_model.IncrUserRepoNum(ctx, u.ID); err != nil {
- return fmt.Errorf("IncrUserRepoNum: %v", err)
+ return fmt.Errorf("IncrUserRepoNum: %w", err)
}
u.NumRepos++
@@ -112,40 +112,40 @@ func CreateRepositoryByExample(ctx context.Context, doer, u *user_model.User, re
if u.IsOrganization() {
teams, err := organization.FindOrgTeams(ctx, u.ID)
if err != nil {
- return fmt.Errorf("FindOrgTeams: %v", err)
+ return fmt.Errorf("FindOrgTeams: %w", err)
}
for _, t := range teams {
if t.IncludesAllRepositories {
if err := models.AddRepository(ctx, t, repo); err != nil {
- return fmt.Errorf("AddRepository: %v", err)
+ return fmt.Errorf("AddRepository: %w", err)
}
}
}
if isAdmin, err := access_model.IsUserRepoAdmin(ctx, repo, doer); err != nil {
- return fmt.Errorf("IsUserRepoAdmin: %v", err)
+ return fmt.Errorf("IsUserRepoAdmin: %w", err)
} else if !isAdmin {
// Make creator repo admin if it wasn't assigned automatically
if err = addCollaborator(ctx, repo, doer); err != nil {
- return fmt.Errorf("addCollaborator: %v", err)
+ return fmt.Errorf("addCollaborator: %w", err)
}
if err = repo_model.ChangeCollaborationAccessModeCtx(ctx, repo, doer.ID, perm.AccessModeAdmin); err != nil {
- return fmt.Errorf("ChangeCollaborationAccessModeCtx: %v", err)
+ return fmt.Errorf("ChangeCollaborationAccessModeCtx: %w", err)
}
}
} else if err = access_model.RecalculateAccesses(ctx, repo); err != nil {
// Organization automatically called this in AddRepository method.
- return fmt.Errorf("RecalculateAccesses: %v", err)
+ return fmt.Errorf("RecalculateAccesses: %w", err)
}
if setting.Service.AutoWatchNewRepos {
if err = repo_model.WatchRepo(ctx, doer.ID, repo.ID, true); err != nil {
- return fmt.Errorf("WatchRepo: %v", err)
+ return fmt.Errorf("WatchRepo: %w", err)
}
}
if err = webhook.CopyDefaultWebhooksToRepo(ctx, repo.ID); err != nil {
- return fmt.Errorf("CopyDefaultWebhooksToRepo: %v", err)
+ return fmt.Errorf("CopyDefaultWebhooksToRepo: %w", err)
}
return nil
@@ -248,7 +248,7 @@ func CreateRepository(doer, u *user_model.User, opts CreateRepoOptions) (*repo_m
return fmt.Errorf(
"delete repo directory %s/%s failed(2): %v", u.Name, repo.Name, err2)
}
- return fmt.Errorf("initRepository: %v", err)
+ return fmt.Errorf("initRepository: %w", err)
}
// Initialize Issue Labels if selected
@@ -256,12 +256,12 @@ func CreateRepository(doer, u *user_model.User, opts CreateRepoOptions) (*repo_m
if err = InitializeLabels(ctx, repo.ID, opts.IssueLabels, false); err != nil {
rollbackRepo = repo
rollbackRepo.OwnerID = u.ID
- return fmt.Errorf("InitializeLabels: %v", err)
+ return fmt.Errorf("InitializeLabels: %w", err)
}
}
if err := CheckDaemonExportOK(ctx, repo); err != nil {
- return fmt.Errorf("checkDaemonExportOK: %v", err)
+ return fmt.Errorf("checkDaemonExportOK: %w", err)
}
if stdout, _, err := git.NewCommand(ctx, "update-server-info").
@@ -270,7 +270,7 @@ func CreateRepository(doer, u *user_model.User, opts CreateRepoOptions) (*repo_m
log.Error("CreateRepository(git update-server-info) in %v: Stdout: %s\nError: %v", repo, stdout, err)
rollbackRepo = repo
rollbackRepo.OwnerID = u.ID
- return fmt.Errorf("CreateRepository(git update-server-info): %v", err)
+ return fmt.Errorf("CreateRepository(git update-server-info): %w", err)
}
return nil
}); err != nil {
@@ -290,12 +290,12 @@ func CreateRepository(doer, u *user_model.User, opts CreateRepoOptions) (*repo_m
func UpdateRepoSize(ctx context.Context, repo *repo_model.Repository) error {
size, err := util.GetDirectorySize(repo.RepoPath())
if err != nil {
- return fmt.Errorf("updateSize: %v", err)
+ return fmt.Errorf("updateSize: %w", err)
}
lfsSize, err := git_model.GetRepoLFSSize(ctx, repo.ID)
if err != nil {
- return fmt.Errorf("updateSize: GetLFSMetaObjects: %v", err)
+ return fmt.Errorf("updateSize: GetLFSMetaObjects: %w", err)
}
return repo_model.UpdateRepoSize(ctx, repo.ID, size+lfsSize)
@@ -339,7 +339,7 @@ func UpdateRepository(ctx context.Context, repo *repo_model.Repository, visibili
e := db.GetEngine(ctx)
if _, err = e.ID(repo.ID).AllCols().Update(repo); err != nil {
- return fmt.Errorf("update: %v", err)
+ return fmt.Errorf("update: %w", err)
}
if err = UpdateRepoSize(ctx, repo); err != nil {
@@ -348,12 +348,12 @@ func UpdateRepository(ctx context.Context, repo *repo_model.Repository, visibili
if visibilityChanged {
if err = repo.GetOwner(ctx); err != nil {
- return fmt.Errorf("getOwner: %v", err)
+ return fmt.Errorf("getOwner: %w", err)
}
if repo.Owner.IsOrganization() {
// Organization repository need to recalculate access table when visibility is changed.
if err = access_model.RecalculateTeamAccesses(ctx, repo, 0); err != nil {
- return fmt.Errorf("recalculateTeamAccesses: %v", err)
+ return fmt.Errorf("recalculateTeamAccesses: %w", err)
}
}
@@ -374,12 +374,12 @@ func UpdateRepository(ctx context.Context, repo *repo_model.Repository, visibili
forkRepos, err := repo_model.GetRepositoriesByForkID(ctx, repo.ID)
if err != nil {
- return fmt.Errorf("getRepositoriesByForkID: %v", err)
+ return fmt.Errorf("getRepositoriesByForkID: %w", err)
}
for i := range forkRepos {
forkRepos[i].IsPrivate = repo.IsPrivate || repo.Owner.Visibility == api.VisibleTypePrivate
if err = UpdateRepository(ctx, forkRepos[i], true); err != nil {
- return fmt.Errorf("updateRepository[%d]: %v", forkRepos[i].ID, err)
+ return fmt.Errorf("updateRepository[%d]: %w", forkRepos[i].ID, err)
}
}
}
diff --git a/modules/repository/generate.go b/modules/repository/generate.go
index a69dd12a78..c5fd7d60bf 100644
--- a/modules/repository/generate.go
+++ b/modules/repository/generate.go
@@ -153,22 +153,22 @@ func generateRepoCommit(ctx context.Context, repo, templateRepo, generateRepo *r
Depth: 1,
Branch: templateRepo.DefaultBranch,
}); err != nil {
- return fmt.Errorf("git clone: %v", err)
+ return fmt.Errorf("git clone: %w", err)
}
if err := util.RemoveAll(path.Join(tmpDir, ".git")); err != nil {
- return fmt.Errorf("remove git dir: %v", err)
+ return fmt.Errorf("remove git dir: %w", err)
}
// Variable expansion
gt, err := checkGiteaTemplate(tmpDir)
if err != nil {
- return fmt.Errorf("checkGiteaTemplate: %v", err)
+ return fmt.Errorf("checkGiteaTemplate: %w", err)
}
if gt != nil {
if err := util.Remove(gt.Path); err != nil {
- return fmt.Errorf("remove .giteatemplate: %v", err)
+ return fmt.Errorf("remove .giteatemplate: %w", err)
}
// Avoid walking tree if there are no globs
@@ -215,7 +215,7 @@ func generateRepoCommit(ctx context.Context, repo, templateRepo, generateRepo *r
SetDescription(fmt.Sprintf("generateRepoCommit (git remote add): %s to %s", templateRepoPath, tmpDir)).
RunStdString(&git.RunOpts{Dir: tmpDir, Env: env}); err != nil {
log.Error("Unable to add %v as remote origin to temporary repo to %s: stdout %s\nError: %v", repo, tmpDir, stdout, err)
- return fmt.Errorf("git remote add: %v", err)
+ return fmt.Errorf("git remote add: %w", err)
}
// set default branch based on whether it's specified in the newly generated repo or not
@@ -230,7 +230,7 @@ func generateRepoCommit(ctx context.Context, repo, templateRepo, generateRepo *r
func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *repo_model.Repository) (err error) {
tmpDir, err := os.MkdirTemp(os.TempDir(), "gitea-"+repo.Name)
if err != nil {
- return fmt.Errorf("Failed to create temp dir for repository %s: %v", repo.RepoPath(), err)
+ return fmt.Errorf("Failed to create temp dir for repository %s: %w", repo.RepoPath(), err)
}
defer func() {
@@ -240,12 +240,12 @@ func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *r
}()
if err = generateRepoCommit(ctx, repo, templateRepo, generateRepo, tmpDir); err != nil {
- return fmt.Errorf("generateRepoCommit: %v", err)
+ return fmt.Errorf("generateRepoCommit: %w", err)
}
// re-fetch repo
if repo, err = repo_model.GetRepositoryByIDCtx(ctx, repo.ID); err != nil {
- return fmt.Errorf("getRepositoryByID: %v", err)
+ return fmt.Errorf("getRepositoryByID: %w", err)
}
// if there was no default branch supplied when generating the repo, use the default one from the template
@@ -255,14 +255,14 @@ func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *r
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()
if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil {
- return fmt.Errorf("setDefaultBranch: %v", err)
+ return fmt.Errorf("setDefaultBranch: %w", err)
}
if err = UpdateRepository(ctx, repo, false); err != nil {
- return fmt.Errorf("updateRepository: %v", err)
+ return fmt.Errorf("updateRepository: %w", err)
}
return nil
@@ -275,11 +275,11 @@ func GenerateGitContent(ctx context.Context, templateRepo, generateRepo *repo_mo
}
if err := UpdateRepoSize(ctx, generateRepo); err != nil {
- return fmt.Errorf("failed to update size for repository: %v", err)
+ return fmt.Errorf("failed to update size for repository: %w", err)
}
if err := git_model.CopyLFS(ctx, generateRepo, templateRepo); err != nil {
- return fmt.Errorf("failed to copy LFS: %v", err)
+ return fmt.Errorf("failed to copy LFS: %w", err)
}
return nil
}
@@ -342,14 +342,14 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ
}
if err = CheckDaemonExportOK(ctx, generateRepo); err != nil {
- return generateRepo, fmt.Errorf("checkDaemonExportOK: %v", err)
+ return generateRepo, fmt.Errorf("checkDaemonExportOK: %w", err)
}
if stdout, _, err := git.NewCommand(ctx, "update-server-info").
SetDescription(fmt.Sprintf("GenerateRepository(git update-server-info): %s", repoPath)).
RunStdString(&git.RunOpts{Dir: repoPath}); err != nil {
log.Error("GenerateRepository(git update-server-info) in %v: Stdout: %s\nError: %v", generateRepo, stdout, err)
- return generateRepo, fmt.Errorf("error in GenerateRepository(git update-server-info): %v", err)
+ return generateRepo, fmt.Errorf("error in GenerateRepository(git update-server-info): %w", err)
}
return generateRepo, nil
diff --git a/modules/repository/hooks.go b/modules/repository/hooks.go
index 7bc77552bd..4d7d294a92 100644
--- a/modules/repository/hooks.go
+++ b/modules/repository/hooks.go
@@ -123,30 +123,30 @@ func createDelegateHooks(repoPath string) (err error) {
newHookPath := filepath.Join(hookDir, hookName+".d", "gitea")
if err := os.MkdirAll(filepath.Join(hookDir, hookName+".d"), os.ModePerm); err != nil {
- return fmt.Errorf("create hooks dir '%s': %v", filepath.Join(hookDir, hookName+".d"), err)
+ return fmt.Errorf("create hooks dir '%s': %w", filepath.Join(hookDir, hookName+".d"), err)
}
// WARNING: This will override all old server-side hooks
if err = util.Remove(oldHookPath); err != nil && !os.IsNotExist(err) {
- return fmt.Errorf("unable to pre-remove old hook file '%s' prior to rewriting: %v ", oldHookPath, err)
+ return fmt.Errorf("unable to pre-remove old hook file '%s' prior to rewriting: %w ", oldHookPath, err)
}
if err = os.WriteFile(oldHookPath, []byte(hookTpls[i]), 0o777); err != nil {
- return fmt.Errorf("write old hook file '%s': %v", oldHookPath, err)
+ return fmt.Errorf("write old hook file '%s': %w", oldHookPath, err)
}
if err = ensureExecutable(oldHookPath); err != nil {
- return fmt.Errorf("Unable to set %s executable. Error %v", oldHookPath, err)
+ return fmt.Errorf("Unable to set %s executable. Error %w", oldHookPath, err)
}
if err = util.Remove(newHookPath); err != nil && !os.IsNotExist(err) {
- return fmt.Errorf("unable to pre-remove new hook file '%s' prior to rewriting: %v", newHookPath, err)
+ return fmt.Errorf("unable to pre-remove new hook file '%s' prior to rewriting: %w", newHookPath, err)
}
if err = os.WriteFile(newHookPath, []byte(giteaHookTpls[i]), 0o777); err != nil {
- return fmt.Errorf("write new hook file '%s': %v", newHookPath, err)
+ return fmt.Errorf("write new hook file '%s': %w", newHookPath, err)
}
if err = ensureExecutable(newHookPath); err != nil {
- return fmt.Errorf("Unable to set %s executable. Error %v", oldHookPath, err)
+ return fmt.Errorf("Unable to set %s executable. Error %w", oldHookPath, err)
}
}
diff --git a/modules/repository/init.go b/modules/repository/init.go
index 473729a599..65072a9599 100644
--- a/modules/repository/init.go
+++ b/modules/repository/init.go
@@ -91,7 +91,7 @@ func GetRepoInitFile(tp, name string) ([]byte, error) {
func GetLabelTemplateFile(name string) ([][3]string, error) {
data, err := GetRepoInitFile("label", name)
if err != nil {
- return nil, ErrIssueLabelTemplateLoad{name, fmt.Errorf("GetRepoInitFile: %v", err)}
+ return nil, ErrIssueLabelTemplateLoad{name, fmt.Errorf("GetRepoInitFile: %w", err)}
}
lines := strings.Split(string(data), "\n")
@@ -232,13 +232,13 @@ func prepareRepoCommit(ctx context.Context, repo *repo_model.Repository, tmpDir,
SetDescription(fmt.Sprintf("prepareRepoCommit (git clone): %s to %s", repoPath, tmpDir)).
RunStdString(&git.RunOpts{Dir: "", Env: env}); err != nil {
log.Error("Failed to clone from %v into %s: stdout: %s\nError: %v", repo, tmpDir, stdout, err)
- return fmt.Errorf("git clone: %v", err)
+ return fmt.Errorf("git clone: %w", err)
}
// README
data, err := GetRepoInitFile("readme", opts.Readme)
if err != nil {
- return fmt.Errorf("GetRepoInitFile[%s]: %v", opts.Readme, err)
+ return fmt.Errorf("GetRepoInitFile[%s]: %w", opts.Readme, err)
}
cloneLink := repo.CloneLink()
@@ -256,7 +256,7 @@ func prepareRepoCommit(ctx context.Context, repo *repo_model.Repository, tmpDir,
}
if err = os.WriteFile(filepath.Join(tmpDir, "README.md"),
[]byte(res), 0o644); err != nil {
- return fmt.Errorf("write README.md: %v", err)
+ return fmt.Errorf("write README.md: %w", err)
}
// .gitignore
@@ -266,7 +266,7 @@ func prepareRepoCommit(ctx context.Context, repo *repo_model.Repository, tmpDir,
for _, name := range names {
data, err = GetRepoInitFile("gitignore", name)
if err != nil {
- return fmt.Errorf("GetRepoInitFile[%s]: %v", name, err)
+ return fmt.Errorf("GetRepoInitFile[%s]: %w", name, err)
}
buf.WriteString("# ---> " + name + "\n")
buf.Write(data)
@@ -275,7 +275,7 @@ func prepareRepoCommit(ctx context.Context, repo *repo_model.Repository, tmpDir,
if buf.Len() > 0 {
if err = os.WriteFile(filepath.Join(tmpDir, ".gitignore"), buf.Bytes(), 0o644); err != nil {
- return fmt.Errorf("write .gitignore: %v", err)
+ return fmt.Errorf("write .gitignore: %w", err)
}
}
}
@@ -284,11 +284,11 @@ func prepareRepoCommit(ctx context.Context, repo *repo_model.Repository, tmpDir,
if len(opts.License) > 0 {
data, err = GetRepoInitFile("license", opts.License)
if err != nil {
- return fmt.Errorf("GetRepoInitFile[%s]: %v", opts.License, err)
+ return fmt.Errorf("GetRepoInitFile[%s]: %w", opts.License, err)
}
if err = os.WriteFile(filepath.Join(tmpDir, "LICENSE"), data, 0o644); err != nil {
- return fmt.Errorf("write LICENSE: %v", err)
+ return fmt.Errorf("write LICENSE: %w", err)
}
}
@@ -314,7 +314,7 @@ func initRepoCommit(ctx context.Context, tmpPath string, repo *repo_model.Reposi
SetDescription(fmt.Sprintf("initRepoCommit (git add): %s", tmpPath)).
RunStdString(&git.RunOpts{Dir: tmpPath}); err != nil {
log.Error("git add --all failed: Stdout: %s\nError: %v", stdout, err)
- return fmt.Errorf("git add --all: %v", err)
+ return fmt.Errorf("git add --all: %w", err)
}
cmd := git.NewCommand(ctx,
@@ -344,7 +344,7 @@ func initRepoCommit(ctx context.Context, tmpPath string, repo *repo_model.Reposi
SetDescription(fmt.Sprintf("initRepoCommit (git commit): %s", tmpPath)).
RunStdString(&git.RunOpts{Dir: tmpPath, Env: env}); err != nil {
log.Error("Failed to commit: %v: Stdout: %s\nError: %v", cmd.String(), stdout, err)
- return fmt.Errorf("git commit: %v", err)
+ return fmt.Errorf("git commit: %w", err)
}
if len(defaultBranch) == 0 {
@@ -355,7 +355,7 @@ func initRepoCommit(ctx context.Context, tmpPath string, repo *repo_model.Reposi
SetDescription(fmt.Sprintf("initRepoCommit (git push): %s", tmpPath)).
RunStdString(&git.RunOpts{Dir: tmpPath, Env: InternalPushingEnvironment(u, repo)}); err != nil {
log.Error("Failed to push back to HEAD: Stdout: %s\nError: %v", stdout, err)
- return fmt.Errorf("git push: %v", err)
+ return fmt.Errorf("git push: %w", err)
}
return nil
@@ -378,9 +378,9 @@ func checkInitRepository(ctx context.Context, owner, name string) (err error) {
// Init git bare new repository.
if err = git.InitRepository(ctx, repoPath, true); err != nil {
- return fmt.Errorf("git.InitRepository: %v", err)
+ return fmt.Errorf("git.InitRepository: %w", err)
} else if err = createDelegateHooks(repoPath); err != nil {
- return fmt.Errorf("createDelegateHooks: %v", err)
+ return fmt.Errorf("createDelegateHooks: %w", err)
}
return nil
}
@@ -395,7 +395,7 @@ func initRepository(ctx context.Context, repoPath string, u *user_model.User, re
if opts.AutoInit {
tmpDir, err := os.MkdirTemp(os.TempDir(), "gitea-"+repo.Name)
if err != nil {
- return fmt.Errorf("Failed to create temp dir for repository %s: %v", repo.RepoPath(), err)
+ return fmt.Errorf("Failed to create temp dir for repository %s: %w", repo.RepoPath(), err)
}
defer func() {
if err := util.RemoveAll(tmpDir); err != nil {
@@ -404,19 +404,19 @@ func initRepository(ctx context.Context, repoPath string, u *user_model.User, re
}()
if err = prepareRepoCommit(ctx, repo, tmpDir, repoPath, opts); err != nil {
- return fmt.Errorf("prepareRepoCommit: %v", err)
+ return fmt.Errorf("prepareRepoCommit: %w", err)
}
// Apply changes and commit.
if err = initRepoCommit(ctx, tmpDir, repo, u, opts.DefaultBranch); err != nil {
- return fmt.Errorf("initRepoCommit: %v", err)
+ return fmt.Errorf("initRepoCommit: %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)
}
if !opts.AutoInit {
@@ -429,16 +429,16 @@ func initRepository(ctx context.Context, repoPath string, u *user_model.User, re
repo.DefaultBranch = opts.DefaultBranch
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()
if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil {
- return fmt.Errorf("setDefaultBranch: %v", err)
+ return fmt.Errorf("setDefaultBranch: %w", err)
}
}
if err = UpdateRepository(ctx, repo, false); err != nil {
- return fmt.Errorf("updateRepository: %v", err)
+ return fmt.Errorf("updateRepository: %w", err)
}
return nil
diff --git a/modules/repository/repo.go b/modules/repository/repo.go
index b01be322d2..de6de3bda4 100644
--- a/modules/repository/repo.go
+++ b/modules/repository/repo.go
@@ -70,7 +70,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
var err error
if err = util.RemoveAll(repoPath); err != nil {
- return repo, fmt.Errorf("Failed to remove %s: %v", repoPath, err)
+ return repo, fmt.Errorf("Failed to remove %s: %w", repoPath, err)
}
if err = git.Clone(ctx, opts.CloneAddr, repoPath, git.CloneRepoOptions{
@@ -79,7 +79,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
Timeout: migrateTimeout,
SkipTLSVerify: setting.Migrations.SkipTLSVerify,
}); err != nil {
- return repo, fmt.Errorf("Clone: %v", err)
+ return repo, fmt.Errorf("Clone: %w", err)
}
if err := git.WriteCommitGraph(ctx, repoPath); err != nil {
@@ -91,7 +91,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
wikiRemotePath := WikiRemoteURL(ctx, opts.CloneAddr)
if len(wikiRemotePath) > 0 {
if err := util.RemoveAll(wikiPath); err != nil {
- return repo, fmt.Errorf("Failed to remove %s: %v", wikiPath, err)
+ return repo, fmt.Errorf("Failed to remove %s: %w", wikiPath, err)
}
if err := git.Clone(ctx, wikiRemotePath, wikiPath, git.CloneRepoOptions{
@@ -103,7 +103,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
}); err != nil {
log.Warn("Clone wiki: %v", err)
if err := util.RemoveAll(wikiPath); err != nil {
- return repo, fmt.Errorf("Failed to remove %s: %v", wikiPath, err)
+ return repo, fmt.Errorf("Failed to remove %s: %w", wikiPath, err)
}
} else {
if err := git.WriteCommitGraph(ctx, wikiPath); err != nil {
@@ -118,25 +118,25 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
}
if err = CheckDaemonExportOK(ctx, repo); err != nil {
- return repo, fmt.Errorf("checkDaemonExportOK: %v", err)
+ return repo, fmt.Errorf("checkDaemonExportOK: %w", err)
}
if stdout, _, err := git.NewCommand(ctx, "update-server-info").
SetDescription(fmt.Sprintf("MigrateRepositoryGitData(git update-server-info): %s", repoPath)).
RunStdString(&git.RunOpts{Dir: repoPath}); err != nil {
log.Error("MigrateRepositoryGitData(git update-server-info) in %v: Stdout: %s\nError: %v", repo, stdout, err)
- return repo, fmt.Errorf("error in MigrateRepositoryGitData(git update-server-info): %v", err)
+ return repo, fmt.Errorf("error in MigrateRepositoryGitData(git update-server-info): %w", err)
}
gitRepo, err := git.OpenRepository(ctx, repoPath)
if err != nil {
- return repo, fmt.Errorf("OpenRepository: %v", err)
+ return repo, fmt.Errorf("OpenRepository: %w", err)
}
defer gitRepo.Close()
repo.IsEmpty, err = gitRepo.IsEmpty()
if err != nil {
- return repo, fmt.Errorf("git.IsEmpty: %v", err)
+ return repo, fmt.Errorf("git.IsEmpty: %w", err)
}
if !repo.IsEmpty {
@@ -144,7 +144,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
// Try to get HEAD branch and set it as default branch.
headBranch, err := gitRepo.GetHEADBranch()
if err != nil {
- return repo, fmt.Errorf("GetHEADBranch: %v", err)
+ return repo, fmt.Errorf("GetHEADBranch: %w", err)
}
if headBranch != nil {
repo.DefaultBranch = headBranch.Name
@@ -207,7 +207,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
}
if err = repo_model.InsertMirror(ctx, &mirrorModel); err != nil {
- return repo, fmt.Errorf("InsertOne: %v", err)
+ return repo, fmt.Errorf("InsertOne: %w", err)
}
repo.IsMirror = true
@@ -231,11 +231,11 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
func cleanUpMigrateGitConfig(configPath string) error {
cfg, err := ini.Load(configPath)
if err != nil {
- return fmt.Errorf("open config file: %v", err)
+ return fmt.Errorf("open config file: %w", err)
}
cfg.DeleteSection("remote \"origin\"")
if err = cfg.SaveToIndent(configPath, "\t"); err != nil {
- return fmt.Errorf("save config file: %v", err)
+ return fmt.Errorf("save config file: %w", err)
}
return nil
}
@@ -244,22 +244,22 @@ func cleanUpMigrateGitConfig(configPath string) error {
func CleanUpMigrateInfo(ctx context.Context, repo *repo_model.Repository) (*repo_model.Repository, error) {
repoPath := repo.RepoPath()
if err := createDelegateHooks(repoPath); err != nil {
- return repo, fmt.Errorf("createDelegateHooks: %v", err)
+ return repo, fmt.Errorf("createDelegateHooks: %w", err)
}
if repo.HasWiki() {
if err := createDelegateHooks(repo.WikiPath()); err != nil {
- return repo, fmt.Errorf("createDelegateHooks.(wiki): %v", err)
+ return repo, fmt.Errorf("createDelegateHooks.(wiki): %w", err)
}
}
_, _, err := git.NewCommand(ctx, "remote", "rm", "origin").RunStdString(&git.RunOpts{Dir: repoPath})
if err != nil && !strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") {
- return repo, fmt.Errorf("CleanUpMigrateInfo: %v", err)
+ return repo, fmt.Errorf("CleanUpMigrateInfo: %w", err)
}
if repo.HasWiki() {
if err := cleanUpMigrateGitConfig(path.Join(repo.WikiPath(), "config")); err != nil {
- return repo, fmt.Errorf("cleanUpMigrateGitConfig (wiki): %v", err)
+ return repo, fmt.Errorf("cleanUpMigrateGitConfig (wiki): %w", err)
}
}
diff --git a/modules/repository/temp.go b/modules/repository/temp.go
index 5947d29965..21af039469 100644
--- a/modules/repository/temp.go
+++ b/modules/repository/temp.go
@@ -27,12 +27,12 @@ func LocalCopyPath() string {
func CreateTemporaryPath(prefix string) (string, error) {
if err := os.MkdirAll(LocalCopyPath(), os.ModePerm); err != nil {
log.Error("Unable to create localcopypath directory: %s (%v)", LocalCopyPath(), err)
- return "", fmt.Errorf("Failed to create localcopypath directory %s: %v", LocalCopyPath(), err)
+ return "", fmt.Errorf("Failed to create localcopypath directory %s: %w", LocalCopyPath(), err)
}
basePath, err := os.MkdirTemp(LocalCopyPath(), prefix+".git")
if err != nil {
log.Error("Unable to create temporary directory: %s-*.git (%v)", prefix, err)
- return "", fmt.Errorf("Failed to create dir %s-*.git: %v", prefix, err)
+ return "", fmt.Errorf("Failed to create dir %s-*.git: %w", prefix, err)
}
return basePath, nil