feat(platform): add GitClient helper with idempotent EnsureRepo
This commit is contained in:
23
internal/platform/git.go
Normal file
23
internal/platform/git.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user