mirror of
https://github.com/go-gitea/gitea.git
synced 2026-07-22 06:15:18 +02:00
refactor: git repo and relative path handling (#38522)
1. simplify "StorageRepo" code 2. simplify git.OpenRepository code 3. by the way, clean up some unused files in git test fixtures.
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
# Git Module
|
||||
|
||||
This module is merged from https://github.com/go-gitea/git which is a Go module to access Git through shell commands. Now it's a part of gitea's main repository for easier pull request.
|
||||
@@ -119,7 +119,7 @@ func Test_BatchChecker(t *testing.T) {
|
||||
setting.AppDataPath = t.TempDir()
|
||||
repoPath := "../tests/repos/language_stats_repo"
|
||||
ctx := t.Context()
|
||||
gitRepo, err := git.OpenRepository(repoPath)
|
||||
gitRepo, err := git.OpenRepositoryLocal(repoPath)
|
||||
require.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
@@ -144,7 +144,7 @@ func Test_BatchChecker(t *testing.T) {
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
tempRepo, err := git.OpenRepository(dir)
|
||||
tempRepo, err := git.OpenRepositoryLocal(dir)
|
||||
assert.NoError(t, err)
|
||||
defer tempRepo.Close()
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
func Test_Checker(t *testing.T) {
|
||||
setting.AppDataPath = t.TempDir()
|
||||
repoPath := "../tests/repos/language_stats_repo"
|
||||
gitRepo, err := git.OpenRepository(repoPath)
|
||||
gitRepo, err := git.OpenRepositoryLocal(repoPath)
|
||||
require.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
@@ -44,7 +44,7 @@ func Test_Checker(t *testing.T) {
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
tempRepo, err := git.OpenRepository(dir)
|
||||
tempRepo, err := git.OpenRepositoryLocal(dir)
|
||||
assert.NoError(t, err)
|
||||
defer tempRepo.Close()
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
func TestBlob_Data(t *testing.T) {
|
||||
output := "file2\n"
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
repo, err := OpenRepository(bareRepo1Path)
|
||||
repo, err := OpenRepositoryLocal(bareRepo1Path)
|
||||
require.NoError(t, err)
|
||||
defer repo.Close()
|
||||
|
||||
@@ -36,7 +36,7 @@ func TestBlob_Data(t *testing.T) {
|
||||
|
||||
func Benchmark_Blob_Data(b *testing.B) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
repo, err := OpenRepository(bareRepo1Path)
|
||||
repo, err := OpenRepositoryLocal(bareRepo1Path)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ package git
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
|
||||
"gitea.dev/modules/git/gitcmd"
|
||||
)
|
||||
|
||||
type BufferedReader interface {
|
||||
@@ -45,7 +47,8 @@ type CatFileBatchCloser interface {
|
||||
|
||||
// NewBatch creates a "batch object provider (CatFileBatch)" for the given repository path to retrieve object info and content efficiently.
|
||||
// The CatFileBatch and the readers create by it should only be used in the same goroutine.
|
||||
func NewBatch(ctx context.Context, repoPath string) (CatFileBatchCloser, error) {
|
||||
func NewBatch(ctx context.Context, repo RepositoryFacade) (CatFileBatchCloser, error) {
|
||||
repoPath := gitcmd.RepoLocalPath(repo)
|
||||
if DefaultFeatures().SupportCatFileBatchCommand {
|
||||
return newCatFileBatchCommand(ctx, repoPath)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"gitea.dev/modules/git/gitcmd"
|
||||
"gitea.dev/modules/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -24,9 +25,10 @@ func TestCatFileBatch(t *testing.T) {
|
||||
}
|
||||
|
||||
func testCatFileBatch(t *testing.T) {
|
||||
repo1 := gitcmd.RepositoryUnmanaged(filepath.Join(testReposDir, "repo1_bare"))
|
||||
t.Run("CorruptedGitRepo", func(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
batch, err := NewBatch(t.Context(), tmpDir)
|
||||
batch, err := NewBatch(t.Context(), gitcmd.RepositoryUnmanaged(tmpDir))
|
||||
// as long as the directory exists, no error, because we can't really know whether the git repo is valid until we run commands
|
||||
require.NoError(t, err)
|
||||
defer batch.Close()
|
||||
@@ -47,7 +49,7 @@ func testCatFileBatch(t *testing.T) {
|
||||
assert.ErrorIs(t, err, expectedErr)
|
||||
}
|
||||
|
||||
batch, err := NewBatch(t.Context(), filepath.Join(testReposDir, "repo1_bare"))
|
||||
batch, err := NewBatch(t.Context(), repo1)
|
||||
require.NoError(t, err)
|
||||
defer batch.Close()
|
||||
_, err = batch.QueryInfo("e2129701f1a4d54dc44f03c93bca0a2aec7c5449")
|
||||
@@ -79,7 +81,7 @@ func testCatFileBatch(t *testing.T) {
|
||||
simulateQueryTerminated(t, nil, os.ErrClosed) // pipes are closed faster
|
||||
})
|
||||
|
||||
batch, err := NewBatch(t.Context(), filepath.Join(testReposDir, "repo1_bare"))
|
||||
batch, err := NewBatch(t.Context(), repo1)
|
||||
require.NoError(t, err)
|
||||
defer batch.Close()
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
)
|
||||
|
||||
func TestEntries_GetCommitsInfo_ContextErr(t *testing.T) {
|
||||
repo, err := OpenRepository(filepath.Join(testReposDir, "repo1_bare"))
|
||||
repo, err := OpenRepositoryLocal(filepath.Join(testReposDir, "repo1_bare"))
|
||||
require.NoError(t, err)
|
||||
defer repo.Close()
|
||||
|
||||
|
||||
@@ -12,10 +12,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const (
|
||||
testReposDir = "tests/repos/"
|
||||
)
|
||||
|
||||
func cloneRepo(tb testing.TB, url string) (string, error) {
|
||||
repoDir := tb.TempDir()
|
||||
if err := Clone(tb.Context(), url, repoDir, CloneRepoOptions{
|
||||
@@ -132,7 +128,7 @@ func testGetCommitsInfo(t *testing.T, repo1 *Repository) {
|
||||
|
||||
func TestEntries_GetCommitsInfo(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
bareRepo1, err := OpenRepositoryLocal(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
@@ -142,7 +138,7 @@ func TestEntries_GetCommitsInfo(t *testing.T) {
|
||||
if err != nil {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
clonedRepo1, err := OpenRepository(clonedPath)
|
||||
clonedRepo1, err := OpenRepositoryLocal(clonedPath)
|
||||
if err != nil {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ signed commit`
|
||||
0x94, 0x33, 0xb2, 0xa6, 0x2b, 0x96, 0x4c, 0x17, 0xa4, 0x48, 0x5a, 0xe1, 0x80, 0xf4, 0x5f, 0x59,
|
||||
0x5d, 0x3e, 0x69, 0xd3, 0x1b, 0x78, 0x60, 0x87, 0x77, 0x5e, 0x28, 0xc6, 0xb6, 0x39, 0x9d, 0xf0,
|
||||
}
|
||||
gitRepo, err := OpenRepository(filepath.Join(testReposDir, "repo1_bare_sha256"))
|
||||
gitRepo, err := OpenRepositoryLocal(filepath.Join(testReposDir, "repo1_bare_sha256"))
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, gitRepo)
|
||||
defer gitRepo.Close()
|
||||
@@ -103,7 +103,7 @@ signed commit`, commitFromReader.Signature.Payload)
|
||||
func TestHasPreviousCommitSha256(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare_sha256")
|
||||
|
||||
repo, err := OpenRepository(bareRepo1Path)
|
||||
repo, err := OpenRepositoryLocal(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer repo.Close()
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ gpgsig -----BEGIN PGP SIGNATURE-----
|
||||
empty commit`
|
||||
|
||||
sha := &Sha1Hash{0xfe, 0xaf, 0x4b, 0xa6, 0xbc, 0x63, 0x5f, 0xec, 0x44, 0x2f, 0x46, 0xdd, 0xd4, 0x51, 0x24, 0x16, 0xec, 0x43, 0xc2, 0xc2}
|
||||
gitRepo, err := OpenRepository(filepath.Join(testReposDir, "repo1_bare"))
|
||||
gitRepo, err := OpenRepositoryLocal(filepath.Join(testReposDir, "repo1_bare"))
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, gitRepo)
|
||||
defer gitRepo.Close()
|
||||
@@ -120,7 +120,7 @@ gpgsig -----BEGIN PGP SIGNATURE-----
|
||||
ISO-8859-1`
|
||||
commitString = strings.ReplaceAll(commitString, "<SPACE>", " ")
|
||||
sha := &Sha1Hash{0xfe, 0xaf, 0x4b, 0xa6, 0xbc, 0x63, 0x5f, 0xec, 0x44, 0x2f, 0x46, 0xdd, 0xd4, 0x51, 0x24, 0x16, 0xec, 0x43, 0xc2, 0xc2}
|
||||
gitRepo, err := OpenRepository(filepath.Join(testReposDir, "repo1_bare"))
|
||||
gitRepo, err := OpenRepositoryLocal(filepath.Join(testReposDir, "repo1_bare"))
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, gitRepo)
|
||||
defer gitRepo.Close()
|
||||
@@ -162,7 +162,7 @@ ISO-8859-1`, commitFromReader.Signature.Payload)
|
||||
func TestHasPreviousCommit(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
|
||||
repo, err := OpenRepository(bareRepo1Path)
|
||||
repo, err := OpenRepositoryLocal(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer repo.Close()
|
||||
|
||||
@@ -187,7 +187,7 @@ func TestHasPreviousCommit(t *testing.T) {
|
||||
|
||||
func Test_GetCommitBranchStart(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
repo, err := OpenRepository(bareRepo1Path)
|
||||
repo, err := OpenRepositoryLocal(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer repo.Close()
|
||||
commit, err := repo.GetBranchCommit(t.Context(), "branch1")
|
||||
|
||||
@@ -198,9 +198,9 @@ func runGitTests(m interface{ Run() int }) int {
|
||||
}
|
||||
|
||||
func LockConfigAndDo(ctx context.Context, repo RepositoryFacade, fn func(ctx context.Context) error) error {
|
||||
return globallock.LockAndDo(ctx, "repo-config:"+repo.GitRepoUniqueID(), fn)
|
||||
return globallock.LockAndDo(ctx, "repo-config:"+repo.GitRepoManagedID(), fn)
|
||||
}
|
||||
|
||||
func LockWriteAndDo(ctx context.Context, repo RepositoryFacade, fn func(ctx context.Context) error) error {
|
||||
return globallock.LockAndDo(ctx, "repo-write:"+repo.GitRepoUniqueID(), fn)
|
||||
return globallock.LockAndDo(ctx, "repo-write:"+repo.GitRepoManagedID(), fn)
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const testReposDir = "tests/repos/"
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
RunGitTests(m)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,14 @@ import (
|
||||
)
|
||||
|
||||
type RepositoryFacade interface {
|
||||
GitRepoUniqueID() string
|
||||
// GitRepoManagedID returns a "managed id", which should be a cache-key-friendly string.
|
||||
// e.g.: ID with prefix&suffix or UUID
|
||||
GitRepoManagedID() string
|
||||
|
||||
// GitRepoLocation returns the location for the git repository.
|
||||
// * relative path: will be converted to an absolute path by setting.RepoRootPath
|
||||
// * absolute path: will be used as-is
|
||||
// * in the future: maybe URI for more flexible definitions
|
||||
GitRepoLocation() string
|
||||
}
|
||||
|
||||
@@ -26,3 +33,34 @@ func RepoLocalPath(repo RepositoryFacade) string {
|
||||
}
|
||||
return filepath.Join(setting.RepoRootPath, filepath.FromSlash(repoLoc))
|
||||
}
|
||||
|
||||
type repositoryUnmanaged string
|
||||
|
||||
func (r repositoryUnmanaged) GitRepoManagedID() string {
|
||||
panic("this repo is not managed by Gitea, can't be used in this managed context")
|
||||
}
|
||||
|
||||
func (r repositoryUnmanaged) GitRepoLocation() string {
|
||||
return string(r)
|
||||
}
|
||||
|
||||
func RepositoryUnmanaged(s string) RepositoryFacade {
|
||||
return repositoryUnmanaged(s)
|
||||
}
|
||||
|
||||
type repositoryManaged struct {
|
||||
id string
|
||||
loc string
|
||||
}
|
||||
|
||||
func (r *repositoryManaged) GitRepoManagedID() string {
|
||||
return r.id
|
||||
}
|
||||
|
||||
func (r *repositoryManaged) GitRepoLocation() string {
|
||||
return r.loc
|
||||
}
|
||||
|
||||
func RepositoryManaged(id, loc string) RepositoryFacade {
|
||||
return &repositoryManaged{id, loc}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func TestGrepSearch(t *testing.T) {
|
||||
repo, err := OpenRepository(filepath.Join(testReposDir, "language_stats_repo"))
|
||||
repo, err := OpenRepositoryLocal(filepath.Join(testReposDir, "language_stats_repo"))
|
||||
assert.NoError(t, err)
|
||||
defer repo.Close()
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
func TestRepository_GetLanguageStats(t *testing.T) {
|
||||
setting.AppDataPath = t.TempDir()
|
||||
repoPath := "../tests/repos/language_stats_repo"
|
||||
gitRepo, err := git.OpenRepository(repoPath)
|
||||
gitRepo, err := git.OpenRepositoryLocal(repoPath)
|
||||
require.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
func TestGetNotes(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
bareRepo1, err := OpenRepositoryLocal(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
@@ -25,7 +25,7 @@ func TestGetNotes(t *testing.T) {
|
||||
|
||||
func TestGetNestedNotes(t *testing.T) {
|
||||
repoPath := filepath.Join(testReposDir, "repo3_notes")
|
||||
repo, err := OpenRepository(repoPath)
|
||||
repo, err := OpenRepositoryLocal(repoPath)
|
||||
assert.NoError(t, err)
|
||||
defer repo.Close()
|
||||
|
||||
@@ -40,7 +40,7 @@ func TestGetNestedNotes(t *testing.T) {
|
||||
|
||||
func TestGetNonExistentNotes(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
bareRepo1, err := OpenRepositoryLocal(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
func TestFindLFSFile(t *testing.T) {
|
||||
repoPath := "../../../tests/gitea-repositories-meta/user2/lfs.git"
|
||||
gitRepo, err := git.OpenRepository(repoPath)
|
||||
gitRepo, err := git.OpenRepositoryLocal(repoPath)
|
||||
require.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
|
||||
@@ -28,15 +28,23 @@ type RepositoryBase struct {
|
||||
|
||||
LastCommitCache *LastCommitCache
|
||||
|
||||
repoFacade RepositoryFacade
|
||||
tagCache *ObjectCache[*Tag]
|
||||
objectFormatCache ObjectFormat
|
||||
}
|
||||
|
||||
func OpenRepository(repoPath string) (*Repository, error) {
|
||||
repoPath, err := filepath.Abs(repoPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var _ gitcmd.RepositoryFacade = (*Repository)(nil)
|
||||
|
||||
func (repo *Repository) GitRepoManagedID() string {
|
||||
return repo.repoFacade.GitRepoManagedID()
|
||||
}
|
||||
|
||||
func (repo *Repository) GitRepoLocation() string {
|
||||
return repo.repoFacade.GitRepoLocation()
|
||||
}
|
||||
|
||||
func OpenRepository(repo RepositoryFacade) (*Repository, error) {
|
||||
repoPath := gitcmd.RepoLocalPath(repo)
|
||||
exist, err := util.IsDir(repoPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -45,7 +53,7 @@ func OpenRepository(repoPath string) (*Repository, error) {
|
||||
return nil, util.NewNotExistErrorf("no such file or directory")
|
||||
}
|
||||
gitRepo := &Repository{
|
||||
RepositoryBase: RepositoryBase{Path: repoPath, tagCache: newObjectCache[*Tag]()},
|
||||
RepositoryBase: RepositoryBase{Path: repoPath, tagCache: newObjectCache[*Tag](), repoFacade: repo},
|
||||
}
|
||||
if err = openRepositoryInternal(gitRepo); err != nil {
|
||||
return nil, err
|
||||
@@ -53,6 +61,16 @@ func OpenRepository(repoPath string) (*Repository, error) {
|
||||
return gitRepo, nil
|
||||
}
|
||||
|
||||
func OpenRepositoryLocal(localPath string) (_ *Repository, err error) {
|
||||
if !filepath.IsAbs(localPath) {
|
||||
localPath, err = filepath.Abs(localPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return OpenRepository(gitcmd.RepositoryUnmanaged(localPath))
|
||||
}
|
||||
|
||||
func (repo *Repository) Close() error {
|
||||
if repo == nil {
|
||||
setting.PanicInDevOrTesting("don't close a nil repository")
|
||||
|
||||
@@ -42,7 +42,7 @@ func (repo *Repository) CatFileBatch(ctx context.Context) (_ CatFileBatch, close
|
||||
}
|
||||
|
||||
if repo.catFileBatchCloser == nil {
|
||||
repo.catFileBatchCloser, err = NewBatch(ctx, repo.Path)
|
||||
repo.catFileBatchCloser, err = NewBatch(ctx, repo)
|
||||
if err != nil {
|
||||
repo.catFileBatchCloser = nil // otherwise it is "interface(nil)" and will cause wrong logic
|
||||
return nil, nil, err
|
||||
@@ -59,7 +59,7 @@ func (repo *Repository) CatFileBatch(ctx context.Context) (_ CatFileBatch, close
|
||||
}
|
||||
|
||||
log.Debug("Opening temporary cat file batch for: %s", repo.Path)
|
||||
tempBatch, err := NewBatch(ctx, repo.Path)
|
||||
tempBatch, err := NewBatch(ctx, repo)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
@@ -14,9 +15,13 @@ import (
|
||||
|
||||
func TestRepoCatFileBatch(t *testing.T) {
|
||||
t.Run("MissingRepoAndClose", func(t *testing.T) {
|
||||
repo, err := OpenRepository(filepath.Join(testReposDir, "repo1_bare"))
|
||||
testDir := filepath.Join(t.TempDir(), "testdir")
|
||||
_ = os.Mkdir(testDir, 0o755)
|
||||
repo, err := OpenRepositoryLocal(testDir)
|
||||
require.NoError(t, err)
|
||||
// when the repo is missing (it usually occurs during testing because the fixtures are synced frequently)
|
||||
err = os.Remove(testDir)
|
||||
require.NoError(t, err)
|
||||
repo.Path = "/no-such" // when the repo is missing (it usually occurs during testing because the fixtures are synced frequently)
|
||||
_, _, err = repo.CatFileBatch(t.Context())
|
||||
require.Error(t, err)
|
||||
require.NoError(t, repo.Close()) // shouldn't panic
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
func TestRepository_GetBlob_Found(t *testing.T) {
|
||||
repoPath := filepath.Join(testReposDir, "repo1_bare")
|
||||
r, err := OpenRepository(repoPath)
|
||||
r, err := OpenRepositoryLocal(repoPath)
|
||||
assert.NoError(t, err)
|
||||
defer r.Close()
|
||||
|
||||
@@ -42,7 +42,7 @@ func TestRepository_GetBlob_Found(t *testing.T) {
|
||||
|
||||
func TestRepository_GetBlob_NotExist(t *testing.T) {
|
||||
repoPath := filepath.Join(testReposDir, "repo1_bare")
|
||||
r, err := OpenRepository(repoPath)
|
||||
r, err := OpenRepositoryLocal(repoPath)
|
||||
assert.NoError(t, err)
|
||||
defer r.Close()
|
||||
|
||||
@@ -56,7 +56,7 @@ func TestRepository_GetBlob_NotExist(t *testing.T) {
|
||||
|
||||
func TestRepository_GetBlob_NoId(t *testing.T) {
|
||||
repoPath := filepath.Join(testReposDir, "repo1_bare")
|
||||
r, err := OpenRepository(repoPath)
|
||||
r, err := OpenRepositoryLocal(repoPath)
|
||||
assert.NoError(t, err)
|
||||
defer r.Close()
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
func TestRepository_GetBranches(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
bareRepo1, err := OpenRepositoryLocal(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
@@ -41,7 +41,7 @@ func TestRepository_GetBranches(t *testing.T) {
|
||||
|
||||
func BenchmarkRepository_GetBranches(b *testing.B) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
bareRepo1, err := OpenRepositoryLocal(bareRepo1Path)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
@@ -57,7 +57,7 @@ func BenchmarkRepository_GetBranches(b *testing.B) {
|
||||
|
||||
func TestGetRefsBySha(t *testing.T) {
|
||||
bareRepo5Path := filepath.Join(testReposDir, "repo5_pulls")
|
||||
bareRepo5, err := OpenRepository(bareRepo5Path)
|
||||
bareRepo5, err := OpenRepositoryLocal(bareRepo5Path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -84,7 +84,7 @@ func TestGetRefsBySha(t *testing.T) {
|
||||
|
||||
func BenchmarkGetRefsBySha(b *testing.B) {
|
||||
bareRepo5Path := filepath.Join(testReposDir, "repo5_pulls")
|
||||
bareRepo5, err := OpenRepository(bareRepo5Path)
|
||||
bareRepo5, err := OpenRepositoryLocal(bareRepo5Path)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
@@ -98,7 +98,7 @@ func BenchmarkGetRefsBySha(b *testing.B) {
|
||||
|
||||
func TestRepository_IsObjectExist(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
repo, err := OpenRepository(filepath.Join(testReposDir, "repo1_bare"))
|
||||
repo, err := OpenRepositoryLocal(filepath.Join(testReposDir, "repo1_bare"))
|
||||
require.NoError(t, err)
|
||||
defer repo.Close()
|
||||
|
||||
@@ -151,7 +151,7 @@ func TestRepository_IsObjectExist(t *testing.T) {
|
||||
|
||||
func TestRepository_IsReferenceExist(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
repo, err := OpenRepository(filepath.Join(testReposDir, "repo1_bare"))
|
||||
repo, err := OpenRepositoryLocal(filepath.Join(testReposDir, "repo1_bare"))
|
||||
require.NoError(t, err)
|
||||
defer repo.Close()
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
|
||||
func TestRepository_GetCommitBranches(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
bareRepo1, err := OpenRepositoryLocal(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
@@ -45,7 +45,7 @@ func TestRepository_GetCommitBranches(t *testing.T) {
|
||||
|
||||
func TestGetTagCommitWithSignature(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
bareRepo1, err := OpenRepositoryLocal(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
@@ -60,7 +60,7 @@ func TestGetTagCommitWithSignature(t *testing.T) {
|
||||
|
||||
func TestGetCommitWithBadCommitID(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
bareRepo1, err := OpenRepositoryLocal(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
@@ -72,7 +72,7 @@ func TestGetCommitWithBadCommitID(t *testing.T) {
|
||||
|
||||
func TestIsCommitInBranch(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
bareRepo1, err := OpenRepositoryLocal(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
@@ -87,7 +87,7 @@ func TestIsCommitInBranch(t *testing.T) {
|
||||
|
||||
func TestRepository_CommitsBetween(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo4_commitsbetween")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
bareRepo1, err := OpenRepositoryLocal(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
@@ -109,7 +109,7 @@ func TestRepository_CommitsBetween(t *testing.T) {
|
||||
|
||||
func TestGetRefCommitID(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
bareRepo1, err := OpenRepositoryLocal(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
@@ -136,7 +136,7 @@ func TestCommitsByFileAndRange(t *testing.T) {
|
||||
defer test.MockVariableValue(&setting.Git.CommitsRangeSize, 2)()
|
||||
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
bareRepo1, err := OpenRepositoryLocal(bareRepo1Path)
|
||||
require.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
@@ -179,7 +179,7 @@ M 100644 :1 b.txt
|
||||
`))).RunStdString(t.Context())
|
||||
require.NoError(t, runErr)
|
||||
|
||||
repoFollowRename, err := OpenRepository(repoFollowRenameDir)
|
||||
repoFollowRename, err := OpenRepositoryLocal(repoFollowRenameDir)
|
||||
require.NoError(t, err)
|
||||
defer repoFollowRename.Close()
|
||||
|
||||
|
||||
@@ -12,10 +12,10 @@ import (
|
||||
|
||||
// WriteCommitGraph write commit graph to speed up repo access
|
||||
// this requires git v2.18 to be installed
|
||||
func WriteCommitGraph(ctx context.Context, repoPath string) error {
|
||||
func WriteCommitGraph(ctx context.Context, repo RepositoryFacade) error {
|
||||
if DefaultFeatures().CheckVersionAtLeast("2.18") {
|
||||
if _, _, err := gitcmd.NewCommand("commit-graph", "write").WithDir(repoPath).RunStdString(ctx); err != nil {
|
||||
return fmt.Errorf("unable to write commit-graph for '%s' : %w", repoPath, err)
|
||||
if _, _, err := gitcmd.NewCommand("commit-graph", "write").WithRepo(repo).RunStdString(ctx); err != nil {
|
||||
return fmt.Errorf("unable to write commit-graph for '%s' : %w", repo.GitRepoLocation(), err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -22,7 +22,7 @@ func TestGetFormatPatch(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
repo, err := OpenRepository(clonedPath)
|
||||
repo, err := OpenRepositoryLocal(clonedPath)
|
||||
if err != nil {
|
||||
assert.NoError(t, err)
|
||||
return
|
||||
@@ -50,7 +50,7 @@ func TestGetFormatPatch(t *testing.T) {
|
||||
func TestReadPatch(t *testing.T) {
|
||||
// Ensure we can read the patch files
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
repo, err := OpenRepository(bareRepo1Path)
|
||||
repo, err := OpenRepositoryLocal(bareRepo1Path)
|
||||
if err != nil {
|
||||
assert.NoError(t, err)
|
||||
return
|
||||
@@ -88,7 +88,7 @@ func TestReadWritePullHead(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
repo, err := OpenRepository(clonedPath)
|
||||
repo, err := OpenRepositoryLocal(clonedPath)
|
||||
if err != nil {
|
||||
assert.NoError(t, err)
|
||||
return
|
||||
@@ -130,7 +130,7 @@ func TestReadWritePullHead(t *testing.T) {
|
||||
|
||||
func TestGetCommitFilesChanged(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
repo, err := OpenRepository(bareRepo1Path)
|
||||
repo, err := OpenRepositoryLocal(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer repo.Close()
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
func TestRepository_GetRefs(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
bareRepo1, err := OpenRepositoryLocal(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
@@ -37,7 +37,7 @@ func TestRepository_GetRefs(t *testing.T) {
|
||||
|
||||
func TestRepository_GetRefsFiltered(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
bareRepo1, err := OpenRepositoryLocal(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
func TestRepository_GetCodeActivityStats(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
bareRepo1, err := OpenRepositoryLocal(bareRepo1Path)
|
||||
assert.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
func TestRepository_GetTagInfos(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||
bareRepo1, err := OpenRepositoryLocal(bareRepo1Path)
|
||||
if err != nil {
|
||||
assert.NoError(t, err)
|
||||
return
|
||||
@@ -44,7 +44,7 @@ func TestRepository_GetTag(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
bareRepo1, err := OpenRepository(clonedPath)
|
||||
bareRepo1, err := OpenRepositoryLocal(clonedPath)
|
||||
if err != nil {
|
||||
assert.NoError(t, err)
|
||||
return
|
||||
@@ -136,7 +136,7 @@ func TestRepository_GetAnnotatedTag(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
bareRepo1, err := OpenRepository(clonedPath)
|
||||
bareRepo1, err := OpenRepositoryLocal(clonedPath)
|
||||
if err != nil {
|
||||
assert.NoError(t, err)
|
||||
return
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
func TestRepoIsEmpty(t *testing.T) {
|
||||
emptyRepo2Path := filepath.Join(testReposDir, "repo2_empty")
|
||||
repo, err := OpenRepository(emptyRepo2Path)
|
||||
repo, err := OpenRepositoryLocal(emptyRepo2Path)
|
||||
assert.NoError(t, err)
|
||||
defer repo.Close()
|
||||
isEmpty, err := repo.IsEmpty(t.Context())
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
Add some test files for GetLanguageStats
|
||||
|
||||
Signed-off-by: Andrew Thornton <art27@cantab.net>
|
||||
@@ -1 +0,0 @@
|
||||
2
|
||||
@@ -4,6 +4,7 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"gitea.dev/modules/util"
|
||||
@@ -13,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
func TestFollowLink(t *testing.T) {
|
||||
r, err := OpenRepository("tests/repos/repo1_bare")
|
||||
r, err := OpenRepositoryLocal(filepath.Join(testReposDir, "repo1_bare"))
|
||||
require.NoError(t, err)
|
||||
defer r.Close()
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func TestSubTree_Issue29101(t *testing.T) {
|
||||
repo, err := OpenRepository(filepath.Join(testReposDir, "repo1_bare"))
|
||||
repo, err := OpenRepositoryLocal(filepath.Join(testReposDir, "repo1_bare"))
|
||||
assert.NoError(t, err)
|
||||
defer repo.Close()
|
||||
|
||||
@@ -27,7 +27,7 @@ func TestSubTree_Issue29101(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_GetTreePathLatestCommit(t *testing.T) {
|
||||
repo, err := OpenRepository(filepath.Join(testReposDir, "repo6_blame"))
|
||||
repo, err := OpenRepositoryLocal(filepath.Join(testReposDir, "repo6_blame"))
|
||||
assert.NoError(t, err)
|
||||
defer repo.Close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user