summaryrefslogtreecommitdiff
path: root/doGit.go
diff options
context:
space:
mode:
Diffstat (limited to 'doGit.go')
-rw-r--r--doGit.go84
1 files changed, 46 insertions, 38 deletions
diff --git a/doGit.go b/doGit.go
index 3ad057d..b2eaae0 100644
--- a/doGit.go
+++ b/doGit.go
@@ -11,6 +11,8 @@ import (
"strings"
"github.com/go-cmd/cmd"
+ "go.wit.com/lib/config"
+ "go.wit.com/lib/env"
"go.wit.com/lib/fhelp"
"go.wit.com/lib/gui/shell"
"go.wit.com/lib/protobuf/argvpb"
@@ -52,6 +54,23 @@ func runCommand(cmds []string) (string, error) {
func doGit() (string, error) {
var s string
var err error
+ var track []string
+
+ if env.Get("track") == "" {
+ env.Set("track", "~/.config/wit")
+ env.Save()
+ log.Info("Setting tracking on", env.Get("track"))
+ }
+
+ for _, p := range strings.Fields(env.Get("track")) {
+ fullp := env.FullPath(p)
+ if config.IsDir(fullp) {
+ log.Info("tracking repo:", fullp)
+ track = append(track, fullp)
+ } else {
+ log.Info("missing repo:", fullp)
+ }
+ }
if argv.Git.Log != nil {
fstr := "--format=\"%h %>(24)%ar %>(20)%an %s"
@@ -104,17 +123,20 @@ func doGit() (string, error) {
}
if argv.Git.Pull != nil {
- doPull(".config/wit")
- doPull("tools")
+ for _, fullp := range track {
+ doPull(fullp)
+ }
s = "git pull"
}
if argv.Git.Push != nil {
- doPush(".config/wit")
- doPush("tools")
- cmd := []string{"bwit", "git", "push"}
- s, err = runCommand(cmd)
- s = "git push"
+ for _, fullp := range track {
+ err := doPush(fullp)
+ if err != nil {
+ return "git push failed", err
+ }
+ }
+ s = "git push worked"
}
if argv.Git.DeleteUntracked {
@@ -150,52 +172,38 @@ func doGit() (string, error) {
return s, err
}
-func findRepo(wpath string) (*gitpb.Repo, bool) {
- d := filepath.Join(me.homedir, wpath)
- if !shell.IsDir(d) {
- return nil, false
- }
- repo, err := gitpb.NewRepo(d)
+func doPull(fpath string) error {
+ repo, err := gitpb.NewRepo(fpath)
if err != nil {
- log.Info("path error", d, err)
- return nil, false
- }
- return repo, true
-}
-
-func doPull(wpath string) {
- repo, ok := findRepo(wpath)
- if !ok {
- return
+ log.Info("path error", fpath, err)
+ return err
}
os.Chdir(repo.FullPath)
cmd := []string{"git", "pull"}
log.Info("Run", repo.FullPath, cmd)
- exitOnErrorRealtime(cmd)
+ err = repo.RunVerbose(cmd)
+ return err
}
-func doPush(wpath string) {
- doPull(wpath)
- d := filepath.Join(me.homedir, wpath)
- if !shell.IsDir(d) {
- return
- }
- repo, err := gitpb.NewRepo(d)
+func doPush(fpath string) error {
+ doPull(fpath)
+ repo, err := gitpb.NewRepo(fpath)
if err != nil {
- log.Info("path error", d, err)
- return
+ log.Info("path error", fpath, err)
+ return err
}
if repo == nil {
- log.Info("repo is nil", d, err)
- return
+ log.Info("repo is nil", fpath, err)
+ return errors.New("not git repo " + fpath)
}
if err := repo.GitCommit(); err != nil {
- msg := fmt.Sprintf("repo.GitCommit() %s", repo.FullPath)
- argvpb.BadExit(msg, err)
+ // msg := fmt.Sprintf("repo.GitCommit() %s err(%v)", repo.FullPath, err)
+ return err
}
- repo.RunRealtime([]string{"git", "push"})
+ err = repo.RunVerbose([]string{"git", "push"})
+ return err
}
/*