From 7fe91f5ce47a327522bd08b291e10c15d0dd6fc7 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 22 Mar 2026 17:46:40 -0700 Subject: [PATCH] Use stderr instead of err --- modules/git/repo_commit.go | 14 +++++++------- modules/git/repo_commit_nogogit.go | 2 +- modules/git/tree_nogogit.go | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go index c10f73690c..163b4fc1b6 100644 --- a/modules/git/repo_commit.go +++ b/modules/git/repo_commit.go @@ -283,7 +283,7 @@ func (repo *Repository) FilesCountBetween(startCommitID, endCommitID string) (in AddDynamicArguments(startCommitID + "..." + endCommitID). WithDir(repo.Path). RunStdString(repo.Ctx) - if err != nil && strings.Contains(err.Error(), "no merge base") { + if err != nil && strings.Contains(err.Stderr(), "no merge base") { // git >= 2.28 now returns an error if startCommitID and endCommitID have become unrelated. // previously it would return the results of git diff --name-only startCommitID endCommitID so let's try that... stdout, _, err = gitcmd.NewCommand("diff", "--name-only"). @@ -301,7 +301,7 @@ func (repo *Repository) FilesCountBetween(startCommitID, endCommitID string) (in // If before is detached (removed by reset + push) it is not included. func (repo *Repository) CommitsBetween(last, before *Commit) ([]*Commit, error) { var stdout []byte - var err error + var err gitcmd.RunStdError if before == nil { stdout, _, err = gitcmd.NewCommand("rev-list"). AddDynamicArguments(last.ID.String()). @@ -312,7 +312,7 @@ func (repo *Repository) CommitsBetween(last, before *Commit) ([]*Commit, error) AddDynamicArguments(before.ID.String() + ".." + last.ID.String()). WithDir(repo.Path). RunStdBytes(repo.Ctx) - if err != nil && strings.Contains(err.Error(), "no merge base") { + if err != nil && strings.Contains(err.Stderr(), "no merge base") { // future versions of git >= 2.28 are likely to return an error if before and last have become unrelated. // previously it would return the results of git rev-list before last so let's try that... stdout, _, err = gitcmd.NewCommand("rev-list"). @@ -330,7 +330,7 @@ func (repo *Repository) CommitsBetween(last, before *Commit) ([]*Commit, error) // CommitsBetweenLimit returns a list that contains at most limit commits skipping the first skip commits between [before, last) func (repo *Repository) CommitsBetweenLimit(last, before *Commit, limit, skip int) ([]*Commit, error) { var stdout []byte - var err error + var err gitcmd.RunStdError if before == nil { stdout, _, err = gitcmd.NewCommand("rev-list"). AddOptionValues("--max-count", strconv.Itoa(limit)). @@ -345,7 +345,7 @@ func (repo *Repository) CommitsBetweenLimit(last, before *Commit, limit, skip in AddDynamicArguments(before.ID.String() + ".." + last.ID.String()). WithDir(repo.Path). RunStdBytes(repo.Ctx) - if err != nil && strings.Contains(err.Error(), "no merge base") { + if err != nil && strings.Contains(err.Stderr(), "no merge base") { // future versions of git >= 2.28 are likely to return an error if before and last have become unrelated. // previously it would return the results of git rev-list --max-count n before last so let's try that... stdout, _, err = gitcmd.NewCommand("rev-list"). @@ -366,7 +366,7 @@ func (repo *Repository) CommitsBetweenLimit(last, before *Commit, limit, skip in // If before is detached (removed by reset + push) it is not included. func (repo *Repository) CommitsBetweenNotBase(last, before *Commit, baseBranch string) ([]*Commit, error) { var stdout []byte - var err error + var err gitcmd.RunStdError if before == nil { stdout, _, err = gitcmd.NewCommand("rev-list"). AddDynamicArguments(last.ID.String()). @@ -379,7 +379,7 @@ func (repo *Repository) CommitsBetweenNotBase(last, before *Commit, baseBranch s AddOptionValues("--not", baseBranch). WithDir(repo.Path). RunStdBytes(repo.Ctx) - if err != nil && strings.Contains(err.Error(), "no merge base") { + if err != nil && strings.Contains(err.Stderr(), "no merge base") { // future versions of git >= 2.28 are likely to return an error if before and last have become unrelated. // previously it would return the results of git rev-list before last so let's try that... stdout, _, err = gitcmd.NewCommand("rev-list"). diff --git a/modules/git/repo_commit_nogogit.go b/modules/git/repo_commit_nogogit.go index 2ddb527502..cfa935da63 100644 --- a/modules/git/repo_commit_nogogit.go +++ b/modules/git/repo_commit_nogogit.go @@ -21,7 +21,7 @@ func (repo *Repository) ResolveReference(name string) (string, error) { WithDir(repo.Path). RunStdString(repo.Ctx) if err != nil { - if strings.Contains(err.Error(), "not a valid ref") { + if strings.Contains(err.Stderr(), "not a valid ref") { return "", ErrNotExist{name, ""} } return "", err diff --git a/modules/git/tree_nogogit.go b/modules/git/tree_nogogit.go index 5d951dad0d..f9470fb22d 100644 --- a/modules/git/tree_nogogit.go +++ b/modules/git/tree_nogogit.go @@ -65,7 +65,7 @@ func (t *Tree) ListEntries() (Entries, error) { stdout, _, runErr := gitcmd.NewCommand("ls-tree", "-l").AddDynamicArguments(t.ID.String()).WithDir(t.repo.Path).RunStdBytes(t.repo.Ctx) if runErr != nil { - if gitcmd.IsStdErrorNotValidObjectName(runErr) || strings.Contains(runErr.Error(), "fatal: not a tree object") { + if gitcmd.IsStdErrorNotValidObjectName(runErr) || strings.Contains(runErr.Stderr(), "fatal: not a tree object") { return nil, ErrNotExist{ ID: t.ID.String(), }