aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/testgit/command.go36
-rw-r--r--internal/testgit/object.go9
-rw-r--r--internal/testgit/repo.go16
3 files changed, 40 insertions, 21 deletions
diff --git a/internal/testgit/command.go b/internal/testgit/command.go
new file mode 100644
index 00000000..cdb87a49
--- /dev/null
+++ b/internal/testgit/command.go
@@ -0,0 +1,36 @@
+package testgit
+
+import (
+ "io"
+ "os/exec"
+ "testing"
+)
+
+func (repo *Repo) Command(
+ tb testing.TB,
+ command string,
+ args ...string,
+) *exec.Cmd {
+ tb.Helper()
+
+ cmd := exec.CommandContext(tb.Context(), command, args...)
+ cmd.Dir = repo.path
+ cmd.Env = repo.env
+
+ return cmd
+}
+
+func (repo *Repo) Run(
+ tb testing.TB,
+ stdin io.Reader,
+ command string,
+ args ...string,
+) (stdout []byte, err error) {
+ tb.Helper()
+
+ cmd := repo.Command(tb, command, args...)
+
+ cmd.Stdin = stdin
+
+ return cmd.Output()
+}
diff --git a/internal/testgit/object.go b/internal/testgit/object.go
index a46ef02b..6f1a2dd8 100644
--- a/internal/testgit/object.go
+++ b/internal/testgit/object.go
@@ -12,16 +12,15 @@ import (
// and returns its object ID.
func (repo *Repo) HashObject(tb testing.TB, ty typ.Type, body io.Reader) id.ObjectID {
tb.Helper()
- cmd := repo.Command(tb, "git", "hash-object", "-t", ty.Name(), "-w", "--stdin", "--literally")
- hex, err := cmd.CombinedOutput()
+ stdout, err := repo.Run(tb, body, "git", "hash-object", "-t", ty.Name(), "-w", "--stdin", "--literally")
if err != nil {
- tb.Fatalf("hash-object: %v", hex)
+ tb.Fatalf("hash-object: %v", err)
}
- id, err := repo.objectFormat.FromString(string(hex))
+ id, err := repo.objectFormat.FromString(string(stdout))
if err != nil {
- tb.Fatalf("parse git hash-object output %q: %v", hex, err)
+ tb.Fatalf("parse git hash-object output %q: %v", string(stdout), err)
}
return id
diff --git a/internal/testgit/repo.go b/internal/testgit/repo.go
index f28ed0cb..81202344 100644
--- a/internal/testgit/repo.go
+++ b/internal/testgit/repo.go
@@ -2,7 +2,6 @@ package testgit
import (
"os"
- "os/exec"
"testing"
"lindenii.org/go/furgit/object/id"
@@ -42,18 +41,3 @@ func NewRepo(tb testing.TB, opts RepoOptions) (*Repo, error) {
func (repo *Repo) ObjectFormat() id.ObjectFormat {
return repo.objectFormat
}
-
-func (repo *Repo) Command(
- tb testing.TB,
- command string,
- args ...string,
-) *exec.Cmd {
- tb.Helper()
-
- //nolint:noctx
- cmd := exec.Command(command, args...)
- cmd.Dir = repo.path
- cmd.Env = repo.env
-
- return cmd
-}