/
main.go
52 lines (45 loc) · 1.07 KB
/
main.go
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
50
51
52
package main
import (
"fmt"
"strings"
"path/filepath"
"os"
"os/exec"
"github.com/yookoala/realpath"
)
func pull() {
cmd := exec.Command("git", "pull")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
fmt.Println("Run failed - ", err)
}
}
func fetchDir(fp string, fi os.FileInfo, err error) error {
// can't walk here,
// but continue walking elsewhere
if err != nil {
return nil
}
if !!fi.IsDir() && fp != "." {
oldPath, _ := realpath.Realpath(".")
matched, _ := filepath.Match("*/.git", fp)
if matched {
dirs := strings.Split(fp, ".")
fmt.Println("Enter in :", dirs[0])
fmt.Println("Trying to pull...")
os.Chdir(dirs[0])
pull()
os.Chdir(oldPath)
fmt.Println()
}
}
return nil
}
func main() {
fmt.Println()
fmt.Println("### Running go-pull script - Fetching directories...")
filepath.Walk(".", fetchDir)
fmt.Println("Done.")
fmt.Println()
}