3 Commits

Author SHA1 Message Date
Tai Groot
991985ab4e update modeperm for directory creation on clone 2024-09-16 12:12:04 -07:00
417cf943fa fixup help text 2024-09-15 13:08:02 -07:00
1030a8f3a9 add cloning 2024-09-15 13:01:55 -07:00
3 changed files with 37 additions and 31 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"log"
"os"
"path/filepath"
"sync"
git "github.com/go-git/go-git/v5"
@@ -37,8 +38,7 @@ var (
mutex := sync.Mutex{}
wg := sync.WaitGroup{}
wg.Add(len(conf.Repos))
for i := 0; i < jobs; i++ {
go func() {
cloneFunc := func() {
for repo := range repoChan {
_, err := git.PlainOpenWithOptions(repo.Path, &(git.PlainOpenOptions{DetectDotGit: true}))
if err == nil {
@@ -50,6 +50,10 @@ var (
continue
} else if err == git.ErrRepositoryNotExists {
log.Printf("attempting clone: %s\n", repo.Path)
parentPath := filepath.Dir(repo.Path)
if _, err := os.Stat(parentPath); err != nil {
os.MkdirAll(parentPath, os.ModeDir|os.ModePerm)
}
_, err = git.PlainClone(repo.Path, false, &git.CloneOptions{
URL: repo.Remote,
})
@@ -73,7 +77,9 @@ var (
continue
}
}
}()
}
for i := 0; i < jobs; i++ {
go cloneFunc()
}
fmt.Println(len(conf.Repos))
for _, repo := range conf.Repos {

View File

@@ -15,7 +15,7 @@ var (
jobs int
pullCmd = &cobra.Command{
Use: "pull",
Short: "add current path to list of repos",
Short: "update all git repos specified in config",
Run: func(_ *cobra.Command, args []string) {
type RepoError struct {
Error error

2
go.mod
View File

@@ -1,6 +1,6 @@
module github.com/taigrr/mg
go 1.21
go 1.23.1
require (
github.com/go-git/go-git/v5 v5.11.0