aboutsummaryrefslogtreecommitdiff
path: root/internal/testgit/repo.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-05-24 09:29:34 +0000
committerGravatar Runxi Yu2026-05-24 09:29:34 +0000
commit748b4e5c3b6e11e10b6a302df8a140bacb7d4eef (patch)
tree4609fd9ac7fe484768cc4f85f34e90f72fffe836 /internal/testgit/repo.go
parentREADME, CONTRIBUTING: Simplify (diff)
signatureNo signature
internal/testgit: Init
Diffstat (limited to 'internal/testgit/repo.go')
-rw-r--r--internal/testgit/repo.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/internal/testgit/repo.go b/internal/testgit/repo.go
new file mode 100644
index 00000000..f18f199c
--- /dev/null
+++ b/internal/testgit/repo.go
@@ -0,0 +1,53 @@
+package testgit
+
+import (
+ "os"
+ "os/exec"
+ "testing"
+
+ "codeberg.org/lindenii/furgit/object/id"
+)
+
+type Repo struct {
+ path string
+ algo id.Algorithm
+ env []string
+}
+
+func (repo *Repo) Command(
+ tb testing.TB,
+ command string,
+ args ...string,
+) *exec.Cmd {
+ //nolint:noctx
+ cmd := exec.Command(command, args...)
+ cmd.Dir = repo.path
+ cmd.Env = repo.env
+
+ return cmd
+}
+
+type RepoOptions struct {
+ ObjectFormat id.Algorithm
+}
+
+func NewRepo(tb testing.TB, opts RepoOptions) (*Repo, error) {
+ tb.Helper()
+
+ repo := &Repo{
+ path: tb.TempDir(),
+ algo: opts.ObjectFormat,
+ env: append(os.Environ(),
+ "GIT_CONFIG_GLOBAL=/dev/null",
+ "GIT_CONFIG_SYSTEM=/dev/null",
+ "GIT_AUTHOR_NAME=Test Author",
+ "GIT_AUTHOR_EMAIL=test@example.org",
+ "GIT_COMMITTER_NAME=Test Committer",
+ "GIT_COMMITTER_EMAIL=committer@example.org",
+ "GIT_AUTHOR_DATE=1234567890 +0000",
+ "GIT_COMMITTER_DATE=1234567890 +0000",
+ ),
+ }
+
+ return repo, repo.Command(tb, "git", "init", "--object-format="+repo.algo.String(), "--", repo.path).Run()
+}