basic git clone works
This commit is contained in:
14
cmd/go-hugo-cms/main.go
Normal file
14
cmd/go-hugo-cms/main.go
Normal 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
37
pkg/git/git.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user