From 2852f9a20613b145fe36a8fde5bfd31ff7e82291 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sat, 21 Feb 2026 12:31:51 +0800 Subject: *: Use testgit.NewRepo --- config/config_test.go | 14 +++++----- object/blob_parse_test.go | 2 +- object/blob_serialize_test.go | 2 +- object/commit_parse_test.go | 2 +- object/commit_serialize_test.go | 2 +- object/tag_parse_test.go | 2 +- object/tag_serialize_test.go | 2 +- object/tree_parse_test.go | 2 +- object/tree_serialize_test.go | 2 +- objectstore/loose/read_test.go | 4 +-- objectstore/loose/write_test.go | 52 +++++++++++++++++++------------------- objectstore/packed/helpers_test.go | 2 +- objectstore/packed/read_test.go | 2 +- refstore/loose/loose_test.go | 10 ++++---- refstore/packed/packed_test.go | 4 +-- refstore/reftable/reftable_test.go | 6 ++++- 16 files changed, 57 insertions(+), 53 deletions(-) diff --git a/config/config_test.go b/config/config_test.go index fd929a1f..1dd0578c 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -27,7 +27,7 @@ func gitConfigGet(t *testing.T, testRepo *testgit.TestRepo, key string) string { func TestConfigAgainstGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) testRepo.Run(t, "config", "core.bare", "true") testRepo.Run(t, "config", "core.filemode", "false") testRepo.Run(t, "config", "user.name", "Jane Doe") @@ -58,7 +58,7 @@ func TestConfigAgainstGit(t *testing.T) { func TestConfigSubsectionAgainstGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) testRepo.Run(t, "config", "remote.origin.url", "https://example.org/repo.git") testRepo.Run(t, "config", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*") @@ -81,7 +81,7 @@ func TestConfigSubsectionAgainstGit(t *testing.T) { func TestConfigMultiValueAgainstGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) testRepo.Run(t, "config", "--add", "remote.origin.fetch", "+refs/heads/main:refs/remotes/origin/main") testRepo.Run(t, "config", "--add", "remote.origin.fetch", "+refs/heads/dev:refs/remotes/origin/dev") testRepo.Run(t, "config", "--add", "remote.origin.fetch", "+refs/tags/*:refs/tags/*") @@ -114,7 +114,7 @@ func TestConfigMultiValueAgainstGit(t *testing.T) { func TestConfigCaseInsensitiveAgainstGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) testRepo.Run(t, "config", "Core.Bare", "true") testRepo.Run(t, "config", "CORE.FileMode", "false") @@ -143,7 +143,7 @@ func TestConfigCaseInsensitiveAgainstGit(t *testing.T) { func TestConfigBooleanAgainstGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) testRepo.Run(t, "config", "test.flag1", "true") testRepo.Run(t, "config", "test.flag2", "false") testRepo.Run(t, "config", "test.flag3", "yes") @@ -177,7 +177,7 @@ func TestConfigBooleanAgainstGit(t *testing.T) { func TestConfigComplexValuesAgainstGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) testRepo.Run(t, "config", "test.spaced", "value with spaces") testRepo.Run(t, "config", "test.special", "value=with=equals") testRepo.Run(t, "config", "test.path", "/path/to/something") @@ -203,7 +203,7 @@ func TestConfigComplexValuesAgainstGit(t *testing.T) { func TestConfigEntriesAgainstGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) testRepo.Run(t, "config", "core.bare", "true") testRepo.Run(t, "config", "core.filemode", "false") testRepo.Run(t, "config", "user.name", "Test User") diff --git a/object/blob_parse_test.go b/object/blob_parse_test.go index ea0a279e..0b8c22ca 100644 --- a/object/blob_parse_test.go +++ b/object/blob_parse_test.go @@ -11,7 +11,7 @@ import ( func TestBlobParseFromGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) body := []byte("hello\nblob\n") blobID := testRepo.HashObject(t, "blob", body) diff --git a/object/blob_serialize_test.go b/object/blob_serialize_test.go index 4853d980..041851ec 100644 --- a/object/blob_serialize_test.go +++ b/object/blob_serialize_test.go @@ -10,7 +10,7 @@ import ( func TestBlobSerialize(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) body := []byte("hello\nblob\n") wantID := testRepo.HashObject(t, "blob", body) diff --git a/object/commit_parse_test.go b/object/commit_parse_test.go index 66061f73..77a570af 100644 --- a/object/commit_parse_test.go +++ b/object/commit_parse_test.go @@ -11,7 +11,7 @@ import ( func TestCommitParseFromGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) _, treeID, commitID := testRepo.MakeCommit(t, "subject\n\nbody") rawBody := testRepo.CatFile(t, "commit", commitID) diff --git a/object/commit_serialize_test.go b/object/commit_serialize_test.go index 9067d511..6db48143 100644 --- a/object/commit_serialize_test.go +++ b/object/commit_serialize_test.go @@ -10,7 +10,7 @@ import ( func TestCommitSerialize(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) _, _, commitID := testRepo.MakeCommit(t, "subject\n\nbody") rawBody := testRepo.CatFile(t, "commit", commitID) diff --git a/object/tag_parse_test.go b/object/tag_parse_test.go index 4131e3f1..0009338e 100644 --- a/object/tag_parse_test.go +++ b/object/tag_parse_test.go @@ -12,7 +12,7 @@ import ( func TestTagParseFromGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) _, _, commitID := testRepo.MakeCommit(t, "subject\n\nbody") tagID := testRepo.TagAnnotated(t, "v1", commitID, "tag message") diff --git a/object/tag_serialize_test.go b/object/tag_serialize_test.go index 3f1f8b0b..6437977b 100644 --- a/object/tag_serialize_test.go +++ b/object/tag_serialize_test.go @@ -10,7 +10,7 @@ import ( func TestTagSerialize(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) _, _, commitID := testRepo.MakeCommit(t, "subject\n\nbody") tagID := testRepo.TagAnnotated(t, "v1", commitID, "tag message") diff --git a/object/tree_parse_test.go b/object/tree_parse_test.go index e1c81d58..f653f068 100644 --- a/object/tree_parse_test.go +++ b/object/tree_parse_test.go @@ -11,7 +11,7 @@ import ( func TestTreeParseFromGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) entries := adversarialRootEntries(t, testRepo) inserted := &object.Tree{} for _, entry := range entries { diff --git a/object/tree_serialize_test.go b/object/tree_serialize_test.go index 8e84a67b..f40b13a4 100644 --- a/object/tree_serialize_test.go +++ b/object/tree_serialize_test.go @@ -10,7 +10,7 @@ import ( func TestTreeSerialize(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) entries := adversarialRootEntries(t, testRepo) tree := &object.Tree{} diff --git a/objectstore/loose/read_test.go b/objectstore/loose/read_test.go index 8663ef1f..d125629a 100644 --- a/objectstore/loose/read_test.go +++ b/objectstore/loose/read_test.go @@ -15,7 +15,7 @@ import ( func TestLooseStoreReadAgainstGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) blobID := testRepo.HashObject(t, "blob", []byte("blob body\n")) _, treeID, commitID := testRepo.MakeCommit(t, "subject\n\nbody") tagID := testRepo.TagAnnotated(t, "v1", commitID, "tag message") @@ -94,7 +94,7 @@ func TestLooseStoreReadAgainstGit(t *testing.T) { func TestLooseStoreErrors(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) store := openLooseStore(t, testRepo.Dir(), algo) notFoundID, err := objectid.ParseHex(algo, strings.Repeat("0", algo.HexLen())) diff --git a/objectstore/loose/write_test.go b/objectstore/loose/write_test.go index 0dcb3a5f..b9a318d2 100644 --- a/objectstore/loose/write_test.go +++ b/objectstore/loose/write_test.go @@ -13,7 +13,7 @@ import ( func TestLooseStoreWriteWriterContentAgainstGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) store := openLooseStore(t, testRepo.Dir(), algo) content := []byte("written-by-content-writer\n") @@ -41,35 +41,35 @@ func TestLooseStoreWriteWriterContentAgainstGit(t *testing.T) { t.Fatalf("WriteWriterContent id = %s, want %s", writtenID, expectedID) } - gotBody := testRepo.CatFile(t, "blob", writtenID) - if !bytes.Equal(gotBody, content) { - t.Fatalf("git cat-file body mismatch") - } + gotBody := testRepo.CatFile(t, "blob", writtenID) + if !bytes.Equal(gotBody, content) { + t.Fatalf("git cat-file body mismatch") + } - // Writing the same object again should succeed and return the same ID. - writer, finalize, err = store.WriteWriterContent(objecttype.TypeBlob, int64(len(content))) - if err != nil { - t.Fatalf("WriteWriterContent second: %v", err) - } - if _, err := io.Copy(writer, bytes.NewReader(content)); err != nil { - t.Fatalf("WriteWriterContent second write: %v", err) - } - if err := writer.Close(); err != nil { - t.Fatalf("WriteWriterContent second close: %v", err) - } - writtenID2, err := finalize() - if err != nil { - t.Fatalf("WriteWriterContent second finalize: %v", err) - } - if writtenID2 != expectedID { - t.Fatalf("WriteWriterContent second id = %s, want %s", writtenID2, expectedID) - } - }) + // Writing the same object again should succeed and return the same ID. + writer, finalize, err = store.WriteWriterContent(objecttype.TypeBlob, int64(len(content))) + if err != nil { + t.Fatalf("WriteWriterContent second: %v", err) + } + if _, err := io.Copy(writer, bytes.NewReader(content)); err != nil { + t.Fatalf("WriteWriterContent second write: %v", err) + } + if err := writer.Close(); err != nil { + t.Fatalf("WriteWriterContent second close: %v", err) + } + writtenID2, err := finalize() + if err != nil { + t.Fatalf("WriteWriterContent second finalize: %v", err) + } + if writtenID2 != expectedID { + t.Fatalf("WriteWriterContent second id = %s, want %s", writtenID2, expectedID) + } + }) } func TestLooseStoreWriteWriterFullAgainstGit(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) store := openLooseStore(t, testRepo.Dir(), algo) body := []byte("full-writer-body\n") @@ -109,7 +109,7 @@ func TestLooseStoreWriteWriterFullAgainstGit(t *testing.T) { func TestLooseStoreWriterValidationErrors(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) store := openLooseStore(t, testRepo.Dir(), algo) t.Run("content overflow", func(t *testing.T) { diff --git a/objectstore/packed/helpers_test.go b/objectstore/packed/helpers_test.go index 5af44f66..f8cbd439 100644 --- a/objectstore/packed/helpers_test.go +++ b/objectstore/packed/helpers_test.go @@ -68,7 +68,7 @@ func expectedRawObject(t *testing.T, testRepo *testgit.TestRepo, id objectid.Obj func createPackedFixtureRepo(t *testing.T, algo objectid.Algorithm) (*testgit.TestRepo, []objectid.ObjectID) { t.Helper() - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) blobID, treeID, commitID := testRepo.MakeCommit(t, "packed store base commit") testRepo.Run(t, "update-ref", "refs/heads/main", commitID.String()) tagID := testRepo.TagAnnotated(t, "v1.0.0", commitID, "packed-store-tag") diff --git a/objectstore/packed/read_test.go b/objectstore/packed/read_test.go index 9244d573..0eb78366 100644 --- a/objectstore/packed/read_test.go +++ b/objectstore/packed/read_test.go @@ -136,7 +136,7 @@ func TestPackedStoreNewValidation(t *testing.T) { } func TestPackedStoreInvalidAlgorithm(t *testing.T) { - testRepo := testgit.NewBareRepo(t, objectid.AlgorithmSHA1) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: objectid.AlgorithmSHA1, Bare: true}) root, err := os.OpenRoot(testRepo.Dir()) if err != nil { t.Fatalf("OpenRoot(%q): %v", testRepo.Dir(), err) diff --git a/refstore/loose/loose_test.go b/refstore/loose/loose_test.go index 63898721..935b4120 100644 --- a/refstore/loose/loose_test.go +++ b/refstore/loose/loose_test.go @@ -31,7 +31,7 @@ func openLooseStore(t *testing.T, repoPath string, algo objectid.Algorithm) *loo func TestLooseResolveAndResolveFully(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) _, _, commitID := testRepo.MakeCommit(t, "loose refs commit") testRepo.UpdateRef(t, "refs/heads/main", commitID) testRepo.SymbolicRef(t, "HEAD", "refs/heads/main") @@ -78,7 +78,7 @@ func TestLooseResolveAndResolveFully(t *testing.T) { func TestLooseResolveFullyCycle(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) testRepo.SymbolicRef(t, "refs/heads/a", "refs/heads/b") testRepo.SymbolicRef(t, "refs/heads/b", "refs/heads/a") @@ -91,7 +91,7 @@ func TestLooseResolveFullyCycle(t *testing.T) { func TestLooseListPattern(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) _, _, commitID := testRepo.MakeCommit(t, "list refs commit") testRepo.UpdateRef(t, "refs/heads/main", commitID) testRepo.UpdateRef(t, "refs/heads/feature", commitID) @@ -132,7 +132,7 @@ func TestLooseListPattern(t *testing.T) { func TestLooseMalformedDetachedRef(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) refPath := filepath.Join(testRepo.Dir(), "refs", "heads", "bad") if err := os.MkdirAll(filepath.Dir(refPath), 0o755); err != nil { t.Fatalf("MkdirAll: %v", err) @@ -150,7 +150,7 @@ func TestLooseMalformedDetachedRef(t *testing.T) { func TestLooseShorten(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) _, _, commitID := testRepo.MakeCommit(t, "shorten refs commit") testRepo.UpdateRef(t, "refs/heads/main", commitID) testRepo.UpdateRef(t, "refs/tags/main", commitID) diff --git a/refstore/packed/packed_test.go b/refstore/packed/packed_test.go index 2c984cb9..c8f7f99c 100644 --- a/refstore/packed/packed_test.go +++ b/refstore/packed/packed_test.go @@ -32,7 +32,7 @@ func openPackedRefStoreFromRepo(t *testing.T, repoPath string, algo objectid.Alg func TestPackedResolveAndPeeled(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) _, _, commitID := testRepo.MakeCommit(t, "packed refs commit") testRepo.UpdateRef(t, "refs/heads/main", commitID) tagID := testRepo.TagAnnotated(t, "v1.0.0", commitID, "annotated tag") @@ -86,7 +86,7 @@ func TestPackedResolveAndPeeled(t *testing.T) { func TestPackedListAndShorten(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { - testRepo := testgit.NewBareRepo(t, algo) + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) _, _, commitID := testRepo.MakeCommit(t, "packed refs list commit") testRepo.UpdateRef(t, "refs/heads/main", commitID) testRepo.UpdateRef(t, "refs/tags/main", commitID) diff --git a/refstore/reftable/reftable_test.go b/refstore/reftable/reftable_test.go index 28201af2..d6345f14 100644 --- a/refstore/reftable/reftable_test.go +++ b/refstore/reftable/reftable_test.go @@ -17,7 +17,11 @@ import ( // newBareReftableRepo creates a bare repository that uses reftable ref storage. func newBareReftableRepo(tb testing.TB, algo objectid.Algorithm) *testgit.TestRepo { tb.Helper() - return testgit.NewRepo(tb, algo, testgit.RepoOptions{Bare: true, RefFormat: "reftable"}) + return testgit.NewRepo(tb, testgit.RepoOptions{ + ObjectFormat: algo, + Bare: true, + RefFormat: "reftable", + }) } // openStore opens a reftable store against repoDir/reftable. -- cgit v1.3.1-10-gc9f91