From bda11a7b87844303fa9d8d14b9469136830f90c7 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sat, 21 Feb 2026 12:27:39 +0800 Subject: testgit: Add RepoOptions and NewRepo for ref format and bare. --- internal/testgit/repo_new.go | 21 +++++++++++++++++---- internal/testgit/repo_refs.go | 6 ++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/internal/testgit/repo_new.go b/internal/testgit/repo_new.go index 8908c8c0..81ac58d5 100644 --- a/internal/testgit/repo_new.go +++ b/internal/testgit/repo_new.go @@ -7,19 +7,29 @@ import ( "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,9 +57,12 @@ func newRepo(tb testing.TB, algo objectid.Algorithm, bare bool) *TestRepo { } 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...) return testRepo diff --git a/internal/testgit/repo_refs.go b/internal/testgit/repo_refs.go index 258d2787..eb09a78b 100644 --- a/internal/testgit/repo_refs.go +++ b/internal/testgit/repo_refs.go @@ -13,6 +13,12 @@ func (testRepo *TestRepo) UpdateRef(tb testing.TB, name string, id objectid.Obje 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() -- cgit v1.3.1-10-gc9f91