aboutsummaryrefslogtreecommitdiff
path: root/internal/testgit/fsck.go
blob: d32fc3a9d5cbf745a0226cb5608514d405e6b8f0 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package testgit

import (
	"fmt"
	"testing"

	"lindenii.org/go/furgit/object/id"
)

// FsckOptions configures [Repo.Fsck].
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")
	}

	args = append(args, "--end-of-options")

	for _, object := range objects {
		args = append(args, object.String())
	}

	_, err := repo.run(tb, nil, "git", args...)
	if err != nil {
		return fmt.Errorf("fsck: %w", err)
	}

	return nil
}