aboutsummaryrefslogtreecommitdiff
path: root/internal/testgit/fsck.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-06-07 07:44:38 +0000
committerGravatar Runxi Yu2026-06-07 07:44:38 +0000
commitfa3ebe770eaf3388bc48bdceba6affb5bc6d5357 (patch)
tree5d0cdc7a2096508a008bcf7383b63b626d1d1dac /internal/testgit/fsck.go
parentobject/commit: parse_test (diff)
signatureNo signature
internal/testgit: Add show and fsck
Diffstat (limited to 'internal/testgit/fsck.go')
-rw-r--r--internal/testgit/fsck.go39
1 files changed, 39 insertions, 0 deletions
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
+}