]>
Commit | Line | Data |
---|---|---|
1 | package utils | |
2 | ||
3 | import ( | |
4 | "io/ioutil" | |
5 | "log" | |
6 | "os" | |
7 | "os/exec" | |
8 | "sync" | |
9 | ) | |
10 | ||
11 | func GitPullAll() { | |
12 | currentDirectory, err := os.Getwd() | |
13 | if err != nil { | |
14 | log.Fatal("Error when trying to get current directory!") | |
15 | } else { | |
16 | log.Println("Pulling all git repositories in the directory: ", currentDirectory, "...") | |
17 | ||
18 | files, err := ioutil.ReadDir("./") | |
19 | if err != nil { | |
20 | log.Fatal(err.Error()) | |
21 | } | |
22 | var wg sync.WaitGroup | |
23 | ||
24 | for _, f := range files { | |
25 | if f.IsDir() { | |
26 | wg.Add(1) | |
27 | go doGitPull(&wg, f) | |
28 | } | |
29 | } | |
30 | wg.Wait() | |
31 | } | |
32 | } | |
33 | ||
34 | func doGitPull(wg *sync.WaitGroup, dir os.FileInfo) { | |
35 | defer wg.Done() | |
36 | output, err := exec.Command("git", "-C", dir.Name(), "pull", "--rebase").Output() | |
37 | if err != nil { | |
38 | log.Println("Error pulling", dir.Name(), err.Error()) | |
39 | } | |
40 | log.Println("Pulling", dir.Name(), "\n", string(output)) | |
41 | } |