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
+7 -2
View File
@@ -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