aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/testgit/config.go25
-rw-r--r--internal/testgit/object.go12
-rw-r--r--internal/testgit/repo.go15
-rw-r--r--internal/testgit/util.go5
4 files changed, 51 insertions, 6 deletions
diff --git a/internal/testgit/config.go b/internal/testgit/config.go
new file mode 100644
index 00000000..2bbadb74
--- /dev/null
+++ b/internal/testgit/config.go
@@ -0,0 +1,25 @@
+package testgit
+
+import "testing"
+
+func (repo *Repo) ConfigGet(tb testing.TB, key string) (string, error) {
+ tb.Helper()
+
+ return String(repo.Run(tb, nil, "git", "config", "--get", "--end-of-options", key))
+}
+
+func (repo *Repo) ConfigSet(tb testing.TB, key, value string) error {
+ tb.Helper()
+
+ _, err := repo.Run(tb, nil, "git", "config", "--end-of-options", key, value)
+
+ return err
+}
+
+func (repo *Repo) ConfigAdd(tb testing.TB, key, value string) error {
+ tb.Helper()
+
+ _, err := repo.Run(tb, nil, "git", "config", "--add", "--end-of-options", key, value)
+
+ return err
+}
diff --git a/internal/testgit/object.go b/internal/testgit/object.go
index 6f1a2dd8..a5f7163b 100644
--- a/internal/testgit/object.go
+++ b/internal/testgit/object.go
@@ -1,7 +1,9 @@
package testgit
import (
+ "fmt"
"io"
+ "strings"
"testing"
"lindenii.org/go/furgit/object/id"
@@ -10,18 +12,18 @@ import (
// HashObject hashes and writes an object,
// and returns its object ID.
-func (repo *Repo) HashObject(tb testing.TB, ty typ.Type, body io.Reader) id.ObjectID {
+func (repo *Repo) HashObject(tb testing.TB, ty typ.Type, body io.Reader) (id.ObjectID, error) {
tb.Helper()
stdout, err := repo.Run(tb, body, "git", "hash-object", "-t", ty.Name(), "-w", "--stdin", "--literally")
if err != nil {
- tb.Fatalf("hash-object: %v", err)
+ return id.ObjectID{}, fmt.Errorf("hash-object: %w", err)
}
- id, err := repo.objectFormat.FromString(string(stdout))
+ objectID, err := repo.objectFormat.FromString(strings.TrimSuffix(string(stdout), "\n"))
if err != nil {
- tb.Fatalf("parse git hash-object output %q: %v", string(stdout), err)
+ return id.ObjectID{}, fmt.Errorf("parse git hash-object output %q: %w", string(stdout), err)
}
- return id
+ return objectID, nil
}
diff --git a/internal/testgit/repo.go b/internal/testgit/repo.go
index 81202344..fa89c022 100644
--- a/internal/testgit/repo.go
+++ b/internal/testgit/repo.go
@@ -38,6 +38,19 @@ func NewRepo(tb testing.TB, opts RepoOptions) (*Repo, error) {
return repo, repo.Command(tb, "git", "init", "--object-format="+repo.objectFormat.String(), "--", repo.path).Run() //nolint:wrapcheck
}
-func (repo *Repo) ObjectFormat() id.ObjectFormat {
+func (repo *Repo) ObjectFormat(tb testing.TB) id.ObjectFormat {
+ tb.Helper()
+
return repo.objectFormat
}
+
+func (repo *Repo) Root(tb testing.TB) *os.Root {
+ tb.Helper()
+
+ root, err := os.OpenRoot(repo.path)
+ if err != nil {
+ tb.Fatalf("failed opening repo root at %q: %v", repo.path, err)
+ }
+
+ return root
+}
diff --git a/internal/testgit/util.go b/internal/testgit/util.go
new file mode 100644
index 00000000..361d7725
--- /dev/null
+++ b/internal/testgit/util.go
@@ -0,0 +1,5 @@
+package testgit
+
+func String(b []byte, err error) (string, error) {
+ return string(b), err
+}