Fast implementation of Git in pure Go codeberg.org/lindenii/furgit
git go
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

Runxi Yu bda11a7b c2b2f7f5

+23 -4
+17 -4
internal/testgit/repo_new.go
··· 7 7 "codeberg.org/lindenii/furgit/objectid" 8 8 ) 9 9 10 + // RepoOptions controls git-init options for test repositories. 11 + type RepoOptions struct { 12 + // Bare selects whether the repository is initialized as bare. 13 + Bare bool 14 + // RefFormat selects the git ref storage format (for example "files" or 15 + // "reftable"). Empty means git's default format. 16 + RefFormat string 17 + } 18 + 10 19 // NewBareRepo creates a temporary bare repository initialized with the requested algorithm. 11 20 func NewBareRepo(tb testing.TB, algo objectid.Algorithm) *TestRepo { 12 21 tb.Helper() 13 - return newRepo(tb, algo, true) 22 + return NewRepo(tb, algo, RepoOptions{Bare: true}) 14 23 } 15 24 16 25 // NewWorkRepo creates a temporary non-bare repository initialized with the requested algorithm. 17 26 func NewWorkRepo(tb testing.TB, algo objectid.Algorithm) *TestRepo { 18 27 tb.Helper() 19 - return newRepo(tb, algo, false) 28 + return NewRepo(tb, algo, RepoOptions{Bare: false}) 20 29 } 21 30 22 - func newRepo(tb testing.TB, algo objectid.Algorithm, bare bool) *TestRepo { 31 + // NewRepo creates a temporary repository initialized with the requested options. 32 + func NewRepo(tb testing.TB, algo objectid.Algorithm, opts RepoOptions) *TestRepo { 23 33 tb.Helper() 24 34 if algo.Size() == 0 { 25 35 tb.Fatalf("invalid algorithm: %v", algo) ··· 47 57 } 48 58 49 59 args := []string{"init", "--object-format=" + algo.String()} 50 - if bare { 60 + if opts.Bare { 51 61 args = append(args, "--bare") 62 + } 63 + if opts.RefFormat != "" { 64 + args = append(args, "--ref-format="+opts.RefFormat) 52 65 } 53 66 args = append(args, dir) 54 67 testRepo.runBytes(tb, nil, "", args...)
+6
internal/testgit/repo_refs.go
··· 13 13 testRepo.Run(tb, "update-ref", name, id.String()) 14 14 } 15 15 16 + // DeleteRef deletes a ref. 17 + func (testRepo *TestRepo) DeleteRef(tb testing.TB, name string) { 18 + tb.Helper() 19 + testRepo.Run(tb, "update-ref", "-d", name) 20 + } 21 + 16 22 // SymbolicRef sets a symbolic reference target. 17 23 func (testRepo *TestRepo) SymbolicRef(tb testing.TB, name, target string) { 18 24 tb.Helper()