9a5720e8ad
Universal: PR Check / Branch Policy (pull_request) Successful in 1s
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
PR RC Release / Build RC Release (pull_request) Successful in 3s
Universal: PR Check / Validate PR (pull_request) Failing after 6s
Branch Cleanup / Delete merged branch (pull_request) Successful in 1s
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Full namespace migration: update the Go module path and all import statements from git.mokoconsulting.tech to code.mokoconsulting.tech. Also updates all URL references in templates, workflows, configs, tests, and documentation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package files
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
repo_model "code.mokoconsulting.tech/MokoConsulting/MokoGitea/models/repo"
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGitea/services/gitdiff"
|
|
)
|
|
|
|
// GetDiffPreview produces and returns diff result of a file which is not yet committed.
|
|
func GetDiffPreview(ctx context.Context, repo *repo_model.Repository, branch, treePath, oldContent, newContent string) (*gitdiff.Diff, error) {
|
|
if branch == "" {
|
|
branch = repo.DefaultBranch
|
|
}
|
|
t, err := NewTemporaryUploadRepository(repo)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer t.Close()
|
|
if err := t.Clone(ctx, branch, true); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := t.SetDefaultIndex(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Add the object to the database
|
|
objectHash, err := t.HashObjectAndWrite(ctx, strings.NewReader(newContent))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Add the object to the index
|
|
if err := t.AddObjectToIndex(ctx, "100644", objectHash, treePath); err != nil {
|
|
return nil, err
|
|
}
|
|
return t.DiffIndex(ctx, oldContent, newContent)
|
|
}
|