return
}
+func (r Repo) MergeDefault(branch string) (out []byte, err error) {
+ out, err = r.gitCmd("checkout", branch)
+
+ if err != nil {
+ return
+ }
+
+ out, err = r.gitCmd("merge", "--ff-only")
+
+ return
+}
+
func (r Repo) GetPath() string {
return r.Path
}
return
}
+// Parse output into one string per line
+func outputToList(out []byte) (list []string) {
+ if len(out) > 0 {
+ list = strings.Split(string(out), "\n")
+
+ l := len(list)
+ if l > 0 && list[l-1] == "" {
+ list = list[:l-1]
+ }
+ }
+ return
+}
+
func (r Repo) Tags() (tags []string, err error) {
out, err := r.gitCmd("tag")
return nil, err
}
- tags = strings.Split(string(out), "\n")
+ tags = outputToList(out)
+
return
}
return
}
+func (r Repo) Branches(pattern string) (branches []string, err error) {
+ var out []byte
+ if pattern == "" {
+ out, err = r.gitCmd("branch")
+ } else {
+ out, err = r.gitCmd("branch", "--list", pattern)
+ }
+
+ if err != nil {
+ return nil, err
+ }
+
+ branches = outputToList(out)
+
+ // Strip the first two bytes from the string
+ for i := range branches {
+ fmt.Printf("Parsing branch %d '%s'\n", i, branches[i])
+ branches[i] = (branches[i])[2:]
+ }
+
+ return
+}
+
+
// Do a 'git am', and if it fails, clean up the tree
func (r Repo) AmClean(amglob string) (out []byte, err error) {
files, err := globToFullPath(amglob)
return 0
}
+func MainRepoUpdate(unused *XSAMeta, args []string) (ret int) {
+ pull := func(xr *XenRepo, tree Tree) (err error) {
+ // git fetch
+ if _, err = xr.Fetch(); err != nil {
+ err = fmt.Errorf("Fetching for tree %v: %v\n",
+ tree, err)
+ return
+ }
+
+ // for master, stable-* branches: 'git merge'
+ branches, err := xr.Branches("stable-*")
+
+ branches = append([]string{"master"}, branches...)
+
+ for _, branch := range branches {
+ if _, err = xr.MergeDefault(branch) ; err != nil {
+ err = fmt.Errorf("Merging branch %s on tree %v: %v\n",
+ branch, tree, err)
+ }
+ }
+
+ return
+ }
+
+ if err := ForEachXenRepo(pull); err != nil {
+ fmt.Printf("Trying to update trees: %v\n", err)
+ return 1
+ }
+
+ return 0
+}
+
func MainRepoInfo(unused *XSAMeta, args []string) (ret int) {
fmt.Printf("[Tool]\n")
fmt.Printf("rootDir: %s\n", G.config.Tool.rootDir)