diff options
| -rw-r--r-- | internal/testgit/fsck.go | 39 | ||||
| -rw-r--r-- | internal/testgit/show.go | 20 |
2 files changed, 59 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 +} diff --git a/internal/testgit/show.go b/internal/testgit/show.go new file mode 100644 index 00000000..31acb9d3 --- /dev/null +++ b/internal/testgit/show.go @@ -0,0 +1,20 @@ +package testgit + +import ( + "fmt" + "testing" + + "lindenii.org/go/furgit/object/id" +) + +// ShowFormat returns git-show output for one pretty format. +func (repo *Repo) ShowFormat(tb testing.TB, oid id.ObjectID, format string) ([]byte, error) { + tb.Helper() + + stdout, err := repo.Run(tb, nil, "git", "show", "--no-patch", "--no-color", "--format="+format, oid.String()) + if err != nil { + return nil, fmt.Errorf("show --format=%q %s: %w", format, oid, err) + } + + return stdout, nil +} |
