-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-repo.go
65 lines (56 loc) · 1.15 KB
/
update-repo.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
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"os/exec"
"strings"
)
func IsGitDir(path string) int {
if strings.Compare(path, ".git") == 0 {
return 1
}
if strings.Contains(path, ".git") {
return 2
}
return 0
}
func IsSvnDir(path string) int {
if strings.Compare(path, ".git") == 0 {
return 1
}
if strings.Contains(path, ".git") {
return 2
}
return 0
}
func RunGitCommand(path string, gitCmd string) {
cmd := exec.Command("CMD", "/C", "git -C", path, gitCmd)
var out bytes.Buffer
cmd.Stdout = &out
cmd.Run()
fmt.Println(out.String())
}
func UpdateRepos(path string) {
dir, _ := ioutil.ReadDir(path)
for _, fi := range dir {
if fi.IsDir() {
if IsGitDir(fi.Name()) == 1 {
fmt.Printf("call git path=%v is a git dir=%v EXEC pull\n", path, fi.Name())
RunGitCommand(path, "pull")
} else if IsGitDir(fi.Name()) == 2 {
fmt.Printf("call git path=%v is a bare git dir=%v EXEC fetch\n", path, fi.Name())
RunGitCommand(path, "fetch")
} else {
//fmt.Printf("call next dir %v\n", fi.Name())
UpdateRepos(path + "/" + fi.Name())
}
}
}
}
func main() {
flag.Parse()
root := flag.Arg(0)
UpdateRepos(root)
}