1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
package app
import (
"fmt"
"sync"
"time"
"github.com/isacikgoz/gitbatch/internal/command"
"github.com/isacikgoz/gitbatch/internal/git"
)
func quick(directories []string, mode string) error {
var wg sync.WaitGroup
start := time.Now()
for _, dir := range directories {
wg.Add(1)
go func(d string, mode string) {
defer wg.Done()
if err := operate(d, mode); err != nil {
fmt.Printf("could not perform %s on %s: %s", mode, d, err)
}
fmt.Printf("%s: successful\n", d)
}(dir, mode)
}
wg.Wait()
elapsed := time.Since(start)
fmt.Printf("%d repositories finished in: %s\n", len(directories), elapsed)
return nil
}
func operate(directory, mode string) error {
r, err := git.FastInitializeRepo(directory)
if err != nil {
return err
}
switch mode {
case "fetch":
return command.Fetch(r, &command.FetchOptions{
RemoteName: "origin",
Progress: true,
})
case "pull":
return command.Pull(r, &command.PullOptions{
RemoteName: "origin",
Progress: true,
})
}
return nil
}
|