mirror of
https://github.com/taigrr/mg.git
synced 2026-04-02 03:28:42 -07:00
register clone cmd
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/taigrr/mg/parse"
|
"github.com/taigrr/mg/parse"
|
||||||
)
|
)
|
||||||
|
|
||||||
// pullCmd represents the pull command
|
// cloneCmd represents the clone command
|
||||||
var (
|
var (
|
||||||
cloneCmd = &cobra.Command{
|
cloneCmd = &cobra.Command{
|
||||||
Use: "clone",
|
Use: "clone",
|
||||||
@@ -33,7 +33,7 @@ var (
|
|||||||
}
|
}
|
||||||
repoChan := make(chan parse.Repo, len(conf.Repos))
|
repoChan := make(chan parse.Repo, len(conf.Repos))
|
||||||
errs := []RepoError{}
|
errs := []RepoError{}
|
||||||
alreadyUpToDate := 0
|
alreadyCloned := 0
|
||||||
mutex := sync.Mutex{}
|
mutex := sync.Mutex{}
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
wg.Add(len(conf.Repos))
|
wg.Add(len(conf.Repos))
|
||||||
@@ -43,9 +43,12 @@ var (
|
|||||||
_, err := git.PlainOpenWithOptions(repo.Remote, &(git.PlainOpenOptions{DetectDotGit: true}))
|
_, err := git.PlainOpenWithOptions(repo.Remote, &(git.PlainOpenOptions{DetectDotGit: true}))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Printf("already cloned: %s\n", repo.Path)
|
log.Printf("already cloned: %s\n", repo.Path)
|
||||||
|
mutex.Lock()
|
||||||
|
alreadyCloned++
|
||||||
|
mutex.Unlock()
|
||||||
} else if err == git.ErrRepositoryNotExists {
|
} else if err == git.ErrRepositoryNotExists {
|
||||||
log.Printf("attempting clone: %s\n", repo)
|
log.Printf("attempting clone: %s\n", repo)
|
||||||
_, err := git.PlainClone(repo.Path, false, &git.CloneOptions{
|
_, err = git.PlainClone(repo.Path, false, &git.CloneOptions{
|
||||||
URL: repo.Remote,
|
URL: repo.Remote,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -80,14 +83,14 @@ var (
|
|||||||
}
|
}
|
||||||
lenErrs := len(errs)
|
lenErrs := len(errs)
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Printf("successfully pulled %d/%d repos\n", len(conf.Repos)-lenErrs, len(conf.Repos))
|
fmt.Printf("successfully cloned %d/%d repos\n", len(conf.Repos)-lenErrs, len(conf.Repos))
|
||||||
fmt.Printf("%d repos already up to date\n", alreadyUpToDate)
|
fmt.Printf("%d repos already cloned\n", alreadyCloned)
|
||||||
fmt.Printf("failed to pull %d/%d repos\n", lenErrs, len(conf.Repos))
|
fmt.Printf("failed to clone %d/%d repos\n", lenErrs, len(conf.Repos))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(pullCmd)
|
rootCmd.AddCommand(cloneCmd)
|
||||||
pullCmd.Flags().IntVarP(&jobs, "jobs", "j", 1, "number of jobs to run in parallel")
|
cloneCmd.Flags().IntVarP(&jobs, "jobs", "j", 1, "number of jobs to run in parallel")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user