diff options
author | Otto <otto@codeberg.org> | 2024-11-04 11:40:07 +0100 |
---|---|---|
committer | Otto <otto@codeberg.org> | 2024-11-04 11:40:07 +0100 |
commit | 1418ac176de9f718419672af870071ce2469a071 (patch) | |
tree | 24d314ae1961b54383358fd6d91f3124c425d597 /services | |
parent | Merge pull request '[PORT] Fix a number of typescript issues (gitea#32308)' (... (diff) | |
parent | [PORT] Fix git error handling (gitea#32401) (diff) | |
download | forgejo-1418ac176de9f718419672af870071ce2469a071.tar.xz forgejo-1418ac176de9f718419672af870071ce2469a071.zip |
Merge pull request '[PORT] Fix git error handling (gitea#32401)' (#5794) from gusted/forgejo-port-32401 into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/5794
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Reviewed-by: Otto <otto@codeberg.org>
Diffstat (limited to 'services')
-rw-r--r-- | services/gitdiff/gitdiff.go | 2 | ||||
-rw-r--r-- | services/mirror/mirror_pull.go | 10 | ||||
-rw-r--r-- | services/repository/branch.go | 7 | ||||
-rw-r--r-- | services/repository/files/temp_repo.go | 34 | ||||
-rw-r--r-- | services/repository/push.go | 4 |
5 files changed, 19 insertions, 38 deletions
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index 8f376a1045..91b1f135c4 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -1159,7 +1159,7 @@ func GetDiff(ctx context.Context, gitRepo *git.Repository, opts *DiffOptions, fi Dir: repoPath, Stdout: writer, Stderr: stderr, - }); err != nil { + }); err != nil && !git.IsErrCanceledOrKilled(err) { log.Error("error during GetDiff(git diff dir: %s): %v, stderr: %s", repoPath, err, stderr.String()) } diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go index 9f7ffb29c9..2d128919f9 100644 --- a/services/mirror/mirror_pull.go +++ b/services/mirror/mirror_pull.go @@ -604,14 +604,8 @@ func checkAndUpdateEmptyRepository(ctx context.Context, m *repo_model.Mirror, re } // Update the git repository default branch if err := gitrepo.SetDefaultBranch(ctx, m.Repo, m.Repo.DefaultBranch); err != nil { - if !git.IsErrUnsupportedVersion(err) { - log.Error("Failed to update default branch of underlying git repository %-v. Error: %v", m.Repo, err) - desc := fmt.Sprintf("Failed to update default branch of underlying git repository '%s': %v", m.Repo.RepoPath(), err) - if err = system_model.CreateRepositoryNotice(desc); err != nil { - log.Error("CreateRepositoryNotice: %v", err) - } - return false - } + log.Error("Failed to update default branch of underlying git repository %-v. Error: %v", m.Repo, err) + return false } m.Repo.IsEmpty = false // Update the is empty and default_branch columns diff --git a/services/repository/branch.go b/services/repository/branch.go index 7d92053178..8d5df98f86 100644 --- a/services/repository/branch.go +++ b/services/repository/branch.go @@ -588,12 +588,7 @@ func SetRepoDefaultBranch(ctx context.Context, repo *repo_model.Repository, gitR log.Error("CancelPreviousJobs: %v", err) } - if err := gitrepo.SetDefaultBranch(ctx, repo, newBranchName); err != nil { - if !git.IsErrUnsupportedVersion(err) { - return err - } - } - return nil + return gitrepo.SetDefaultBranch(ctx, repo, newBranchName) }); err != nil { return err } diff --git a/services/repository/files/temp_repo.go b/services/repository/files/temp_repo.go index 50b936cfa7..6e7570b82c 100644 --- a/services/repository/files/temp_repo.go +++ b/services/repository/files/temp_repo.go @@ -343,8 +343,7 @@ func (t *TemporaryUploadRepository) Push(doer *user_model.User, commitHash, bran 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: %w", err) + return nil, fmt.Errorf("unable to open stdout pipe: %w", err) } defer func() { _ = stdoutReader.Close() @@ -352,9 +351,7 @@ func (t *TemporaryUploadRepository) DiffIndex() (*gitdiff.Diff, error) { }() stderr := new(bytes.Buffer) var diff *gitdiff.Diff - var finalErr error - - if err := git.NewCommand(t.ctx, "diff-index", "--src-prefix=\\a/", "--dst-prefix=\\b/", "--cached", "-p", "HEAD"). + err = git.NewCommand(t.ctx, "diff-index", "--src-prefix=\\a/", "--dst-prefix=\\b/", "--cached", "-p", "HEAD"). Run(&git.RunOpts{ Timeout: 30 * time.Second, Dir: t.basePath, @@ -362,23 +359,20 @@ func (t *TemporaryUploadRepository) DiffIndex() (*gitdiff.Diff, error) { Stderr: stderr, PipelineFunc: func(ctx context.Context, cancel context.CancelFunc) error { _ = stdoutWriter.Close() - diff, finalErr = gitdiff.ParsePatch(t.ctx, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, stdoutReader, "") - if finalErr != nil { - log.Error("ParsePatch: %v", finalErr) - cancel() - } + defer cancel() + var diffErr error + diff, diffErr = gitdiff.ParsePatch(t.ctx, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, stdoutReader, "") _ = stdoutReader.Close() - return finalErr + if diffErr != nil { + // if the diffErr is not nil, it will be returned as the error of "Run()" + return fmt.Errorf("ParsePatch: %w", diffErr) + } + return nil }, - }); err != nil { - if finalErr != nil { - log.Error("Unable to ParsePatch in temporary repo %s (%s). Error: %v", t.repo.FullName(), t.basePath, finalErr) - return nil, finalErr - } - 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: %w\nStderr: %s", - t.repo.FullName(), err, stderr) + }) + if err != nil && !git.IsErrCanceledOrKilled(err) { + log.Error("Unable to diff-index 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: %w", err) } diff.NumFiles, diff.TotalAddition, diff.TotalDeletion, err = git.GetDiffShortStat(t.ctx, t.basePath, git.TrustedCmdArgs{"--cached"}, "HEAD") diff --git a/services/repository/push.go b/services/repository/push.go index afd6308cdb..0f24295e89 100644 --- a/services/repository/push.go +++ b/services/repository/push.go @@ -183,9 +183,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { repo.IsEmpty = false if repo.DefaultBranch != setting.Repository.DefaultBranch { if err := gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil { - if !git.IsErrUnsupportedVersion(err) { - return err - } + return err } } // Update the is empty and default_branch columns |