121 lines
2.9 KiB
Go
121 lines
2.9 KiB
Go
package repolist
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"go.wit.com/log"
|
|
)
|
|
|
|
func (v *RepoList) InitRepoList(cfgfile string) {
|
|
lines := parsecfg(cfgfile)
|
|
for _, line := range lines {
|
|
log.Verbose("repo =", line)
|
|
line = strings.TrimSpace(line)
|
|
if strings.HasPrefix(line, "#") {
|
|
continue
|
|
}
|
|
parts := strings.Split(line, " ")
|
|
if len(parts) > 0 {
|
|
path := parts[0]
|
|
v.NewRepo(path)
|
|
}
|
|
}
|
|
}
|
|
|
|
func parsecfg(f string) []string {
|
|
homeDir, _ := os.UserHomeDir()
|
|
cfgfile := filepath.Join(homeDir, f)
|
|
content, _ := ioutil.ReadFile(cfgfile)
|
|
out := string(content)
|
|
out = strings.TrimSpace(out)
|
|
lines := strings.Split(out, "\n")
|
|
return lines
|
|
}
|
|
|
|
func (rl *RepoList) ArgCheckoutUser() bool {
|
|
log.Info("running git checkout devel everwhere")
|
|
var failed int = 0
|
|
for _, repo := range rl.AllRepos() {
|
|
if repo.Status.ReadOnly() {
|
|
// log.Info("skipping read-only", repo.Name())
|
|
continue
|
|
}
|
|
if repo.Status.CheckDirty() {
|
|
log.Info("skipping dirty repo", repo.Name())
|
|
continue
|
|
}
|
|
branch := repo.Status.GetUserBranchName()
|
|
if branch == repo.Status.GetCurrentBranchName() {
|
|
// already on user branch
|
|
continue
|
|
}
|
|
cmd := []string{"git", "checkout", branch}
|
|
log.Info("Running:", cmd, "in", repo.Name())
|
|
err, output := repo.RunCmd(cmd)
|
|
if err == nil {
|
|
log.Info("git checkout worked", output)
|
|
} else {
|
|
failed += 1
|
|
log.Info("git checkout failed")
|
|
log.Info("Something went wrong. Got err", err)
|
|
log.Info("output =", output)
|
|
// return false
|
|
}
|
|
}
|
|
log.Info("Ran git checkout in all repos. failure count =", failed)
|
|
return true
|
|
}
|
|
|
|
func (rl *RepoList) ArgGitPull() bool {
|
|
log.Info("running git pull everywhere")
|
|
cmd := []string{"git", "pull"}
|
|
var failed int = 0
|
|
for _, repo := range rl.AllRepos() {
|
|
log.Info("Running:", repo.Status.Path(), cmd)
|
|
err, output := repo.RunCmd(cmd)
|
|
if err == nil {
|
|
log.Info(output)
|
|
} else {
|
|
failed += 1
|
|
log.Info("Something went wrong. Got err", err)
|
|
log.Info("output =", output)
|
|
return false
|
|
}
|
|
}
|
|
log.Info("Ran git pull in all repos. failure count =", failed)
|
|
return true
|
|
}
|
|
|
|
func (rl *RepoList) ArgCheckoutDevel() bool {
|
|
log.Info("running git checkout devel everwhere")
|
|
var failed int = 0
|
|
for _, repo := range rl.AllRepos() {
|
|
if repo.Status.ReadOnly() {
|
|
// log.Info("skipping read-only", repo.Name())
|
|
continue
|
|
}
|
|
if repo.CheckDirty() {
|
|
log.Info("skipping dirty repo", repo.Name())
|
|
continue
|
|
}
|
|
branch := repo.Status.GetDevelBranchName()
|
|
cmd := []string{"git", "checkout", branch}
|
|
log.Info("Running:", cmd, "in", repo.Name())
|
|
err, output := repo.RunCmd(cmd)
|
|
if err == nil {
|
|
log.Info("git checkout worked", output)
|
|
} else {
|
|
failed += 1
|
|
log.Info("git checkout failed")
|
|
log.Info("Something went wrong. Got err", err)
|
|
log.Info("output =", output)
|
|
// return false
|
|
}
|
|
}
|
|
log.Info("Ran git checkout in all repos. failure count =", failed)
|
|
return true
|
|
}
|