shithub: furgit

Download patch

ref: bda11a7b87844303fa9d8d14b9469136830f90c7
parent: c2b2f7f5f50e729217d9b70674651ca58eae2e9a
author: Runxi Yu <me@runxiyu.org>
date: Sat Feb 21 07:27:39 EST 2026

testgit: Add RepoOptions and NewRepo for ref format and bare.

--- a/internal/testgit/repo_new.go
+++ b/internal/testgit/repo_new.go
@@ -7,19 +7,29 @@
 	"codeberg.org/lindenii/furgit/objectid"
 )
 
+// RepoOptions controls git-init options for test repositories.
+type RepoOptions struct {
+	// Bare selects whether the repository is initialized as bare.
+	Bare bool
+	// RefFormat selects the git ref storage format (for example "files" or
+	// "reftable"). Empty means git's default format.
+	RefFormat string
+}
+
 // NewBareRepo creates a temporary bare repository initialized with the requested algorithm.
 func NewBareRepo(tb testing.TB, algo objectid.Algorithm) *TestRepo {
 	tb.Helper()
-	return newRepo(tb, algo, true)
+	return NewRepo(tb, algo, RepoOptions{Bare: true})
 }
 
 // NewWorkRepo creates a temporary non-bare repository initialized with the requested algorithm.
 func NewWorkRepo(tb testing.TB, algo objectid.Algorithm) *TestRepo {
 	tb.Helper()
-	return newRepo(tb, algo, false)
+	return NewRepo(tb, algo, RepoOptions{Bare: false})
 }
 
-func newRepo(tb testing.TB, algo objectid.Algorithm, bare bool) *TestRepo {
+// NewRepo creates a temporary repository initialized with the requested options.
+func NewRepo(tb testing.TB, algo objectid.Algorithm, opts RepoOptions) *TestRepo {
 	tb.Helper()
 	if algo.Size() == 0 {
 		tb.Fatalf("invalid algorithm: %v", algo)
@@ -47,8 +57,11 @@
 	}
 
 	args := []string{"init", "--object-format=" + algo.String()}
-	if bare {
+	if opts.Bare {
 		args = append(args, "--bare")
+	}
+	if opts.RefFormat != "" {
+		args = append(args, "--ref-format="+opts.RefFormat)
 	}
 	args = append(args, dir)
 	testRepo.runBytes(tb, nil, "", args...)
--- a/internal/testgit/repo_refs.go
+++ b/internal/testgit/repo_refs.go
@@ -13,6 +13,12 @@
 	testRepo.Run(tb, "update-ref", name, id.String())
 }
 
+// DeleteRef deletes a ref.
+func (testRepo *TestRepo) DeleteRef(tb testing.TB, name string) {
+	tb.Helper()
+	testRepo.Run(tb, "update-ref", "-d", name)
+}
+
 // SymbolicRef sets a symbolic reference target.
 func (testRepo *TestRepo) SymbolicRef(tb testing.TB, name, target string) {
 	tb.Helper()
--