ref: 2852f9a20613b145fe36a8fde5bfd31ff7e82291
parent: 304559e6a539cb60e97c429d56a32991d1c68bc1
author: Runxi Yu <me@runxiyu.org>
date: Sat Feb 21 07:31:51 EST 2026
*: Use testgit.NewRepo
--- a/config/config_test.go
+++ b/config/config_test.go
@@ -27,7 +27,7 @@
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 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 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 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 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 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 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")
--- a/object/blob_parse_test.go
+++ b/object/blob_parse_test.go
@@ -11,7 +11,7 @@
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)
--- a/object/blob_serialize_test.go
+++ b/object/blob_serialize_test.go
@@ -10,7 +10,7 @@
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)
--- a/object/commit_parse_test.go
+++ b/object/commit_parse_test.go
@@ -11,7 +11,7 @@
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)
--- a/object/commit_serialize_test.go
+++ b/object/commit_serialize_test.go
@@ -10,7 +10,7 @@
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)
--- a/object/tag_parse_test.go
+++ b/object/tag_parse_test.go
@@ -12,7 +12,7 @@
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")
--- a/object/tag_serialize_test.go
+++ b/object/tag_serialize_test.go
@@ -10,7 +10,7 @@
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")
--- a/object/tree_parse_test.go
+++ b/object/tree_parse_test.go
@@ -11,7 +11,7 @@
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 {--- a/object/tree_serialize_test.go
+++ b/object/tree_serialize_test.go
@@ -10,7 +10,7 @@
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{}--- a/objectstore/loose/read_test.go
+++ b/objectstore/loose/read_test.go
@@ -15,7 +15,7 @@
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 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()))--- a/objectstore/loose/write_test.go
+++ b/objectstore/loose/write_test.go
@@ -13,7 +13,7 @@
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 @@
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 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) {--- a/objectstore/packed/helpers_test.go
+++ b/objectstore/packed/helpers_test.go
@@ -68,7 +68,7 @@
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")
--- a/objectstore/packed/read_test.go
+++ b/objectstore/packed/read_test.go
@@ -136,7 +136,7 @@
}
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)--- a/refstore/loose/loose_test.go
+++ b/refstore/loose/loose_test.go
@@ -31,7 +31,7 @@
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 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 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 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 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)
--- a/refstore/packed/packed_test.go
+++ b/refstore/packed/packed_test.go
@@ -32,7 +32,7 @@
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 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)
--- a/refstore/reftable/reftable_test.go
+++ b/refstore/reftable/reftable_test.go
@@ -17,7 +17,11 @@
// 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.
--
⑨