mirror of
https://github.com/go-gitea/gitea.git
synced 2026-07-24 07:15:18 +02:00
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
25 lines
788 B
Go
25 lines
788 B
Go
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package repository
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"gitea.dev/modules/git"
|
|
"gitea.dev/modules/git/gitcmd"
|
|
"gitea.dev/modules/setting"
|
|
)
|
|
|
|
// 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 {
|
|
return "", nil, nil, fmt.Errorf("failed to create temp dir with prefix %s: %w", tmpNamePrefix, err)
|
|
}
|
|
tmpRepo = gitcmd.RepositoryUnmanaged(tmpPath)
|
|
return tmpPath, tmpRepo, cancel, nil
|
|
}
|