From fa3ebe770eaf3388bc48bdceba6affb5bc6d5357 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 7 Jun 2026 07:44:38 +0000 Subject: internal/testgit: Add show and fsck --- internal/testgit/fsck.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 internal/testgit/fsck.go (limited to 'internal/testgit/fsck.go') diff --git a/internal/testgit/fsck.go b/internal/testgit/fsck.go new file mode 100644 index 00000000..6eb4047a --- /dev/null +++ b/internal/testgit/fsck.go @@ -0,0 +1,39 @@ +package testgit + +import ( + "fmt" + "testing" + + "lindenii.org/go/furgit/object/id" +) + +// FsckOptions configures [Repo.Fsck]. +// +//exhaustruct:ignore +type FsckOptions struct { + Strict bool + NoDangling bool +} + +// Fsck runs git-fsck against the repository. +func (repo *Repo) Fsck(tb testing.TB, opts FsckOptions, objects ...id.ObjectID) error { + tb.Helper() + + args := []string{"fsck"} + if opts.Strict { + args = append(args, "--strict") + } + if opts.NoDangling { + args = append(args, "--no-dangling") + } + + for _, object := range objects { + args = append(args, object.String()) + } + + if _, err := repo.Run(tb, nil, "git", args...); err != nil { + return fmt.Errorf("fsck: %w", err) + } + + return nil +} -- cgit v1.3.1-10-gc9f91