From 748b4e5c3b6e11e10b6a302df8a140bacb7d4eef Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 24 May 2026 09:29:34 +0000 Subject: internal/testgit: Init --- internal/testgit/repo.go | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 internal/testgit/repo.go (limited to 'internal/testgit/repo.go') 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() +} -- cgit v1.3.1-10-gc9f91