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