mirror of
https://github.com/taigrr/mg.git
synced 2026-04-02 03:28:42 -07:00
add cloning
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
git "github.com/go-git/go-git/v5"
|
git "github.com/go-git/go-git/v5"
|
||||||
@@ -37,8 +38,7 @@ var (
|
|||||||
mutex := sync.Mutex{}
|
mutex := sync.Mutex{}
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
wg.Add(len(conf.Repos))
|
wg.Add(len(conf.Repos))
|
||||||
for i := 0; i < jobs; i++ {
|
cloneFunc := func() {
|
||||||
go func() {
|
|
||||||
for repo := range repoChan {
|
for repo := range repoChan {
|
||||||
_, err := git.PlainOpenWithOptions(repo.Path, &(git.PlainOpenOptions{DetectDotGit: true}))
|
_, err := git.PlainOpenWithOptions(repo.Path, &(git.PlainOpenOptions{DetectDotGit: true}))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -50,6 +50,10 @@ var (
|
|||||||
continue
|
continue
|
||||||
} else if err == git.ErrRepositoryNotExists {
|
} else if err == git.ErrRepositoryNotExists {
|
||||||
log.Printf("attempting clone: %s\n", repo.Path)
|
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)
|
||||||
|
}
|
||||||
_, err = git.PlainClone(repo.Path, false, &git.CloneOptions{
|
_, err = git.PlainClone(repo.Path, false, &git.CloneOptions{
|
||||||
URL: repo.Remote,
|
URL: repo.Remote,
|
||||||
})
|
})
|
||||||
@@ -73,7 +77,9 @@ var (
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}
|
||||||
|
for i := 0; i < jobs; i++ {
|
||||||
|
go cloneFunc()
|
||||||
}
|
}
|
||||||
fmt.Println(len(conf.Repos))
|
fmt.Println(len(conf.Repos))
|
||||||
for _, repo := range conf.Repos {
|
for _, repo := range conf.Repos {
|
||||||
|
|||||||
Reference in New Issue
Block a user