basic git clone works

This commit is contained in:
lourenco
2025-09-22 12:12:59 +02:00
parent 86b363e302
commit 6b021e023f
2 changed files with 51 additions and 0 deletions

14
cmd/go-hugo-cms/main.go Normal file
View File

@@ -0,0 +1,14 @@
package main
import (
"fmt"
"git.assilvestrar.club/lourenco/go-hugo-cms.git/pkg/git"
)
func main() {
options := git.GitOptions{
URL: "https://git.assilvestrar.club/lourenco/go-hugo-cms.git",
}
fmt.Println(options.Clone())
}

37
pkg/git/git.go Normal file
View File

@@ -0,0 +1,37 @@
package git
import (
"fmt"
"os"
gogit "github.com/go-git/go-git/v5"
)
type GitOptions struct {
URL string
RecurseSubmodule bool
}
func (g *GitOptions) Clone() (string, error) {
a := &gogit.CloneOptions{
URL: g.URL,
Progress: os.Stdout,
}
if err := a.Validate(); err != nil {
return fmt.Sprintln("Validation failed"), err
}
dir, err := os.MkdirTemp("", "clone")
if err != nil {
return "", err
}
defer os.RemoveAll(dir)
_, err = gogit.PlainClone(dir, false, a)
if err != nil {
return "", err
}
return "Success", nil
}