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:
wxiaoguang
2026-07-19 15:32:00 +08:00
committed by GitHub
parent ae176cd649
commit b06002f449
100 changed files with 315 additions and 290 deletions
+5 -3
View File
@@ -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()