feat(platform): add GitClient helper with idempotent EnsureRepo

This commit is contained in:
MDietermann
2026-04-14 08:32:04 +02:00
parent 3f4223879b
commit 1903217b5f
2 changed files with 78 additions and 0 deletions

23
internal/platform/git.go Normal file
View File

@@ -0,0 +1,23 @@
package platform
import (
"context"
"os"
"path/filepath"
)
// GitClient wraps `git` via a Runner.
type GitClient struct{ Runner Runner }
// Clone always runs `git clone --depth=1 url dest`.
func (g GitClient) Clone(ctx context.Context, url, dest string) error {
return g.Runner.Run(ctx, "git", "clone", "--depth=1", url, dest)
}
// EnsureRepo clones url into dest if dest/.git is missing; otherwise noop.
func (g GitClient) EnsureRepo(ctx context.Context, url, dest string) error {
if _, err := os.Stat(filepath.Join(dest, ".git")); err == nil {
return nil
}
return g.Clone(ctx, url, dest)
}