summaryrefslogtreecommitdiffstats
path: root/modules/git
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/git
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/git')
-rw-r--r--modules/git/blame.go6
-rw-r--r--modules/git/diff.go4
-rw-r--r--modules/git/error.go4
-rw-r--r--modules/git/parse_gogit.go4
-rw-r--r--modules/git/pipeline/catfile.go6
-rw-r--r--modules/git/pipeline/namerev.go2
-rw-r--r--modules/git/pipeline/revlist.go4
-rw-r--r--modules/git/repo.go4
-rw-r--r--modules/git/repo_attribute.go2
-rw-r--r--modules/git/repo_compare.go12
-rw-r--r--modules/git/repo_gpg.go2
-rw-r--r--modules/git/repo_tag.go4
12 files changed, 27 insertions, 27 deletions
diff --git a/modules/git/blame.go b/modules/git/blame.go
index 1653ecbf85..832b12213c 100644
--- a/modules/git/blame.go
+++ b/modules/git/blame.go
@@ -106,7 +106,7 @@ func (r *BlameReader) Close() error {
_ = r.output.Close()
if err := r.cmd.Wait(); err != nil {
- return fmt.Errorf("Wait: %v", err)
+ return fmt.Errorf("Wait: %w", err)
}
return nil
@@ -129,13 +129,13 @@ func createBlameReader(ctx context.Context, dir string, command ...string) (*Bla
stdout, err := cmd.StdoutPipe()
if err != nil {
defer finished()
- return nil, fmt.Errorf("StdoutPipe: %v", err)
+ return nil, fmt.Errorf("StdoutPipe: %w", err)
}
if err = cmd.Start(); err != nil {
defer finished()
_ = stdout.Close()
- return nil, fmt.Errorf("Start: %v", err)
+ return nil, fmt.Errorf("Start: %w", err)
}
reader := bufio.NewReader(stdout)
diff --git a/modules/git/diff.go b/modules/git/diff.go
index 13ff6bd1e6..1a43d0dd4a 100644
--- a/modules/git/diff.go
+++ b/modules/git/diff.go
@@ -41,7 +41,7 @@ func GetReverseRawDiff(ctx context.Context, repoPath, commitID string, writer io
Stdout: writer,
Stderr: stderr,
}); err != nil {
- return fmt.Errorf("Run: %v - %s", err, stderr)
+ return fmt.Errorf("Run: %w - %s", err, stderr)
}
return nil
}
@@ -89,7 +89,7 @@ func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diff
Stdout: writer,
Stderr: stderr,
}); err != nil {
- return fmt.Errorf("Run: %v - %s", err, stderr)
+ return fmt.Errorf("Run: %w - %s", err, stderr)
}
return nil
}
diff --git a/modules/git/error.go b/modules/git/error.go
index 40c4106414..ebfea8e702 100644
--- a/modules/git/error.go
+++ b/modules/git/error.go
@@ -116,7 +116,7 @@ func (err *ErrPushOutOfDate) Error() string {
// Unwrap unwraps the underlying error
func (err *ErrPushOutOfDate) Unwrap() error {
- return fmt.Errorf("%v - %s", err.Err, err.StdErr)
+ return fmt.Errorf("%w - %s", err.Err, err.StdErr)
}
// ErrPushRejected represents an error if merging fails due to rejection from a hook
@@ -139,7 +139,7 @@ func (err *ErrPushRejected) Error() string {
// Unwrap unwraps the underlying error
func (err *ErrPushRejected) Unwrap() error {
- return fmt.Errorf("%v - %s", err.Err, err.StdErr)
+ return fmt.Errorf("%w - %s", err.Err, err.StdErr)
}
// GenerateMessage generates the remote message from the stderr
diff --git a/modules/git/parse_gogit.go b/modules/git/parse_gogit.go
index 409432c5d6..4a8dcfdf35 100644
--- a/modules/git/parse_gogit.go
+++ b/modules/git/parse_gogit.go
@@ -56,7 +56,7 @@ func parseTreeEntries(data []byte, ptree *Tree) ([]*TreeEntry, error) {
}
id, err := NewIDFromString(string(data[pos : pos+40]))
if err != nil {
- return nil, fmt.Errorf("Invalid ls-tree output: %v", err)
+ return nil, fmt.Errorf("Invalid ls-tree output: %w", err)
}
entry.ID = id
entry.gogitTreeEntry.Hash = id
@@ -80,7 +80,7 @@ func parseTreeEntries(data []byte, ptree *Tree) ([]*TreeEntry, error) {
if data[pos] == '"' {
entry.gogitTreeEntry.Name, err = strconv.Unquote(string(data[pos:end]))
if err != nil {
- return nil, fmt.Errorf("Invalid ls-tree output: %v", err)
+ return nil, fmt.Errorf("Invalid ls-tree output: %w", err)
}
} else {
entry.gogitTreeEntry.Name = string(data[pos:end])
diff --git a/modules/git/pipeline/catfile.go b/modules/git/pipeline/catfile.go
index 40dd2bca29..c1d4bd1665 100644
--- a/modules/git/pipeline/catfile.go
+++ b/modules/git/pipeline/catfile.go
@@ -33,7 +33,7 @@ func CatFileBatchCheck(ctx context.Context, shasToCheckReader *io.PipeReader, ca
Stdout: catFileCheckWriter,
Stderr: stderr,
}); err != nil {
- _ = catFileCheckWriter.CloseWithError(fmt.Errorf("git cat-file --batch-check [%s]: %v - %s", tmpBasePath, err, errbuf.String()))
+ _ = catFileCheckWriter.CloseWithError(fmt.Errorf("git cat-file --batch-check [%s]: %w - %s", tmpBasePath, err, errbuf.String()))
}
}
@@ -51,7 +51,7 @@ func CatFileBatchCheckAllObjects(ctx context.Context, catFileCheckWriter *io.Pip
Stderr: stderr,
}); err != nil {
log.Error("git cat-file --batch-check --batch-all-object [%s]: %v - %s", tmpBasePath, err, errbuf.String())
- err = fmt.Errorf("git cat-file --batch-check --batch-all-object [%s]: %v - %s", tmpBasePath, err, errbuf.String())
+ err = fmt.Errorf("git cat-file --batch-check --batch-all-object [%s]: %w - %s", tmpBasePath, err, errbuf.String())
_ = catFileCheckWriter.CloseWithError(err)
errChan <- err
}
@@ -71,7 +71,7 @@ func CatFileBatch(ctx context.Context, shasToBatchReader *io.PipeReader, catFile
Stdin: shasToBatchReader,
Stderr: stderr,
}); err != nil {
- _ = shasToBatchReader.CloseWithError(fmt.Errorf("git rev-list [%s]: %v - %s", tmpBasePath, err, errbuf.String()))
+ _ = shasToBatchReader.CloseWithError(fmt.Errorf("git rev-list [%s]: %w - %s", tmpBasePath, err, errbuf.String()))
}
}
diff --git a/modules/git/pipeline/namerev.go b/modules/git/pipeline/namerev.go
index 8356e70234..85ba7db23e 100644
--- a/modules/git/pipeline/namerev.go
+++ b/modules/git/pipeline/namerev.go
@@ -29,6 +29,6 @@ func NameRevStdin(ctx context.Context, shasToNameReader *io.PipeReader, nameRevS
Stdin: shasToNameReader,
Stderr: stderr,
}); err != nil {
- _ = shasToNameReader.CloseWithError(fmt.Errorf("git name-rev [%s]: %v - %s", tmpBasePath, err, errbuf.String()))
+ _ = shasToNameReader.CloseWithError(fmt.Errorf("git name-rev [%s]: %w - %s", tmpBasePath, err, errbuf.String()))
}
}
diff --git a/modules/git/pipeline/revlist.go b/modules/git/pipeline/revlist.go
index 5f62e85e7f..93142034ec 100644
--- a/modules/git/pipeline/revlist.go
+++ b/modules/git/pipeline/revlist.go
@@ -31,7 +31,7 @@ func RevListAllObjects(ctx context.Context, revListWriter *io.PipeWriter, wg *sy
Stderr: stderr,
}); err != nil {
log.Error("git rev-list --objects --all [%s]: %v - %s", basePath, err, errbuf.String())
- err = fmt.Errorf("git rev-list --objects --all [%s]: %v - %s", basePath, err, errbuf.String())
+ err = fmt.Errorf("git rev-list --objects --all [%s]: %w - %s", basePath, err, errbuf.String())
_ = revListWriter.CloseWithError(err)
errChan <- err
}
@@ -50,7 +50,7 @@ func RevListObjects(ctx context.Context, revListWriter *io.PipeWriter, wg *sync.
Stderr: stderr,
}); err != nil {
log.Error("git rev-list [%s]: %v - %s", tmpBasePath, err, errbuf.String())
- errChan <- fmt.Errorf("git rev-list [%s]: %v - %s", tmpBasePath, err, errbuf.String())
+ errChan <- fmt.Errorf("git rev-list [%s]: %w - %s", tmpBasePath, err, errbuf.String())
}
}
diff --git a/modules/git/repo.go b/modules/git/repo.go
index 575b686e29..8ba3ae4fda 100644
--- a/modules/git/repo.go
+++ b/modules/git/repo.go
@@ -90,7 +90,7 @@ func (repo *Repository) IsEmpty() (bool, error) {
if err.Error() == "exit status 1" && errbuf.String() == "" {
return true, nil
}
- return true, fmt.Errorf("check empty: %v - %s", err, errbuf.String())
+ return true, fmt.Errorf("check empty: %w - %s", err, errbuf.String())
}
return strings.TrimSpace(output.String()) == "", nil
@@ -251,7 +251,7 @@ func Push(ctx context.Context, repoPath string, opts PushOptions) error {
}
if errbuf.Len() > 0 && err != nil {
- return fmt.Errorf("%v - %s", err, errbuf.String())
+ return fmt.Errorf("%w - %s", err, errbuf.String())
}
return err
diff --git a/modules/git/repo_attribute.go b/modules/git/repo_attribute.go
index 60dc993dc2..d9c50be6f7 100644
--- a/modules/git/repo_attribute.go
+++ b/modules/git/repo_attribute.go
@@ -68,7 +68,7 @@ func (repo *Repository) CheckAttribute(opts CheckAttributeOpts) (map[string]map[
Stdout: stdOut,
Stderr: stdErr,
}); err != nil {
- return nil, fmt.Errorf("failed to run check-attr: %v\n%s\n%s", err, stdOut.String(), stdErr.String())
+ return nil, fmt.Errorf("failed to run check-attr: %w\n%s\n%s", err, stdOut.String(), stdErr.String())
}
// FIXME: This is incorrect on versions < 1.8.5
diff --git a/modules/git/repo_compare.go b/modules/git/repo_compare.go
index aad78370ff..7575b11658 100644
--- a/modules/git/repo_compare.go
+++ b/modules/git/repo_compare.go
@@ -62,7 +62,7 @@ func (repo *Repository) GetCompareInfo(basePath, baseBranch, headBranch string,
// Add a temporary remote
tmpRemote = strconv.FormatInt(time.Now().UnixNano(), 10)
if err = repo.AddRemote(tmpRemote, basePath, false); err != nil {
- return nil, fmt.Errorf("AddRemote: %v", err)
+ return nil, fmt.Errorf("AddRemote: %w", err)
}
defer func() {
if err := repo.RemoveRemote(tmpRemote); err != nil {
@@ -100,7 +100,7 @@ func (repo *Repository) GetCompareInfo(basePath, baseBranch, headBranch string,
}
compareInfo.Commits, err = repo.parsePrettyFormatLogToList(logs)
if err != nil {
- return nil, fmt.Errorf("parsePrettyFormatLogToList: %v", err)
+ return nil, fmt.Errorf("parsePrettyFormatLogToList: %w", err)
}
} else {
compareInfo.Commits = []*Commit{}
@@ -166,7 +166,7 @@ func (repo *Repository) GetDiffNumChangedFiles(base, head string, directComparis
return w.numLines, nil
}
}
- return 0, fmt.Errorf("%v: Stderr: %s", err, stderr)
+ return 0, fmt.Errorf("%w: Stderr: %s", err, stderr)
}
return w.numLines, nil
}
@@ -215,20 +215,20 @@ func parseDiffStat(stdout string) (numFiles, totalAdditions, totalDeletions int,
numFiles, err = strconv.Atoi(groups[1])
if err != nil {
- return 0, 0, 0, fmt.Errorf("unable to parse shortstat: %s. Error parsing NumFiles %v", stdout, err)
+ return 0, 0, 0, fmt.Errorf("unable to parse shortstat: %s. Error parsing NumFiles %w", stdout, err)
}
if len(groups[2]) != 0 {
totalAdditions, err = strconv.Atoi(groups[2])
if err != nil {
- return 0, 0, 0, fmt.Errorf("unable to parse shortstat: %s. Error parsing NumAdditions %v", stdout, err)
+ return 0, 0, 0, fmt.Errorf("unable to parse shortstat: %s. Error parsing NumAdditions %w", stdout, err)
}
}
if len(groups[3]) != 0 {
totalDeletions, err = strconv.Atoi(groups[3])
if err != nil {
- return 0, 0, 0, fmt.Errorf("unable to parse shortstat: %s. Error parsing NumDeletions %v", stdout, err)
+ return 0, 0, 0, fmt.Errorf("unable to parse shortstat: %s. Error parsing NumDeletions %w", stdout, err)
}
}
return numFiles, totalAdditions, totalDeletions, err
diff --git a/modules/git/repo_gpg.go b/modules/git/repo_gpg.go
index abbb349159..25188d07e3 100644
--- a/modules/git/repo_gpg.go
+++ b/modules/git/repo_gpg.go
@@ -18,7 +18,7 @@ func (gpgSettings *GPGSettings) LoadPublicKeyContent() error {
"gpg -a --export",
"gpg", "-a", "--export", gpgSettings.KeyID)
if err != nil {
- return fmt.Errorf("Unable to get default signing key: %s, %s, %v", gpgSettings.KeyID, stderr, err)
+ return fmt.Errorf("Unable to get default signing key: %s, %s, %w", gpgSettings.KeyID, stderr, err)
}
gpgSettings.PublicKeyContent = content
return nil
diff --git a/modules/git/repo_tag.go b/modules/git/repo_tag.go
index fd0de7b3a1..8585d824f9 100644
--- a/modules/git/repo_tag.go
+++ b/modules/git/repo_tag.go
@@ -166,7 +166,7 @@ func parseTagRef(ref map[string]string) (tag *Tag, err error) {
tag.ID, err = NewIDFromString(ref["objectname"])
if err != nil {
- return nil, fmt.Errorf("parse objectname '%s': %v", ref["objectname"], err)
+ return nil, fmt.Errorf("parse objectname '%s': %w", ref["objectname"], err)
}
if tag.Type == "commit" {
@@ -176,7 +176,7 @@ func parseTagRef(ref map[string]string) (tag *Tag, err error) {
// annotated tag
tag.Object, err = NewIDFromString(ref["object"])
if err != nil {
- return nil, fmt.Errorf("parse object '%s': %v", ref["object"], err)
+ return nil, fmt.Errorf("parse object '%s': %w", ref["object"], err)
}
}