mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-03 18:24:29 +00:00
refactor: make git package handle all git operations (#38543)
before: gitrepo vs git packages after: git package fully handle all git operations by the way, use `WithRepo(repo)` instead of `WithDir(repo.Path)` to hide path details. benefits: 1. remove all unnecessary wrappers, developers no need to struggle with "which package should be used" 2. simplify code, RepositoryFacade can (will) be used everywhere, all "path" details are (will be) hidden
This commit is contained in:
@@ -7,16 +7,18 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modules/log"
|
||||
"gitea.dev/modules/git"
|
||||
"gitea.dev/modules/git/gitcmd"
|
||||
"gitea.dev/modules/setting"
|
||||
)
|
||||
|
||||
// CreateTemporaryPath creates a temporary path
|
||||
func CreateTemporaryPath(prefix string) (string, context.CancelFunc, error) {
|
||||
basePath, cleanup, err := setting.AppDataTempDir("local-repo").MkdirTempRandom(prefix + ".git")
|
||||
// CreateTemporaryGitRepo creates a temporary Git repository empty directory (not initialized)
|
||||
func CreateTemporaryGitRepo(prefix string) (tmpPath string, tmpRepo git.RepositoryFacade, cancel context.CancelFunc, err error) {
|
||||
tmpNamePrefix := prefix + ".git"
|
||||
tmpPath, cancel, err = setting.AppDataTempDir("local-repo").MkdirTempRandom(tmpNamePrefix)
|
||||
if err != nil {
|
||||
log.Error("Unable to create temporary directory: %s-*.git (%v)", prefix, err)
|
||||
return "", nil, fmt.Errorf("failed to create dir %s-*.git: %w", prefix, err)
|
||||
return "", nil, nil, fmt.Errorf("failed to create temp dir with prefix %s: %w", tmpNamePrefix, err)
|
||||
}
|
||||
return basePath, cleanup, nil
|
||||
tmpRepo = gitcmd.RepositoryUnmanaged(tmpPath)
|
||||
return tmpPath, tmpRepo, cancel, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user