summaryrefslogtreecommitdiff
path: root/doGit.go
diff options
context:
space:
mode:
Diffstat (limited to 'doGit.go')
-rw-r--r--doGit.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/doGit.go b/doGit.go
index 3b77830..1f51dea 100644
--- a/doGit.go
+++ b/doGit.go
@@ -4,10 +4,59 @@
package main
import (
+ "os"
+ "path/filepath"
+
"go.wit.com/lib/gui/shell"
+ "go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
+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)
+ 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
+ }
+ os.Chdir(repo.FullPath)
+ exitOnErrorRealtime([]string{"git", "pull"})
+}
+
+func doPush(wpath string) {
+ doPull(wpath)
+ d := filepath.Join(me.homedir, wpath)
+ if !shell.IsDir(d) {
+ return
+ }
+ repo, err := gitpb.NewRepo(d)
+ if err != nil {
+ log.Info("path error", d, err)
+ return
+ }
+ if repo == nil {
+ log.Info("repo is nil", d, err)
+ return
+ }
+
+ if err := repo.GitCommit(); err != nil {
+ badExit(err)
+ }
+
+ repo.RunRealtime([]string{"git", "push"})
+}
+
func doGit() error {
log.DaemonMode(true)
defer log.DaemonMode(false)
@@ -16,11 +65,25 @@ func doGit() error {
fstr := "--format=\"%h %>(24)%ar %>(20)%an %s"
cmd := []string{"git", "log", fstr}
shell.RunVerbose(cmd)
+ okExit("")
}
if argv.Git.Who != nil {
cmd := []string{"git", "who"}
shell.RunVerbose(cmd)
+ okExit("")
+ }
+
+ if argv.Git.Pull != nil {
+ doPull(".config/wit")
+ doPull("tools")
+ okExit("")
+ }
+
+ if argv.Git.Push != nil {
+ doPush(".config/wit")
+ doPush("tools")
+ okExit("")
}
return nil